|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.tomp2p.futures.BaseFutureImpl<K>
K
- The class that extends BaseFuture and is used to return back the type for method calls. E.g, if K is
FutureDHT await() returns FutureDHT.public abstract class BaseFutureImpl<K extends BaseFuture>
The base for all BaseFuture implementations. Be aware of possible deadlocks. Never await from a listener. This class is heavily inspired by MINA and Netty.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface net.tomp2p.futures.BaseFuture |
---|
BaseFuture.FutureType |
Field Summary | |
---|---|
protected boolean |
completed
|
protected Object |
lock
|
protected String |
reason
|
protected BaseFuture.FutureType |
type
|
Constructor Summary | |
---|---|
BaseFutureImpl()
Default constructor that sets the lock object, which is used for synchronization to this instance. |
Method Summary | |
---|---|
K |
addCancellation(Cancellable cancellable)
Adds a cancel listener to this future, which is called when cancel is executed. |
K |
addListener(BaseFutureListener<? extends BaseFuture> listener)
Adds a listener which is notified when the state of this future changes. |
K |
addListener(BaseFutureListener<? extends BaseFuture> listener,
boolean last)
Adds a listener which is notified when the state of this future changes. |
K |
await()
Wait for the asynchronous operation to end. |
boolean |
await(long timeoutMillis)
Wait for the asynchronous operation to end with the specified timeout. |
K |
awaitListeners()
Waits until all the listener finished. |
K |
awaitUninterruptibly()
Wait for the asynchronous operation to end without interruption. |
boolean |
awaitUninterruptibly(long timeoutMillis)
Wait for the asynchronous operation to end with the specified timeout without interruption. |
void |
cancel()
This method gets called if a future is cancelled. |
String |
getFailedReason()
The default failed reason is Unknown. |
BaseFuture.FutureType |
getType()
If the type is not OK, then something unexpected happened. |
boolean |
isCompleted()
Checks if the asynchronous operation is finished. |
boolean |
isFailed()
Checks if operation has failed. |
boolean |
isSuccess()
Returns the opposite of isFailed (returns !isFailed). |
protected void |
notifyListerenrs()
Always call this from outside synchronized(lock)! |
K |
removeListener(BaseFutureListener<? extends BaseFuture> listener)
Removes a listener which is notified when the state of this future changes. |
protected void |
self(K self2)
|
protected boolean |
setCompletedAndNotify()
Make sure that the calling method has synchronized (lock) |
K |
setFailed(BaseFuture origin)
Sets the failed flat to true and the completed flag to true. |
K |
setFailed(String failed)
Sets the failed flat to true and the completed flag to true. |
K |
setFailed(String failed,
BaseFuture origin)
Sets the failed flat to true and the completed flag to true. |
K |
setFailed(String failed,
Throwable t)
Sets the failed flat to true and the completed flag to true. |
K |
setFailed(Throwable t)
Sets the failed flat to true and the completed flag to true. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final Object lock
protected boolean completed
protected BaseFuture.FutureType type
protected String reason
Constructor Detail |
---|
public BaseFutureImpl()
Method Detail |
---|
protected void self(K self2)
self2
- Set the type so that we are able to return it to the user. This is for making the API much more
usable.public K await() throws InterruptedException
BaseFuture
await
in interface BaseFuture
InterruptedException
- if thread is interruptedpublic K awaitUninterruptibly()
BaseFuture
awaitUninterruptibly
in interface BaseFuture
public boolean await(long timeoutMillis) throws InterruptedException
BaseFuture
await
in interface BaseFuture
timeoutMillis
- time to wait at most
InterruptedException
- if thread is interruptedpublic boolean awaitUninterruptibly(long timeoutMillis)
BaseFuture
awaitUninterruptibly
in interface BaseFuture
timeoutMillis
- to wait at most
public boolean isCompleted()
BaseFuture
isCompleted
in interface BaseFuture
public boolean isSuccess()
BaseFuture
isSuccess
in interface BaseFuture
public boolean isFailed()
BaseFuture
isFailed
in interface BaseFuture
public K setFailed(BaseFuture origin)
BaseFuture
setFailed
in interface BaseFuture
origin
- The origin of failure
public K setFailed(String failed, BaseFuture origin)
BaseFuture
setFailed
in interface BaseFuture
failed
- The reason of failureorigin
- The origin of failure
public K setFailed(Throwable t)
BaseFuture
setFailed
in interface BaseFuture
t
- The stack trace where the failure happened
public K setFailed(String failed, Throwable t)
BaseFuture
setFailed
in interface BaseFuture
failed
- The reason of failuret
- The stack trace where the failure happened
public K setFailed(String failed)
BaseFuture
setFailed
in interface BaseFuture
failed
- The reason of failure
public String getFailedReason()
BaseFuture
getFailedReason
in interface BaseFuture
public BaseFuture.FutureType getType()
BaseFuture
getType
in interface BaseFuture
protected boolean setCompletedAndNotify()
public K awaitListeners() throws InterruptedException
BaseFuture
awaitListeners
in interface BaseFuture
InterruptedException
- If interrupted from outsidepublic K addListener(BaseFutureListener<? extends BaseFuture> listener)
BaseFuture
addListener
in interface BaseFuture
listener
- The listener extends the BaseFuture
public K addListener(BaseFutureListener<? extends BaseFuture> listener, boolean last)
BaseFuture
addListener
in interface BaseFuture
listener
- The listener extends the BaseFuturelast
- Set to true if the listener should be added at the end of the list, true if it should be added first
protected void notifyListerenrs()
public K removeListener(BaseFutureListener<? extends BaseFuture> listener)
BaseFuture
removeListener
in interface BaseFuture
listener
- The listener extends the BaseFuture
public K addCancellation(Cancellable cancellable)
BaseFuture
addCancellation
in interface BaseFuture
cancellable
- A cancellable class
public void cancel()
Cancellable
cancel
in interface Cancellable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |