1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20 package org.apache.mina.core.future;
21
22 import java.util.concurrent.TimeUnit;
23
24 import org.apache.mina.core.session.IoSession;
25
26 /**
27 * Represents the completion of an asynchronous I/O operation on an
28 * {@link IoSession}.
29 * Can be listened for completion using a {@link IoFutureListener}.
30 *
31 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
32 */
33 public interface IoFuture {
34 /**
35 * Returns the {@link IoSession} which is associated with this future.
36 */
37 IoSession getSession();
38
39 /**
40 * Wait for the asynchronous operation to complete.
41 * The attached listeners will be notified when the operation is
42 * completed.
43 */
44 IoFuture await() throws InterruptedException;
45
46 /**
47 * Wait for the asynchronous operation to complete with the specified timeout.
48 *
49 * @return <tt>true</tt> if the operation is completed.
50 */
51 boolean await(long timeout, TimeUnit unit) throws InterruptedException;
52
53 /**
54 * Wait for the asynchronous operation to complete with the specified timeout.
55 *
56 * @return <tt>true</tt> if the operation is completed.
57 */
58 boolean await(long timeoutMillis) throws InterruptedException;
59
60 /**
61 * Wait for the asynchronous operation to complete uninterruptibly.
62 * The attached listeners will be notified when the operation is
63 * completed.
64 *
65 * @return the current IoFuture
66 */
67 IoFuture awaitUninterruptibly();
68
69 /**
70 * Wait for the asynchronous operation to complete with the specified timeout
71 * uninterruptibly.
72 *
73 * @return <tt>true</tt> if the operation is completed.
74 */
75 boolean awaitUninterruptibly(long timeout, TimeUnit unit);
76
77 /**
78 * Wait for the asynchronous operation to complete with the specified timeout
79 * uninterruptibly.
80 *
81 * @return <tt>true</tt> if the operation is finished.
82 */
83 boolean awaitUninterruptibly(long timeoutMillis);
84
85 /**
86 * @deprecated Replaced with {@link #awaitUninterruptibly()}.
87 */
88 @Deprecated
89 void join();
90
91 /**
92 * @deprecated Replaced with {@link #awaitUninterruptibly(long)}.
93 */
94 @Deprecated
95 boolean join(long timeoutMillis);
96
97 /**
98 * Returns if the asynchronous operation is completed.
99 */
100 boolean isDone();
101
102 /**
103 * Adds an event <tt>listener</tt> which is notified when
104 * this future is completed. If the listener is added
105 * after the completion, the listener is directly notified.
106 */
107 IoFuture addListener(IoFutureListener<?> listener);
108
109 /**
110 * Removes an existing event <tt>listener</tt> so it won't be notified when
111 * the future is completed.
112 */
113 IoFuture removeListener(IoFutureListener<?> listener);
114 }