Package org.apache.sshd.common.future
Class AbstractSshFuture<T extends SshFuture<T>>
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.common.future.AbstractSshFuture<T>
-
- Type Parameters:
T
- Type of future
- All Implemented Interfaces:
SshFuture<T>
,WaitableFuture
- Direct Known Subclasses:
DefaultSshFuture
public abstract class AbstractSshFuture<T extends SshFuture<T>> extends AbstractLoggingBean implements SshFuture<T>
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Object
id
-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractSshFuture(java.lang.Object id)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected SshFutureListener<T>
asListener(java.lang.Object o)
protected T
asT()
boolean
await(long timeoutMillis, CancelOption... options)
Wait for the asynchronous operation to complete with the specified timeout.protected abstract java.lang.Object
await0(long timeoutMillis, boolean interruptable, CancelOption... options)
Wait for the Future to be ready.boolean
awaitUninterruptibly(long timeoutMillis, CancelOption... options)
Wait for the asynchronous operation to complete with the specified timeout uninterruptibly.protected <E extends java.lang.Throwable>
EformatExceptionMessage(java.util.function.Function<? super java.lang.String,? extends E> exceptionCreator, java.lang.String format, java.lang.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.java.lang.Object
getId()
protected void
notifyListener(SshFutureListener<T> l)
java.lang.String
toString()
protected <R> R
verifyResult(java.lang.Class<? extends R> expectedType, long timeout, CancelOption... options)
Waits (interruptible) for the specified timeout (msec.) and then checks the result:-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.common.future.SshFuture
addListener, removeListener
-
Methods inherited from interface org.apache.sshd.common.future.WaitableFuture
await, await, await, awaitUninterruptibly, awaitUninterruptibly, awaitUninterruptibly, isDone
-
-
-
-
Method Detail
-
getId
public java.lang.Object getId()
- Specified by:
getId
in interfaceWaitableFuture
- Returns:
- Some identifier useful as
toString()
value
-
await
public boolean await(long timeoutMillis, CancelOption... options) throws java.io.IOException
Description copied from interface:WaitableFuture
Wait for the asynchronous operation to complete with the specified timeout.- Specified by:
await
in interfaceWaitableFuture
- Parameters:
timeoutMillis
- Wait time in millisecondsoptions
- OptionalCancelOption
s defining the behavior on time-out or interrupt; ignored if the future is notCancellable
.- Returns:
true
if the operation is completed.- Throws:
java.io.IOException
- if failed - specificallyInterruptedIOException
if waiting was interrupted
-
awaitUninterruptibly
public boolean awaitUninterruptibly(long timeoutMillis, CancelOption... options)
Description copied from interface:WaitableFuture
Wait for the asynchronous operation to complete with the specified timeout uninterruptibly.- Specified by:
awaitUninterruptibly
in interfaceWaitableFuture
- Parameters:
timeoutMillis
- Wait time in millisecondsoptions
- OptionalCancelOption
s defining the behavior on time-out; ignored if the future is notCancellable
.- Returns:
true
if the operation is finished.
-
verifyResult
protected <R> R verifyResult(java.lang.Class<? extends R> expectedType, long timeout, CancelOption... options) throws java.io.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 appropriateIOException
-
If the result is of the expected type, then cast and return it
-
If the result is a
Throwable
then throw anIOException
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 typetimeout
- The timeout (millis) to wait for a resultoptions
- OptionalCancelOption
s defining the behavior on time-out or interrupt.- Returns:
- The (never
null
) result - Throws:
java.io.IOException
- If failed to retrieve the expected result on time
-
-
await0
protected abstract java.lang.Object await0(long timeoutMillis, boolean interruptable, CancelOption... options) throws java.io.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 readyinterruptable
- Tells if the wait can be interrupted or not. Iftrue
and the thread is interrupted then anInterruptedIOException
is thrown.options
- OptionalCancelOption
defining the behavior on time-out or interrupt.- Returns:
- The non-
null
result object if the Future is ready,null
if the timeout expired and no result was received - Throws:
java.io.InterruptedIOException
- If the thread has been interrupted when it's not allowed.
-
asListener
protected SshFutureListener<T> asListener(java.lang.Object o)
-
notifyListener
protected void notifyListener(SshFutureListener<T> l)
-
asT
protected T asT()
-
formatExceptionMessage
protected <E extends java.lang.Throwable> E formatExceptionMessage(java.util.function.Function<? super java.lang.String,? extends E> exceptionCreator, java.lang.String format, java.lang.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 ofThrowable
being generated- Parameters:
exceptionCreator
- The exception creator from the formatted messageformat
- The extra payload format as perString.format(String, Object...)
args
- The formatting arguments- Returns:
- The generated exception
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-