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