Package org.apache.sshd.common.future
Class DefaultSshFuture<T extends SshFuture>
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.common.future.AbstractSshFuture<T>
-
- org.apache.sshd.common.future.DefaultSshFuture<T>
-
- 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 ofSshFuture
.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Object
listeners
private java.lang.Object
lock
A lock used by the wait() methodprivate java.lang.Object
result
-
Fields inherited from class org.apache.sshd.common.future.AbstractSshFuture
CANCELED
-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Constructor Description DefaultSshFuture(java.lang.Object id, java.lang.Object lock)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
addListener(SshFutureListener<T> listener)
Adds an event listener which is notified when this future is completed.protected java.lang.Object
await0(long timeoutMillis, boolean interruptable)
Wait for the Future to be ready.void
cancel()
int
getNumRegisteredListeners()
java.lang.Object
getValue()
boolean
isCanceled()
boolean
isDone()
protected void
notifyListeners()
T
removeListener(SshFutureListener<T> listener)
Removes an existing event listener so it won't be notified when the future is completed.void
setValue(java.lang.Object newValue)
Sets the result of the asynchronous operation, and mark it as finished.java.lang.String
toString()
-
Methods inherited from class org.apache.sshd.common.future.AbstractSshFuture
asListener, asT, await, awaitUninterruptibly, formatExceptionMessage, getId, notifyListener, verifyResult
-
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.WaitableFuture
await, await, await, awaitUninterruptibly, awaitUninterruptibly, awaitUninterruptibly
-
-
-
-
Method Detail
-
await0
protected java.lang.Object await0(long timeoutMillis, boolean interruptable) throws java.io.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 classAbstractSshFuture<T extends SshFuture>
- 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.- 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.
-
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(java.lang.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 java.lang.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
- TheSshFutureListener
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
- TheSshFutureListener
instance to remove- Returns:
- The future instance
-
notifyListeners
protected void notifyListeners()
-
isCanceled
public boolean isCanceled()
-
cancel
public void cancel()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classAbstractSshFuture<T extends SshFuture>
-
-