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.util.concurrent;
17  
18  import java.util.Set;
19  
20  /**
21   * The {@link EventExecutor} is a special {@link EventExecutorGroup} which comes
22   * with some handy methods to see if a {@link Thread} is executed in a event loop.
23   * Besides this, it also extends the {@link EventExecutorGroup} to allow for a generic
24   * way to access methods.
25   *
26   */
27  public interface EventExecutor extends EventExecutorGroup {
28  
29      /**
30       * Returns a reference to itself.
31       */
32      @Override
33      EventExecutor next();
34  
35      /**
36       * Returns an unmodifiable singleton set which contains itself.
37       */
38      @Override
39      <E extends EventExecutor> Set<E> children();
40  
41      /**
42       * Return the {@link EventExecutorGroup} which is the parent of this {@link EventExecutor},
43       */
44      EventExecutorGroup parent();
45  
46      /**
47       * Calls {@link #inEventLoop(Thread)} with {@link Thread#currentThread()} as argument
48       */
49      boolean inEventLoop();
50  
51      /**
52       * Return {@code true} if the given {@link Thread} is executed in the event loop,
53       * {@code false} otherwise.
54       */
55      boolean inEventLoop(Thread thread);
56  
57      /**
58       * Returns an {@link EventExecutor} that is not a {@link WrappedEventExecutor}.
59       *
60       * <ul>
61       *     <li>
62       *         A {@link WrappedEventExecutor} implementing this method must return the underlying
63       *         {@link EventExecutor} while making sure that it's not a {@link WrappedEventExecutor}
64       *         (e.g. by multiple calls to {@link #unwrap()}).
65       *     </li>
66       *     <li>
67       *         An {@link EventExecutor} that is not a {@link WrappedEventExecutor} must return a reference to itself.
68       *     </li>
69       *     <li>
70       *         This method must not return null.
71       *     </li>
72       * </ul>
73       */
74      EventExecutor unwrap();
75  
76      /**
77       * Return a new {@link Promise}.
78       */
79      <V> Promise<V> newPromise();
80  
81      /**
82       * Create a new {@link ProgressivePromise}.
83       */
84      <V> ProgressivePromise<V> newProgressivePromise();
85  
86      /**
87       * Create a new {@link Future} which is marked as succeeded already. So {@link Future#isSuccess()}
88       * will return {@code true}. All {@link FutureListener} added to it will be notified directly. Also
89       * every call of blocking methods will just return without blocking.
90       */
91      <V> Future<V> newSucceededFuture(V result);
92  
93      /**
94       * Create a new {@link Future} which is marked as failed already. So {@link Future#isSuccess()}
95       * will return {@code false}. All {@link FutureListener} added to it will be notified directly. Also
96       * every call of blocking methods will just return without blocking.
97       */
98      <V> Future<V> newFailedFuture(Throwable cause);
99  }