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 * 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.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 * Return the {@link EventExecutorGroup} which is the parent of this {@link EventExecutor}, 29 */ 30 EventExecutorGroup parent(); 31 32 /** 33 * Calls {@link #inEventLoop(Thread)} with {@link Thread#currentThread()} as argument 34 */ 35 default boolean inEventLoop() { 36 return inEventLoop(Thread.currentThread()); 37 } 38 39 /** 40 * Return {@code true} if the given {@link Thread} is executed in the event loop, 41 * {@code false} otherwise. 42 */ 43 boolean inEventLoop(Thread thread); 44 45 /** 46 * Return a new {@link Promise}. 47 */ 48 default <V> Promise<V> newPromise() { 49 return new DefaultPromise<>(this); 50 } 51 52 /** 53 * Create a new {@link ProgressivePromise}. 54 */ 55 default <V> ProgressivePromise<V> newProgressivePromise() { 56 return new DefaultProgressivePromise<>(this); 57 } 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 default <V> Future<V> newSucceededFuture(V result) { 65 return new SucceededFuture<>(this, result); 66 } 67 68 /** 69 * Create a new {@link Future} which is marked as failed already. So {@link Future#isSuccess()} 70 * will return {@code false}. All {@link FutureListener} added to it will be notified directly. Also 71 * every call of blocking methods will just return without blocking. 72 */ 73 default <V> Future<V> newFailedFuture(Throwable cause) { 74 return new FailedFuture<>(this, cause); 75 } 76 }