Package org.apache.mina.core.future
Class DefaultWriteFuture
- java.lang.Object
-
- org.apache.mina.core.future.DefaultIoFuture
-
- org.apache.mina.core.future.DefaultWriteFuture
-
- All Implemented Interfaces:
IoFuture
,WriteFuture
public class DefaultWriteFuture extends DefaultIoFuture implements WriteFuture
A default implementation ofWriteFuture
.- Author:
- Apache MINA Project
-
-
Constructor Summary
Constructors Constructor Description DefaultWriteFuture(IoSession session)
Creates a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description WriteFuture
addListener(IoFutureListener<?> listener)
Adds an event listener which is notified when this future is completed.WriteFuture
await()
Wait for the asynchronous operation to complete.WriteFuture
awaitUninterruptibly()
Wait for the asynchronous operation to complete uninterruptibly.Throwable
getException()
boolean
isWritten()
static WriteFuture
newNotWrittenFuture(IoSession session, Throwable cause)
Returns a newDefaultWriteFuture
which is already marked as 'not written'.static WriteFuture
newWrittenFuture(IoSession session)
Returns a newDefaultWriteFuture
which is already marked as 'written'.WriteFuture
removeListener(IoFutureListener<?> listener)
Removes an existing event listener so it won't be notified when the future is completed.void
setException(Throwable exception)
Sets the cause of the write failure, and notifies all threads waiting for this future.void
setWritten()
Sets the message is written, and notifies all threads waiting for this future.-
Methods inherited from class org.apache.mina.core.future.DefaultIoFuture
await, await, awaitUninterruptibly, awaitUninterruptibly, getSession, getValue, isDone, join, join, setValue
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.mina.core.future.IoFuture
await, await, awaitUninterruptibly, awaitUninterruptibly, getSession, isDone, join, join
-
-
-
-
Constructor Detail
-
DefaultWriteFuture
public DefaultWriteFuture(IoSession session)
Creates a new instance.- Parameters:
session
- The associated session
-
-
Method Detail
-
newWrittenFuture
public static WriteFuture newWrittenFuture(IoSession session)
Returns a newDefaultWriteFuture
which is already marked as 'written'.- Parameters:
session
- The associated session- Returns:
- A new future for a written message
-
newNotWrittenFuture
public static WriteFuture newNotWrittenFuture(IoSession session, Throwable cause)
Returns a newDefaultWriteFuture
which is already marked as 'not written'.- Parameters:
session
- The associated sessioncause
- The reason why the message has not be written- Returns:
- A new future for not written message
-
isWritten
public boolean isWritten()
- Specified by:
isWritten
in interfaceWriteFuture
- Returns:
- true if the write operation is finished successfully.
-
getException
public Throwable getException()
- Specified by:
getException
in interfaceWriteFuture
- Returns:
- the cause of the write failure if and only if the write
operation has failed due to an
Exception
. Otherwise, null is returned.
-
setWritten
public void setWritten()
Sets the message is written, and notifies all threads waiting for this future. This method is invoked by MINA internally. Please do not call this method directly.- Specified by:
setWritten
in interfaceWriteFuture
-
setException
public void setException(Throwable exception)
Sets the cause of the write failure, and notifies all threads waiting for this future. This method is invoked by MINA internally. Please do not call this method directly.- Specified by:
setException
in interfaceWriteFuture
- Parameters:
exception
- The exception to store in the Future instance
-
await
public WriteFuture await() throws InterruptedException
Wait for the asynchronous operation to complete. The attached listeners will be notified when the operation is completed.- Specified by:
await
in interfaceIoFuture
- Specified by:
await
in interfaceWriteFuture
- Overrides:
await
in classDefaultIoFuture
- Returns:
- The instance of IoFuture that we are waiting for
- Throws:
InterruptedException
- If the thread is interrupted while waiting
-
awaitUninterruptibly
public WriteFuture awaitUninterruptibly()
Wait for the asynchronous operation to complete uninterruptibly. The attached listeners will be notified when the operation is completed.- Specified by:
awaitUninterruptibly
in interfaceIoFuture
- Specified by:
awaitUninterruptibly
in interfaceWriteFuture
- Overrides:
awaitUninterruptibly
in classDefaultIoFuture
- Returns:
- the current IoFuture
-
addListener
public WriteFuture addListener(IoFutureListener<?> listener)
Adds an event listener which is notified when this future is completed. If the listener is added after the completion, the listener is directly notified.- Specified by:
addListener
in interfaceIoFuture
- Specified by:
addListener
in interfaceWriteFuture
- Overrides:
addListener
in classDefaultIoFuture
- Parameters:
listener
- The listener to add- Returns:
- the current IoFuture
-
removeListener
public WriteFuture removeListener(IoFutureListener<?> listener)
Removes an existing event listener so it won't be notified when the future is completed.- Specified by:
removeListener
in interfaceIoFuture
- Specified by:
removeListener
in interfaceWriteFuture
- Overrides:
removeListener
in classDefaultIoFuture
- Parameters:
listener
- The listener to remove- Returns:
- the current IoFuture
-
-