1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.mina.common;
20
21 /***
22 * An {@link IoFuture} for asynchronous write requests.
23 *
24 * <h3>Example</h3>
25 * <pre>
26 * IoSession session = ...;
27 * WriteFuture future = session.write(...);
28 * // Wait until the message is completely written out to the O/S buffer.
29 * future.join();
30 * if( future.isWritten() )
31 * {
32 * // The message has been written successfully.
33 * }
34 * else
35 * {
36 * // The messsage couldn't be written out completely for some reason.
37 * // (e.g. Connection is closed)
38 * }
39 * </pre>
40 *
41 * @author The Apache Directory Project
42 * @version $Rev: 355016 $, $Date: 2005-12-08 16:00:30 +0900 (Thu, 08 Dec 2005) $
43 */
44 public class WriteFuture extends IoFuture
45 {
46 /***
47 * Returns a new {@link WriteFuture} which is already marked as 'written'.
48 */
49 public static WriteFuture newWrittenFuture()
50 {
51 WriteFuture unwrittenFuture = new WriteFuture();
52 unwrittenFuture.setWritten( true );
53 return unwrittenFuture;
54 }
55
56 /***
57 * Returns a new {@link WriteFuture} which is already marked as 'not written'.
58 */
59 public static WriteFuture newNotWrittenFuture()
60 {
61 WriteFuture unwrittenFuture = new WriteFuture();
62 unwrittenFuture.setWritten( false );
63 return unwrittenFuture;
64 }
65
66 /***
67 * Creates a new instance.
68 */
69 public WriteFuture()
70 {
71 }
72
73 /***
74 * Creates a new instance which uses the specified object as a lock.
75 */
76 public WriteFuture( Object lock )
77 {
78 super( lock );
79 }
80
81 /***
82 * Returns <tt>true</tt> if the write operation is finished successfully.
83 */
84 public boolean isWritten()
85 {
86 if( isReady() )
87 {
88 return ( ( Boolean ) getValue() ).booleanValue();
89 }
90 else
91 {
92 return false;
93 }
94 }
95
96 /***
97 * This method is invoked by MINA internally. Please do not call this method
98 * directly.
99 */
100 public void setWritten( boolean written )
101 {
102 setValue( written? Boolean.TRUE : Boolean.FALSE );
103 }
104 }