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 import java.util.Iterator; 19 import java.util.List; 20 import java.util.concurrent.Callable; 21 import java.util.concurrent.ScheduledExecutorService; 22 import java.util.concurrent.TimeUnit; 23 24 /** 25 * The {@link EventExecutorGroup} is responsible for providing the {@link EventExecutor}'s to use 26 * via its {@link #next()} method. Besides this, it is also responsible for handling their 27 * life-cycle and allows shutting them down in a global fashion. 28 * 29 */ 30 public interface EventExecutorGroup extends ScheduledExecutorService, Iterable<EventExecutor> { 31 32 /** 33 * Returns {@code true} if and only if all {@link EventExecutor}s managed by this {@link EventExecutorGroup} 34 * are being {@linkplain #shutdownGracefully() shut down gracefully} or was {@linkplain #isShutdown() shut down}. 35 */ 36 boolean isShuttingDown(); 37 38 /** 39 * Shortcut method for {@link #shutdownGracefully(long, long, TimeUnit)} with sensible default values. 40 * 41 * @return the {@link #terminationFuture()} 42 */ 43 Future<?> shutdownGracefully(); 44 45 /** 46 * Signals this executor that the caller wants the executor to be shut down. Once this method is called, 47 * {@link #isShuttingDown()} starts to return {@code true}, and the executor prepares to shut itself down. 48 * Unlike {@link #shutdown()}, graceful shutdown ensures that no tasks are submitted for <i>'the quiet period'</i> 49 * (usually a couple seconds) before it shuts itself down. If a task is submitted during the quiet period, 50 * it is guaranteed to be accepted and the quiet period will start over. 51 * 52 * @param quietPeriod the quiet period as described in the documentation 53 * @param timeout the maximum amount of time to wait until the executor is {@linkplain #shutdown()} 54 * regardless if a task was submitted during the quiet period 55 * @param unit the unit of {@code quietPeriod} and {@code timeout} 56 * 57 * @return the {@link #terminationFuture()} 58 */ 59 Future<?> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit); 60 61 /** 62 * Returns the {@link Future} which is notified when all {@link EventExecutor}s managed by this 63 * {@link EventExecutorGroup} have been terminated. 64 */ 65 Future<?> terminationFuture(); 66 67 /** 68 * @deprecated {@link #shutdownGracefully(long, long, TimeUnit)} or {@link #shutdownGracefully()} instead. 69 */ 70 @Override 71 @Deprecated 72 void shutdown(); 73 74 /** 75 * @deprecated {@link #shutdownGracefully(long, long, TimeUnit)} or {@link #shutdownGracefully()} instead. 76 */ 77 @Override 78 @Deprecated 79 List<Runnable> shutdownNow(); 80 81 /** 82 * Returns one of the {@link EventExecutor}s managed by this {@link EventExecutorGroup}. 83 */ 84 EventExecutor next(); 85 86 @Override 87 Iterator<EventExecutor> iterator(); 88 89 @Override 90 Future<?> submit(Runnable task); 91 92 @Override 93 <T> Future<T> submit(Runnable task, T result); 94 95 @Override 96 <T> Future<T> submit(Callable<T> task); 97 98 @Override 99 ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit); 100 101 @Override 102 <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit); 103 104 @Override 105 ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit); 106 107 @Override 108 ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit); 109 }