Package org.apache.sshd.common.future
Class AbstractSshFuture<T extends SshFuture>
- 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> extends AbstractLoggingBean implements SshFuture<T>
- Author:
- Apache MINA SSHD Project
-
-
Field Summary
Fields Modifier and Type Field Description protected static ObjectCANCELEDA default value to indicate the future has been canceled-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractSshFuture(Object id)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected SshFutureListener<T>asListener(Object o)protected TasT()booleanawait(long timeoutMillis)Wait for the asynchronous operation to complete with the specified timeout.protected abstract Objectawait0(long timeoutMillis, boolean interruptable)Wait for the Future to be ready.booleanawaitUninterruptibly(long timeoutMillis)Wait for the asynchronous operation to complete with the specified timeout uninterruptibly.protected <E extends Throwable>
EformatExceptionMessage(Function<? super String,? extends E> exceptionCreator, String format, Object... args)Generates an exception whose message is prefixed by the future simple class name +identifieras a hint to the context of the failure.ObjectgetId()protected voidnotifyListener(SshFutureListener<T> l)StringtoString()protected <R> RverifyResult(Class<? extends R> expectedType, long timeout)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
-
-
-
-
Field Detail
-
CANCELED
protected static final Object CANCELED
A default value to indicate the future has been canceled
-
-
Constructor Detail
-
AbstractSshFuture
protected AbstractSshFuture(Object id)
- Parameters:
id- Some identifier useful astoString()value
-
-
Method Detail
-
getId
public Object getId()
- Specified by:
getIdin interfaceWaitableFuture- Returns:
- Some identifier useful as
toString()value
-
await
public boolean await(long timeoutMillis) throws IOExceptionDescription copied from interface:WaitableFutureWait for the asynchronous operation to complete with the specified timeout.- Specified by:
awaitin interfaceWaitableFuture- Parameters:
timeoutMillis- Wait time in milliseconds- Returns:
trueif the operation is completed.- Throws:
IOException- if failed - specificallyInterruptedIOExceptionif waiting was interrupted
-
awaitUninterruptibly
public boolean awaitUninterruptibly(long timeoutMillis)
Description copied from interface:WaitableFutureWait for the asynchronous operation to complete with the specified timeout uninterruptibly.- Specified by:
awaitUninterruptiblyin interfaceWaitableFuture- Parameters:
timeoutMillis- Wait time in milliseconds- Returns:
trueif 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
nullthen 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
Throwablethen throw anIOExceptionwhose cause is the original exception -
Otherwise (should never happen), throw a
StreamCorruptedExceptionwith 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 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 readyinterruptable- Tells if the wait can be interrupted or not. Iftrueand the thread is interrupted then anInterruptedIOExceptionis thrown.- Returns:
- The non-
nullresult object if the Future is ready,nullif the timeout expired and no result was received - Throws:
InterruptedIOException- If the thread has been interrupted when it's not allowed.
-
asListener
protected SshFutureListener<T> asListener(Object o)
-
notifyListener
protected void notifyListener(SshFutureListener<T> l)
-
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 +identifieras a hint to the context of the failure.- Type Parameters:
E- Type ofThrowablebeing 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
-
-