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  
23  /**
24   * An {@link IoFuture} for asynchronous write requests.
25   *
26   * <h3>Example</h3>
27   * <pre>
28   * IoSession session = ...;
29   * WriteFuture future = session.write(...);
30   * // Wait until the message is completely written out to the O/S buffer.
31   * future.join();
32   * if( future.isWritten() )
33   * {
34   *     // The message has been written successfully.
35   * }
36   * else
37   * {
38   *     // The messsage couldn't be written out completely for some reason.
39   *     // (e.g. Connection is closed)
40   * }
41   * </pre>
42   *
43   * @author The Apache MINA Project (dev@mina.apache.org)
44   * @version $Rev: 671827 $, $Date: 2008-06-26 10:49:48 +0200 (jeu, 26 jun 2008) $
45   */
46  public interface WriteFuture extends IoFuture {
47      /**
48       * Returns <tt>true</tt> if the write operation is finished successfully.
49       */
50      boolean isWritten();
51      
52      /**
53       * Returns the cause of the write failure if and only if the write
54       * operation has failed due to an {@link Exception}.  Otherwise,
55       * <tt>null</tt> is returned.
56       */
57      Throwable getException();
58  
59      /**
60       * Sets the message is written, and notifies all threads waiting for
61       * this future.  This method is invoked by MINA internally.  Please do
62       * not call this method directly.
63       */
64      void setWritten();
65      
66      /**
67       * Sets the cause of the write failure, and notifies all threads waiting
68       * for this future.  This method is invoked by MINA internally.  Please
69       * do not call this method directly.
70       */
71      void setException(Throwable cause);
72  
73      /**
74       * Wait for the asynchronous operation to complete.
75       * The attached listeners will be notified when the operation is 
76       * completed.
77       * 
78       * @return the created {@link WriteFuture}
79       * @throws InterruptedException
80       */
81      WriteFuture await() throws InterruptedException;
82  
83      /**
84       * {@inheritDoc}
85       */
86      WriteFuture awaitUninterruptibly();
87  
88      /**
89       * {@inheritDoc}
90       */
91      WriteFuture addListener(IoFutureListener<?> listener);
92  
93      /**
94       * {@inheritDoc}
95       */
96      WriteFuture removeListener(IoFutureListener<?> listener);
97  }