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 /**
19  * The {@link EventExecutor} is a special {@link EventExecutorGroup} which comes
20  * with some handy methods to see if a {@link Thread} is executed in a event loop.
21  * Besides this, it also extends the {@link EventExecutorGroup} to allow for a generic
22  * way to access methods.
23  *
24  */

25 public interface EventExecutor extends EventExecutorGroup {
26
27     /**
28      * Returns a reference to itself.
29      */

30     @Override
31     EventExecutor next();
32
33     /**
34      * Return the {@link EventExecutorGroup} which is the parent of this {@link EventExecutor},
35      */

36     EventExecutorGroup parent();
37
38     /**
39      * Calls {@link #inEventLoop(Thread)} with {@link Thread#currentThread()} as argument
40      */

41     boolean inEventLoop();
42
43     /**
44      * Return {@code trueif the given {@link Thread} is executed in the event loop,
45      * {@code false} otherwise.
46      */

47     boolean inEventLoop(Thread thread);
48
49     /**
50      * Return a new {@link Promise}.
51      */

52     <V> Promise<V> newPromise();
53
54     /**
55      * Create a new {@link ProgressivePromise}.
56      */

57     <V> ProgressivePromise<V> newProgressivePromise();
58
59     /**
60      * Create a new {@link Future} which is marked as succeeded already. So {@link Future#isSuccess()}
61      * will return {@code true}. All {@link FutureListener} added to it will be notified directly. Also
62      * every call of blocking methods will just return without blocking.
63      */

64     <V> Future<V> newSucceededFuture(V result);
65
66     /**
67      * Create a new {@link Future} which is marked as failed already. So {@link Future#isSuccess()}
68      * will return {@code false}. All {@link FutureListener} added to it will be notified directly. Also
69      * every call of blocking methods will just return without blocking.
70      */

71     <V> Future<V> newFailedFuture(Throwable cause);
72 }
73