Class DefaultSshFuture<T extends SshFuture>

Type Parameters:
T - Type of future
All Implemented Interfaces:
SshFuture<T>, WaitableFuture
Direct Known Subclasses:
DefaultCloseFuture, DefaultVerifiableSshFuture, Nio2Connector.DefaultIoConnectFuture

public class DefaultSshFuture<T extends SshFuture> extends AbstractSshFuture<T>
A default implementation of SshFuture.
  • Field Details

    • lock

      private final Object lock
      A lock used by the wait() method
    • listeners

      private Object listeners
    • result

      private Object result
  • Constructor Details

    • DefaultSshFuture

      public DefaultSshFuture(Object id, Object lock)
      Creates a new instance.
      Parameters:
      id - Some identifier useful as toString() value
      lock - A synchronization object for locking access - if null then synchronization occurs on this instance
  • Method Details

    • await0

      protected Object await0(long timeoutMillis, boolean interruptable) throws InterruptedIOException
      Description copied from class: AbstractSshFuture
      Wait for the Future to be ready. If the requested delay is 0 or negative, this method returns immediately.
      Specified by:
      await0 in class AbstractSshFuture<T extends SshFuture>
      Parameters:
      timeoutMillis - The delay we will wait for the Future to be ready
      interruptable - Tells if the wait can be interrupted or not. If true and the thread is interrupted then an InterruptedIOException is thrown.
      Returns:
      The non-null result object if the Future is ready, null if the timeout expired and no result was received
      Throws:
      InterruptedIOException - If the thread has been interrupted when it's not allowed.
    • isDone

      public boolean isDone()
      Returns:
      true if the asynchronous operation is completed. Note: it is up to the caller to determine whether it was a successful or failed completion.
    • setValue

      public void setValue(Object newValue)
      Sets the result of the asynchronous operation, and mark it as finished.
      Parameters:
      newValue - The operation result
    • getNumRegisteredListeners

      public int getNumRegisteredListeners()
    • getValue

      public Object getValue()
      Returns:
      The result of the asynchronous operation - or null if none set.
    • addListener

      public T addListener(SshFutureListener<T> listener)
      Description copied from interface: SshFuture
      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.
      Parameters:
      listener - The SshFutureListener instance to add
      Returns:
      The future instance
    • removeListener

      public T removeListener(SshFutureListener<T> listener)
      Description copied from interface: SshFuture
      Removes an existing event listener so it won't be notified when the future is completed.
      Parameters:
      listener - The SshFutureListener instance to remove
      Returns:
      The future instance
    • notifyListeners

      protected void notifyListeners()
    • isCanceled

      public boolean isCanceled()
    • cancel

      public void cancel()
    • toString

      public String toString()
      Overrides:
      toString in class AbstractSshFuture<T extends SshFuture>