View Javadoc
1   /*
2    * Copyright 2012 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    *   http://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;
17  
18  import io.netty.util.concurrent.DefaultThreadFactory;
19  
20  import java.util.concurrent.Executor;
21  import java.util.concurrent.ThreadFactory;
22  
23  public class DefaultEventLoop extends SingleThreadEventLoop {
24  
25      public DefaultEventLoop() {
26          this((EventLoopGroup) null);
27      }
28  
29      public DefaultEventLoop(ThreadFactory threadFactory) {
30          this(null, threadFactory);
31      }
32  
33      public DefaultEventLoop(Executor executor) {
34          this(null, executor);
35      }
36  
37      public DefaultEventLoop(EventLoopGroup parent) {
38          this(parent, new DefaultThreadFactory(DefaultEventLoop.class));
39      }
40  
41      public DefaultEventLoop(EventLoopGroup parent, ThreadFactory threadFactory) {
42          super(parent, threadFactory, true);
43      }
44  
45      public DefaultEventLoop(EventLoopGroup parent, Executor executor) {
46          super(parent, executor, true);
47      }
48  
49      @Override
50      protected void run() {
51          for (;;) {
52              Runnable task = takeTask();
53              if (task != null) {
54                  task.run();
55                  updateLastExecutionTime();
56              }
57  
58              if (confirmShutdown()) {
59                  break;
60              }
61          }
62      }
63  }