View Javadoc

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 The Apache MINA Project (dev@mina.apache.org)
32   * @version $Rev:671827 $, $Date:2008-06-26 09:49:48 +0100 (jeu., 26 juin 2008) $
33   */
34  public interface IoFuture {
35  	
36      /**
37       * Returns the {@link IoSession} which is associated with this future.
38       */
39      IoSession getSession();
40  
41      /**
42       * Wait for the asynchronous operation to complete.
43       * The attached listeners will be notified when the operation is 
44       * completed.
45       */
46      IoFuture await() throws InterruptedException;
47  
48      /**
49       * Wait for the asynchronous operation to complete with the specified timeout.
50       *
51       * @return <tt>true</tt> if the operation is completed.
52       */
53      boolean await(long timeout, TimeUnit unit) throws InterruptedException;
54  
55      /**
56       * Wait for the asynchronous operation to complete with the specified timeout.
57       *
58       * @return <tt>true</tt> if the operation is completed.
59       */
60      boolean await(long timeoutMillis) throws InterruptedException;
61  
62      /**
63       * Wait for the asynchronous operation to complete uninterruptibly.
64       * The attached listeners will be notified when the operation is 
65       * completed.
66       * 
67       * @return the current IoFuture
68       */
69      IoFuture awaitUninterruptibly();
70  
71      /**
72       * Wait for the asynchronous operation to complete with the specified timeout
73       * uninterruptibly.
74       *
75       * @return <tt>true</tt> if the operation is completed.
76       */
77      boolean awaitUninterruptibly(long timeout, TimeUnit unit);
78  
79      /**
80       * Wait for the asynchronous operation to complete with the specified timeout
81       * uninterruptibly.
82       *
83       * @return <tt>true</tt> if the operation is finished.
84       */
85      boolean awaitUninterruptibly(long timeoutMillis);
86  
87      /**
88       * @deprecated Replaced with {@link #awaitUninterruptibly()}.
89       */
90      @Deprecated
91      void join();
92  
93      /**
94       * @deprecated Replaced with {@link #awaitUninterruptibly(long)}.
95       */
96      @Deprecated
97      boolean join(long timeoutMillis);
98  
99      /**
100      * Returns if the asynchronous operation is completed.
101      */
102     boolean isDone();
103 
104     /**
105      * Adds an event <tt>listener</tt> which is notified when
106      * this future is completed. If the listener is added
107      * after the completion, the listener is directly notified.
108      */
109     IoFuture addListener(IoFutureListener<?> listener);
110 
111     /**
112      * Removes an existing event <tt>listener</tt> so it won't be notified when
113      * the future is completed.
114      */
115     IoFuture removeListener(IoFutureListener<?> listener);
116 }