View Javadoc
1   /*
2    * Copyright 2014 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.channel.epoll;
17  
18  import io.netty.channel.Channel;
19  import io.netty.channel.EventLoopTaskQueueFactory;
20  import io.netty.channel.IoEventLoopGroup;
21  import io.netty.channel.IoHandler;
22  import io.netty.channel.SingleThreadIoEventLoop;
23  import io.netty.util.concurrent.RejectedExecutionHandler;
24  import io.netty.util.internal.PlatformDependent;
25  import io.netty.util.internal.logging.InternalLogger;
26  import io.netty.util.internal.logging.InternalLoggerFactory;
27  
28  import java.util.Iterator;
29  import java.util.Queue;
30  import java.util.concurrent.Executor;
31  import java.util.concurrent.ThreadFactory;
32  
33  /**
34   * @deprecated Use {@link SingleThreadIoEventLoop} with {@link EpollIoHandler}
35   */
36  @Deprecated
37  public class EpollEventLoop extends SingleThreadIoEventLoop {
38  
39      private static final InternalLogger LOGGER = InternalLoggerFactory.getInstance(EpollEventLoop.class);
40  
41      EpollEventLoop(IoEventLoopGroup parent, ThreadFactory threadFactory, IoHandler ioHandler) {
42          super(parent, threadFactory, ioHandler);
43      }
44  
45      EpollEventLoop(IoEventLoopGroup parent, Executor executor, IoHandler ioHandler) {
46          super(parent, executor, ioHandler);
47      }
48  
49      EpollEventLoop(IoEventLoopGroup parent, Executor executor, IoHandler ioHandler,
50                     EventLoopTaskQueueFactory taskQueueFactory,
51                     EventLoopTaskQueueFactory tailTaskQueueFactory,
52                     RejectedExecutionHandler rejectedExecutionHandler) {
53          super(parent, executor, ioHandler, newTaskQueue(taskQueueFactory), newTaskQueue(tailTaskQueueFactory),
54                  rejectedExecutionHandler);
55      }
56  
57      private static Queue<Runnable> newTaskQueue(
58              EventLoopTaskQueueFactory queueFactory) {
59          if (queueFactory == null) {
60              return newTaskQueue0(DEFAULT_MAX_PENDING_TASKS);
61          }
62          return queueFactory.newTaskQueue(DEFAULT_MAX_PENDING_TASKS);
63      }
64  
65      @Override
66      protected Queue<Runnable> newTaskQueue(int maxPendingTasks) {
67          return newTaskQueue0(maxPendingTasks);
68      }
69  
70      private static Queue<Runnable> newTaskQueue0(int maxPendingTasks) {
71          // This event loop never calls takeTask()
72          return maxPendingTasks == Integer.MAX_VALUE ? PlatformDependent.<Runnable>newMpscQueue()
73                  : PlatformDependent.<Runnable>newMpscQueue(maxPendingTasks);
74      }
75  
76      @Override
77      public int registeredChannels() {
78          return ((EpollIoHandler) ioHandler()).numRegisteredChannels();
79      }
80  
81      @Override
82      public Iterator<Channel> registeredChannelsIterator() {
83          return ((EpollIoHandler) ioHandler()).registeredChannelsList().iterator();
84      }
85  
86      /**
87       * Returns 0.
88       */
89      public int getIoRatio() {
90          return 0;
91      }
92  
93      /**
94       * This method is a no-op.
95       *
96       * @deprecated
97       */
98      @Deprecated
99      public void setIoRatio(int ioRatio) {
100         LOGGER.debug("EpollEventLoop.setIoRatio(int) logic was removed, this is a no-op");
101     }
102 }