Class AbstractSshFuture<T extends SshFuture>

    • Field Detail

      • CANCELED

        protected static final Object CANCELED
        A default value to indicate the future has been canceled
      • debugEnabled

        protected final boolean debugEnabled
      • traceEnabled

        protected final boolean traceEnabled
    • Constructor Detail

      • AbstractSshFuture

        protected AbstractSshFuture​(Object id)
        Parameters:
        id - Some identifier useful as toString() value
    • Method Detail

      • getId

        public Object getId()
        Specified by:
        getId in interface WaitableFuture
        Returns:
        Some identifier useful as toString() value
      • await

        public boolean await​(long timeoutMillis)
                      throws IOException
        Description copied from interface: WaitableFuture
        Wait for the asynchronous operation to complete with the specified timeout.
        Specified by:
        await in interface WaitableFuture
        Parameters:
        timeoutMillis - Wait time in milliseconds
        Returns:
        true if the operation is completed.
        Throws:
        IOException - if failed - specifically InterruptedIOException if waiting was interrupted
      • awaitUninterruptibly

        public boolean awaitUninterruptibly​(long timeoutMillis)
        Description copied from interface: WaitableFuture
        Wait for the asynchronous operation to complete with the specified timeout uninterruptibly.
        Specified by:
        awaitUninterruptibly in interface WaitableFuture
        Parameters:
        timeoutMillis - Wait time in milliseconds
        Returns:
        true if the operation is finished.
      • verifyResult

        protected <R> R verifyResult​(Class<? extends R> expectedType,
                                     long timeout)
                              throws IOException

        Waits (interruptible) for the specified timeout (msec.) and then checks the result:

        • If result is null then timeout is assumed to have expired - throw an appropriate IOException

        • If the result is of the expected type, then cast and return it

        • If the result is an IOException then re-throw it

        • If the result is a Throwable then throw an IOException whose cause is the original exception

        • Otherwise (should never happen), throw a StreamCorruptedException with the name of the result type

        Type Parameters:
        R - The generic result type
        Parameters:
        expectedType - The expected result type
        timeout - The timeout (millis) to wait for a result
        Returns:
        The (never null) result
        Throws:
        IOException - If failed to retrieve the expected result on time
      • await0

        protected abstract Object await0​(long timeoutMillis,
                                         boolean interruptable)
                                  throws InterruptedIOException
        Wait for the Future to be ready. If the requested delay is 0 or negative, this method returns immediately.
        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.
      • asT

        protected T asT()
      • formatExceptionMessage

        protected <E extends Throwable> E formatExceptionMessage​(Function<? super String,​? extends E> exceptionCreator,
                                                                 String format,
                                                                 Object... args)
        Generates an exception whose message is prefixed by the future simple class name + identifier as a hint to the context of the failure.
        Type Parameters:
        E - Type of Throwable being generated
        Parameters:
        exceptionCreator - The exception creator from the formatted message
        format - The extra payload format as per String.format(String, Object...)
        args - The formatting arguments
        Returns:
        The generated exception