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.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 this executor was started to be 34 * {@linkplain #shutdownGracefully() shut down gracefuclly} 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 this executor has been terminated. 63 */ 64 Future<?> terminationFuture(); 65 66 /** 67 * @deprecated {@link #shutdownGracefully(long, long, TimeUnit)} or {@link #shutdownGracefully()} instead. 68 */ 69 @Override 70 @Deprecated 71 void shutdown(); 72 73 /** 74 * @deprecated {@link #shutdownGracefully(long, long, TimeUnit)} or {@link #shutdownGracefully()} instead. 75 */ 76 @Override 77 @Deprecated 78 List<Runnable> shutdownNow(); 79 80 /** 81 * Returns one of the {@link EventExecutor}s that belong to this group. 82 */ 83 EventExecutor next(); 84 85 /** 86 * Returns a read-only {@link Iterator} over all {@link EventExecutor}, which are handled by this 87 * {@link EventExecutorGroup} at the time of invoke this method. 88 */ 89 @Override 90 Iterator<EventExecutor> iterator(); 91 92 @Override 93 Future<?> submit(Runnable task); 94 95 @Override 96 <T> Future<T> submit(Runnable task, T result); 97 98 @Override 99 <T> Future<T> submit(Callable<T> task); 100 101 @Override 102 ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit); 103 104 @Override 105 <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit); 106 107 @Override 108 ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit); 109 110 @Override 111 ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit); 112 }