Package org.jboss.netty.channel
Class DefaultChannelFuture
- java.lang.Object
-
- org.jboss.netty.channel.DefaultChannelFuture
-
- All Implemented Interfaces:
ChannelFuture
- Direct Known Subclasses:
AbstractChannel.ChannelCloseFuture
,ChannelRunnableWrapper
,SslHandler.SSLEngineInboundCloseFuture
public class DefaultChannelFuture extends java.lang.Object implements ChannelFuture
The defaultChannelFuture
implementation. It is recommended to useChannels.future(Channel)
andChannels.future(Channel, boolean)
to create a newChannelFuture
rather than calling the constructor explicitly.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
cancellable
private static java.lang.Throwable
CANCELLED
private java.lang.Throwable
cause
private Channel
channel
private static boolean
disabledDeadLockCheckerOnce
private boolean
done
private ChannelFutureListener
firstListener
private static InternalLogger
logger
private java.util.List<ChannelFutureListener>
otherListeners
private java.util.List<ChannelFutureProgressListener>
progressListeners
private static boolean
useDeadLockChecker
private int
waiters
-
Constructor Summary
Constructors Constructor Description DefaultChannelFuture(Channel channel, boolean cancellable)
Creates a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(ChannelFutureListener listener)
Adds the specified listener to this future.ChannelFuture
await()
Waits for this future to be completed.boolean
await(long timeoutMillis)
Waits for this future to be completed within the specified time limit.boolean
await(long timeout, java.util.concurrent.TimeUnit unit)
Waits for this future to be completed within the specified time limit.private boolean
await0(long timeoutNanos, boolean interruptable)
ChannelFuture
awaitUninterruptibly()
Waits for this future to be completed without interruption.boolean
awaitUninterruptibly(long timeoutMillis)
Waits for this future to be completed within the specified time limit without interruption.boolean
awaitUninterruptibly(long timeout, java.util.concurrent.TimeUnit unit)
Waits for this future to be completed within the specified time limit without interruption.boolean
cancel()
Cancels the I/O operation associated with this future and notifies all listeners if canceled successfully.private static void
checkDeadLock()
java.lang.Throwable
getCause()
Returns the cause of the failed I/O operation if the I/O operation has failed.Channel
getChannel()
Returns a channel where the I/O operation associated with this future takes place.boolean
isCancelled()
Returnstrue
if and only if this future was cancelled by aChannelFuture.cancel()
method.boolean
isDone()
Returnstrue
if and only if this future is complete, regardless of whether the operation was successful, failed, or cancelled.boolean
isSuccess()
Returnstrue
if and only if the I/O operation was completed successfully.static boolean
isUseDeadLockChecker()
Returnstrue
if and only if the dead lock checker is enabled.private void
notifyListener(ChannelFutureListener l)
private void
notifyListeners()
private void
notifyProgressListener(ChannelFutureProgressListener l, long amount, long current, long total)
void
removeListener(ChannelFutureListener listener)
Removes the specified listener from this future.private void
rethrowIfFailed0()
boolean
setFailure(java.lang.Throwable cause)
Marks this future as a failure and notifies all listeners.boolean
setProgress(long amount, long current, long total)
Notifies the progress of the operation to the listeners that implementsChannelFutureProgressListener
.boolean
setSuccess()
Marks this future as a success and notifies all listeners.static void
setUseDeadLockChecker(boolean useDeadLockChecker)
Enables or disables the dead lock checker.ChannelFuture
sync()
Waits for this future until it is done, and rethrows the cause of the failure if this future failed.ChannelFuture
syncUninterruptibly()
Waits for this future until it is done, and rethrows the cause of the failure if this future failed.
-
-
-
Field Detail
-
logger
private static final InternalLogger logger
-
CANCELLED
private static final java.lang.Throwable CANCELLED
-
useDeadLockChecker
private static volatile boolean useDeadLockChecker
-
disabledDeadLockCheckerOnce
private static boolean disabledDeadLockCheckerOnce
-
channel
private final Channel channel
-
cancellable
private final boolean cancellable
-
firstListener
private ChannelFutureListener firstListener
-
otherListeners
private java.util.List<ChannelFutureListener> otherListeners
-
progressListeners
private java.util.List<ChannelFutureProgressListener> progressListeners
-
done
private boolean done
-
cause
private java.lang.Throwable cause
-
waiters
private int waiters
-
-
Method Detail
-
isUseDeadLockChecker
public static boolean isUseDeadLockChecker()
Returnstrue
if and only if the dead lock checker is enabled.
-
setUseDeadLockChecker
public static void setUseDeadLockChecker(boolean useDeadLockChecker)
Enables or disables the dead lock checker. It is not recommended to disable the dead lock checker. Disable it at your own risk!
-
getChannel
public Channel getChannel()
Description copied from interface:ChannelFuture
Returns a channel where the I/O operation associated with this future takes place.- Specified by:
getChannel
in interfaceChannelFuture
-
isDone
public boolean isDone()
Description copied from interface:ChannelFuture
Returnstrue
if and only if this future is complete, regardless of whether the operation was successful, failed, or cancelled.- Specified by:
isDone
in interfaceChannelFuture
-
isSuccess
public boolean isSuccess()
Description copied from interface:ChannelFuture
Returnstrue
if and only if the I/O operation was completed successfully.- Specified by:
isSuccess
in interfaceChannelFuture
-
getCause
public java.lang.Throwable getCause()
Description copied from interface:ChannelFuture
Returns the cause of the failed I/O operation if the I/O operation has failed.- Specified by:
getCause
in interfaceChannelFuture
- Returns:
- the cause of the failure.
null
if succeeded or this future is not completed yet.
-
isCancelled
public boolean isCancelled()
Description copied from interface:ChannelFuture
Returnstrue
if and only if this future was cancelled by aChannelFuture.cancel()
method.- Specified by:
isCancelled
in interfaceChannelFuture
-
addListener
public void addListener(ChannelFutureListener listener)
Description copied from interface:ChannelFuture
Adds the specified listener to this future. The specified listener is notified when this future is done. If this future is already completed, the specified listener is notified immediately.- Specified by:
addListener
in interfaceChannelFuture
-
removeListener
public void removeListener(ChannelFutureListener listener)
Description copied from interface:ChannelFuture
Removes the specified listener from this future. The specified listener is no longer notified when this future is done. If the specified listener is not associated with this future, this method does nothing and returns silently.- Specified by:
removeListener
in interfaceChannelFuture
-
sync
public ChannelFuture sync() throws java.lang.InterruptedException
Description copied from interface:ChannelFuture
Waits for this future until it is done, and rethrows the cause of the failure if this future failed. If the cause of the failure is a checked exception, it is wrapped with a newChannelException
before being thrown.- Specified by:
sync
in interfaceChannelFuture
- Throws:
java.lang.InterruptedException
-
syncUninterruptibly
public ChannelFuture syncUninterruptibly()
Description copied from interface:ChannelFuture
Waits for this future until it is done, and rethrows the cause of the failure if this future failed. If the cause of the failure is a checked exception, it is wrapped with a newChannelException
before being thrown.- Specified by:
syncUninterruptibly
in interfaceChannelFuture
-
rethrowIfFailed0
private void rethrowIfFailed0()
-
await
public ChannelFuture await() throws java.lang.InterruptedException
Description copied from interface:ChannelFuture
Waits for this future to be completed.- Specified by:
await
in interfaceChannelFuture
- Throws:
java.lang.InterruptedException
- if the current thread was interrupted
-
await
public boolean await(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
Description copied from interface:ChannelFuture
Waits for this future to be completed within the specified time limit.- Specified by:
await
in interfaceChannelFuture
- Returns:
true
if and only if the future was completed within the specified time limit- Throws:
java.lang.InterruptedException
- if the current thread was interrupted
-
await
public boolean await(long timeoutMillis) throws java.lang.InterruptedException
Description copied from interface:ChannelFuture
Waits for this future to be completed within the specified time limit.- Specified by:
await
in interfaceChannelFuture
- Returns:
true
if and only if the future was completed within the specified time limit- Throws:
java.lang.InterruptedException
- if the current thread was interrupted
-
awaitUninterruptibly
public ChannelFuture awaitUninterruptibly()
Description copied from interface:ChannelFuture
Waits for this future to be completed without interruption. This method catches anInterruptedException
and discards it silently.- Specified by:
awaitUninterruptibly
in interfaceChannelFuture
-
awaitUninterruptibly
public boolean awaitUninterruptibly(long timeout, java.util.concurrent.TimeUnit unit)
Description copied from interface:ChannelFuture
Waits for this future to be completed within the specified time limit without interruption. This method catches anInterruptedException
and discards it silently.- Specified by:
awaitUninterruptibly
in interfaceChannelFuture
- Returns:
true
if and only if the future was completed within the specified time limit
-
awaitUninterruptibly
public boolean awaitUninterruptibly(long timeoutMillis)
Description copied from interface:ChannelFuture
Waits for this future to be completed within the specified time limit without interruption. This method catches anInterruptedException
and discards it silently.- Specified by:
awaitUninterruptibly
in interfaceChannelFuture
- Returns:
true
if and only if the future was completed within the specified time limit
-
await0
private boolean await0(long timeoutNanos, boolean interruptable) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
checkDeadLock
private static void checkDeadLock()
-
setSuccess
public boolean setSuccess()
Description copied from interface:ChannelFuture
Marks this future as a success and notifies all listeners.- Specified by:
setSuccess
in interfaceChannelFuture
- Returns:
true
if and only if successfully marked this future as a success. Otherwisefalse
because this future is already marked as either a success or a failure.
-
setFailure
public boolean setFailure(java.lang.Throwable cause)
Description copied from interface:ChannelFuture
Marks this future as a failure and notifies all listeners.- Specified by:
setFailure
in interfaceChannelFuture
- Returns:
true
if and only if successfully marked this future as a failure. Otherwisefalse
because this future is already marked as either a success or a failure.
-
cancel
public boolean cancel()
Description copied from interface:ChannelFuture
Cancels the I/O operation associated with this future and notifies all listeners if canceled successfully.- Specified by:
cancel
in interfaceChannelFuture
- Returns:
true
if and only if the operation has been canceled.false
if the operation can't be canceled or is already completed.
-
notifyListeners
private void notifyListeners()
-
notifyListener
private void notifyListener(ChannelFutureListener l)
-
setProgress
public boolean setProgress(long amount, long current, long total)
Description copied from interface:ChannelFuture
Notifies the progress of the operation to the listeners that implementsChannelFutureProgressListener
. Please note that this method will not do anything and returnfalse
if this future is complete already.- Specified by:
setProgress
in interfaceChannelFuture
- Returns:
true
if and only if notification was made.
-
notifyProgressListener
private void notifyProgressListener(ChannelFutureProgressListener l, long amount, long current, long total)
-
-