Top Description Fields Constructors Methods
org.apache.sshd.common.future

public Class DefaultSshFuture<T extends SshFuture<T>>

extends AbstractSshFuture<T extends SshFuture<T>>
Class Inheritance
Known Direct Subclasses
org.apache.sshd.common.future.DefaultVerifiableSshFuture, org.apache.sshd.common.future.DefaultCancelFuture, org.apache.sshd.common.future.DefaultCloseFuture
Type Parameters
<T>
Type of future
Imports
java.io.InterruptedIOException, java.lang.reflect.Array, java.util.Arrays, .Objects, java.util.concurrent.CancellationException, .TimeoutException, org.apache.sshd.common.util.GenericUtils, .ValidateUtils

A default implementation of SshFuture.
Author
Apache MINA SSHD Project

Field Summary

Modifier and TypeField and Description
private Object
private final Object
lock

A lock used by the wait() method

private Object

Constructor Summary

AccessConstructor and Description
public
DefaultSshFuture(Object
Some identifier useful as toString() value
id
,
Object
A synchronization object for locking access - if null then synchronization occurs on this instance
lock
)

Creates a new instance.

Method Summary

Modifier and TypeMethod and Description
public T
addListener(SshFutureListener<T>
The SshFutureListener instance to add
listener
)

Implements org.apache.sshd.common.future.SshFuture.addListener.

Adds an event listener which is notified when this future is completed.

protected Object
await0(long
The delay we will wait for the Future to be ready
timeoutMillis
,
boolean
Tells if the wait can be interrupted or not. If true and the thread is interrupted then an InterruptedIOException is thrown.
interruptable
,
CancelOption...
Optional CancelOption defining the behavior on time-out or interrupt.
options
)

Implements abstract org.apache.sshd.common.future.AbstractSshFuture.await0.

Wait for the Future to be ready.

private CancelFuture
cancelOnTimeout(long timeoutMillis, CancelOption... options)

protected CancelFuture

Returns:

A CancelFuture that can be used to wait for the cancellation to have been effected, or null if the future cannot be canceled.
createCancellation
()

Creates a CancelFuture if this future can be canceled.

public int
public Object

Returns:

The result of the asynchronous operation - or null if none set.
getValue
()

public boolean
protected void
protected void
onValueSet(Object
that was just set
value
)

Callback that is invoked under lock when the future's value is set.

public T
removeListener(SshFutureListener<T>
The SshFutureListener instance to remove
listener
)

Implements org.apache.sshd.common.future.SshFuture.removeListener.

Removes an existing event listener so it won't be notified when the future is completed.

public void
setValue(Object
The operation result
newValue
)

Sets the result of the asynchronous operation, and mark it as finished.

public String
toString()

Overrides org.apache.sshd.common.future.AbstractSshFuture.toString.

Returns a string representation of the object.

Inherited from org.apache.sshd.common.future.AbstractSshFuture:
asListenerasTawaitawaitUninterruptiblyformatExceptionMessagegetIdnotifyListenerverifyResult

Field Detail

listenersback to summary
private Object listeners
lockback to summary
private final Object lock

A lock used by the wait() method

resultback to summary
private Object result

Constructor Detail

DefaultSshFutureback to summary
public DefaultSshFuture(Object id, Object lock)

Creates a new instance.

Parameters
id:Object

Some identifier useful as toString() value

lock:Object

A synchronization object for locking access - if null then synchronization occurs on this instance

Method Detail

addListenerback to summary
public T addListener(SshFutureListener<T> listener)

Implements org.apache.sshd.common.future.SshFuture.addListener.

Doc from org.apache.sshd.common.future.SshFuture.addListener.

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:SshFutureListener<T>

The SshFutureListener instance to add

Returns:T

The future instance

Annotations
@Override
await0back to summary
protected Object await0(long timeoutMillis, boolean interruptable, CancelOption... options) throws InterruptedIOException

Implements abstract org.apache.sshd.common.future.AbstractSshFuture.await0.

Doc from org.apache.sshd.common.future.AbstractSshFuture.await0.

Wait for the Future to be ready. If the requested delay is 0 or negative, this method returns immediately.

Parameters
timeoutMillis:long

The delay we will wait for the Future to be ready

interruptable:boolean

Tells if the wait can be interrupted or not. If true and the thread is interrupted then an InterruptedIOException is thrown.

options:CancelOption[]

Optional CancelOption defining the behavior on time-out or interrupt.

Returns:Object

The non-null result object if the Future is ready, null if the timeout expired and no result was received

Annotations
@Override
Exceptions
InterruptedIOException:
If the thread has been interrupted when it's not allowed.
cancelOnTimeoutback to summary
private CancelFuture cancelOnTimeout(long timeoutMillis, CancelOption... options)
createCancellationback to summary
protected CancelFuture createCancellation()

Creates a CancelFuture if this future can be canceled.

This doesn't cancel this future yet.

Returns:CancelFuture

A CancelFuture that can be used to wait for the cancellation to have been effected, or null if the future cannot be canceled.

getNumRegisteredListenersback to summary
public int getNumRegisteredListeners()
getValueback to summary
public Object getValue()
Returns:Object

The result of the asynchronous operation - or null if none set.

isDoneback to summary
public boolean isDone()

Implements org.apache.sshd.common.future.WaitableFuture.isDone.

Returns:boolean

Doc from org.apache.sshd.common.future.WaitableFuture.isDone.

true if the asynchronous operation is completed

Note

it is up to the caller to determine whether it was a successful or failed completion.

Annotations
@Override
notifyListenersback to summary
protected void notifyListeners()
onValueSetback to summary
protected void onValueSet(Object value)

Callback that is invoked under lock when the future's value is set.

As this is called under lock, subclasses should not do any elaborate processing. It is intended to give subclasses a safe and convenient way to update local state before any listeners are invoked or callers waiting in await0(long, boolean, CancelOption...) are woken up.

The default implementation does nothing.

Parameters
value:Object

that was just set

removeListenerback to summary
public T removeListener(SshFutureListener<T> listener)

Implements org.apache.sshd.common.future.SshFuture.removeListener.

Doc from org.apache.sshd.common.future.SshFuture.removeListener.

Removes an existing event listener so it won't be notified when the future is completed.

Parameters
listener:SshFutureListener<T>

The SshFutureListener instance to remove

Returns:T

The future instance

Annotations
@Override
setValueback to summary
public void setValue(Object newValue)

Sets the result of the asynchronous operation, and mark it as finished.

Parameters
newValue:Object

The operation result

toStringback to summary
public String toString()

Overrides org.apache.sshd.common.future.AbstractSshFuture.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override