goldengate.common.future
Class GgFuture

java.lang.Object
  extended by goldengate.common.future.GgFuture
Direct Known Subclasses:
GgChannelFuture, GgCompletedFuture

public class GgFuture
extends Object

Ftp Future operation
Completely inspired from the excellent ChannelFuture of Netty, but without any channel inside.

Author:
Frederic Bregier

Constructor Summary
GgFuture()
          Creates a new instance.
GgFuture(boolean cancellable)
          Creates a new instance.
 
Method Summary
 GgFuture 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, TimeUnit unit)
          Waits for this future to be completed within the specified time limit.
 GgFuture 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, TimeUnit unit)
          Waits for this future to be completed within the specified time limit without interruption.
 boolean cancel()
          Cancels the operation associated with this future and notifies all listeners if canceled successfully.
 Throwable getCause()
          Returns the cause of the failed operation if the operation has failed.
 boolean isCancelled()
          Returns true if and only if this future was canceled by a cancel() method.
 boolean isDone()
          Returns true if and only if this future is complete, regardless of whether the operation was successful, failed, or canceled.
 boolean isFailed()
          Returns true if and only if the operation was completed but unsuccessfully.
 boolean isSuccess()
          Returns true if and only if the operation was completed successfully.
 GgFuture rethrowIfFailed()
          Rethrows the exception that caused this future fail if this future is complete and failed.
 boolean setFailure(Throwable cause)
          Marks this future as a failure and notifies all listeners.
 boolean setSuccess()
          Marks this future as a success and notifies all listeners.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GgFuture

public GgFuture()
Creates a new instance.


GgFuture

public GgFuture(boolean cancellable)
Creates a new instance.

Parameters:
cancellable - true if and only if this future can be canceled
Method Detail

isDone

public boolean isDone()
Returns true if and only if this future is complete, regardless of whether the operation was successful, failed, or canceled.

Returns:
True if the future is complete

isSuccess

public boolean isSuccess()
Returns true if and only if the operation was completed successfully.

Returns:
True if the future is successful

isFailed

public boolean isFailed()
Returns true if and only if the operation was completed but unsuccessfully.

Returns:
True if the future is done but unsuccessful

getCause

public Throwable getCause()
Returns the cause of the failed operation if the operation has failed.

Returns:
the cause of the failure. null if succeeded or this future is not completed yet.

isCancelled

public boolean isCancelled()
Returns true if and only if this future was canceled by a cancel() method.

Returns:
True if the future was canceled

rethrowIfFailed

public GgFuture rethrowIfFailed()
                         throws Exception
Rethrows the exception that caused this future fail if this future is complete and failed.

Throws:
Exception

await

public GgFuture await()
               throws InterruptedException
Waits for this future to be completed.

Returns:
The GgFuture
Throws:
InterruptedException - if the current thread was interrupted

await

public boolean await(long timeout,
                     TimeUnit unit)
              throws InterruptedException
Waits for this future to be completed within the specified time limit.

Parameters:
timeout -
unit -
Returns:
true if and only if the future was completed within the specified time limit
Throws:
InterruptedException - if the current thread was interrupted

await

public boolean await(long timeoutMillis)
              throws InterruptedException
Waits for this future to be completed within the specified time limit.

Parameters:
timeoutMillis -
Returns:
true if and only if the future was completed within the specified time limit
Throws:
InterruptedException - if the current thread was interrupted

awaitUninterruptibly

public GgFuture awaitUninterruptibly()
Waits for this future to be completed without interruption. This method catches an InterruptedException and discards it silently.

Returns:
The GgFuture

awaitUninterruptibly

public boolean awaitUninterruptibly(long timeout,
                                    TimeUnit unit)
Waits for this future to be completed within the specified time limit without interruption. This method catches an InterruptedException and discards it silently.

Parameters:
timeout -
unit -
Returns:
true if and only if the future was completed within the specified time limit

awaitUninterruptibly

public boolean awaitUninterruptibly(long timeoutMillis)
Waits for this future to be completed within the specified time limit without interruption. This method catches an InterruptedException and discards it silently.

Parameters:
timeoutMillis -
Returns:
true if and only if the future was completed within the specified time limit

setSuccess

public boolean setSuccess()
Marks this future as a success and notifies all listeners.

Returns:
true if and only if successfully marked this future as a success. Otherwise false because this future is already marked as either a success or a failure.

setFailure

public boolean setFailure(Throwable cause)
Marks this future as a failure and notifies all listeners.

Parameters:
cause -
Returns:
true if and only if successfully marked this future as a failure. Otherwise false because this future is already marked as either a success or a failure.

cancel

public boolean cancel()
Cancels the operation associated with this future and notifies all listeners if canceled successfully.

Returns:
true if and only if the operation has been canceled. false if the operation can't be canceled or is already completed.


Copyright © 2009-2012 Frederic Bregier. All Rights Reserved.