Created
November 23, 2011 08:29
-
-
Save normanmaurer/1388185 to your computer and use it in GitHub Desktop.
ChannelFuture refactoring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ChannelFuture extends Future<ChannelFutureResult>{ | |
/** | |
* Returns a channel where the I/O operation associated with this | |
* future takes place. | |
*/ | |
Channel getChannel(); | |
/** | |
* Returns {@code true} if and only if the I/O operation was completed | |
* successfully. | |
*/ | |
@Deprecated | |
boolean isSuccess(); | |
/** | |
* Returns the cause of the failed I/O operation if the I/O operation has | |
* failed. | |
* | |
* @return the cause of the failure. | |
* {@code null} if succeeded or this future is not | |
* completed yet. | |
*/ | |
@Deprecated | |
Throwable getCause(); | |
/** | |
* Cancels the I/O operation associated with this future | |
* and notifies all listeners if canceled successfully. | |
* | |
* @return {@code true} if and only if the operation has been canceled. | |
* {@code false} if the operation can't be canceled or is already | |
* completed. | |
*/ | |
boolean cancel(); | |
/** | |
* Marks this future as a success and notifies all | |
* listeners. | |
* | |
* @return {@code true} if and only if successfully marked this future as | |
* a success. Otherwise {@code false} because this future is | |
* already marked as either a success or a failure. | |
*/ | |
@Deprecated | |
boolean setSuccess(); | |
/** | |
* Marks this future as a failure and notifies all | |
* listeners. | |
* | |
* @return {@code true} if and only if successfully marked this future as | |
* a failure. Otherwise {@code false} because this future is | |
* already marked as either a success or a failure. | |
*/ | |
@Deprecated | |
boolean setFailure(Throwable cause); | |
/** | |
* Notifies the progress of the operation to the listeners that implements | |
* {@link ChannelFutureProgressListener}. Please note that this method will | |
* not do anything and return {@code false} if this future is complete | |
* already. | |
* | |
* @return {@code true} if and only if notification was made. | |
*/ | |
boolean setProgress(long amount, long current, long total); | |
/** | |
* Adds the specified listener to this future. The | |
* specified listener is notified when this future is | |
* {@linkplain #isDone() done}. If this future is already | |
* completed, the specified listener is notified immediately. | |
*/ | |
void addListener(ChannelFutureListener listener); | |
/** | |
* Removes the specified listener from this future. | |
* The specified listener is no longer notified when this | |
* future is {@linkplain #isDone() done}. If the specified | |
* listener is not associated with this future, this method | |
* does nothing and returns silently. | |
*/ | |
void removeListener(ChannelFutureListener listener); | |
/** | |
* Waits for this future to be completed. | |
* | |
* @throws InterruptedException | |
* if the current thread was interrupted | |
*/ | |
ChannelFutureResult await() throws InterruptedException; | |
/** | |
* Waits for this future to be completed without | |
* interruption. This method catches an {@link InterruptedException} and | |
* discards it silently. | |
*/ | |
ChannelFutureResult awaitUninterruptibly(); | |
/** | |
* Waits for this future to be completed within the | |
* specified time limit. | |
* | |
* @return {@code true} if and only if the future was completed within | |
* the specified time limit | |
* | |
* @throws InterruptedException | |
* if the current thread was interrupted | |
*/ | |
boolean await(long timeout, TimeUnit unit) throws InterruptedException; | |
/** | |
* Waits for this future to be completed within the | |
* specified time limit. | |
* | |
* @return {@code true} if and only if the future was completed within | |
* the specified time limit | |
* | |
* @throws InterruptedException | |
* if the current thread was interrupted | |
*/ | |
boolean await(long timeoutMillis) throws InterruptedException; | |
/** | |
* Waits for this future to be completed within the | |
* specified time limit without interruption. This method catches an | |
* {@link InterruptedException} and discards it silently. | |
* | |
* @return {@code true} if and only if the future was completed within | |
* the specified time limit | |
*/ | |
boolean awaitUninterruptibly(long timeout, TimeUnit unit); | |
/** | |
* Waits for this future to be completed within the | |
* specified time limit without interruption. This method catches an | |
* {@link InterruptedException} and discards it silently. | |
* | |
* @return {@code true} if and only if the future was completed within | |
* the specified time limit | |
*/ | |
boolean awaitUninterruptibly(long timeoutMillis); | |
/** | |
* Set the {@link ChannelFutureResult} for this {@link ChannelFuture} and mark it as complete. This will also notify all | |
* waiting threads and fire the {@link ChannelFutureListener} | |
* | |
* @param result the {@link ChannelFutureResult} | |
*/ | |
void setChannelFutureResult(ChannelFutureResult result); | |
/** | |
* Returns the {@link ChannelFutureResult} if the {@link ChannelFuture} was complete or <code>null</code> otherwise | |
* | |
* @return result then result of the {@link ChannelFuture} if it was complete | |
*/ | |
ChannelFutureResult getChannelFutureResult(); | |
} | |
public interface ChannelFutureResult { | |
/** | |
* Returns {@code true} if and only if the I/O operation was completed | |
* successfully. | |
*/ | |
boolean isSuccess(); | |
/** | |
* Returns the cause of the failed I/O operation if the I/O operation has | |
* failed. | |
* | |
* @return the cause of the failure. | |
* {@code null} if succeeded or this future is not | |
* completed yet. | |
*/ | |
Throwable getCause(); | |
/** | |
* Marks this future as a success and notifies all | |
* listeners. | |
* | |
* @return {@code true} if and only if successfully marked this future as | |
* a success. Otherwise {@code false} because this future is | |
* already marked as either a success or a failure. | |
*/ | |
boolean setSuccess(); | |
/** | |
* Marks this future as a failure and notifies all | |
* listeners. | |
* | |
* @return {@code true} if and only if successfully marked this future as | |
* a failure. Otherwise {@code false} because this future is | |
* already marked as either a success or a failure. | |
*/ | |
boolean setFailure(Throwable cause); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment