Class DefaultIoFuture
java.lang.Object
org.apache.mina.core.future.DefaultIoFuture
- All Implemented Interfaces:
IoFuture
- Direct Known Subclasses:
AbstractIoService.ServiceOperationFuture, CompositeIoFuture, DefaultCloseFuture, DefaultConnectFuture, DefaultReadFuture, DefaultWriteFuture
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final longA number of milliseconds to wait between two deadlock controls ( 5 seconds )private IoFutureListener<?> The first listener.private final ObjectA lock used by the wait() methodprivate List<IoFutureListener<?>> All the other listeners, in case we have more than oneprivate booleanThe flag used to determinate if the Future is completed or notprivate Objectprivate final IoSessionThe associated sessionprivate intA counter for the number of threads waiting on this future -
Constructor Summary
ConstructorsConstructorDescriptionDefaultIoFuture(IoSession session) Creates a new instance associated with anIoSession. -
Method Summary
Modifier and TypeMethodDescriptionaddListener(IoFutureListener<?> listener) Adds an eventlistenerwhich is notified when this future is completed.await()Wait for the asynchronous operation to complete.booleanawait(long timeoutMillis) Wait for the asynchronous operation to complete with the specified timeout.booleanWait for the asynchronous operation to complete with the specified timeout.private booleanawait0(long timeoutMillis, boolean interruptable) Wait for the Future to be ready.Wait for the asynchronous operation to complete uninterruptibly.booleanawaitUninterruptibly(long timeoutMillis) Wait for the asynchronous operation to complete with the specified timeout uninterruptibly.booleanawaitUninterruptibly(long timeout, TimeUnit unit) Wait for the asynchronous operation to complete with the specified timeout uninterruptibly.private voidCheck for a deadlock, ie look into the stack trace that we don't have already an instance of the caller.protected ObjectgetValue()booleanisDone()voidjoin()Deprecated.booleanjoin(long timeoutMillis) Deprecated.Replaced withawaitUninterruptibly(long).private voidnotifyListener(IoFutureListener listener) private voidNotify the listeners, if we have some.removeListener(IoFutureListener<?> listener) Removes an existing eventlistenerso it won't be notified when the future is completed.booleanSets the result of the asynchronous operation, and mark it as finished.
-
Field Details
-
DEAD_LOCK_CHECK_INTERVAL
private static final long DEAD_LOCK_CHECK_INTERVALA number of milliseconds to wait between two deadlock controls ( 5 seconds )- See Also:
-
session
The associated session -
lock
A lock used by the wait() method -
firstListener
The first listener. This is easier to have this variable when we most of the time have one single listener -
otherListeners
All the other listeners, in case we have more than one -
result
-
ready
private boolean readyThe flag used to determinate if the Future is completed or not -
waiters
private int waitersA counter for the number of threads waiting on this future
-
-
Constructor Details
-
DefaultIoFuture
-
-
Method Details
-
getSession
- Specified by:
getSessionin interfaceIoFuture- Returns:
- the
IoSessionwhich is associated with this future.
-
join
Deprecated.Replaced withawaitUninterruptibly(). -
join
Deprecated.Replaced withawaitUninterruptibly(long). -
await
Wait for the asynchronous operation to complete. The attached listeners will be notified when the operation is completed.- Specified by:
awaitin interfaceIoFuture- Returns:
- The instance of IoFuture that we are waiting for
- Throws:
InterruptedException- If the thread is interrupted while waiting
-
await
Wait for the asynchronous operation to complete with the specified timeout.- Specified by:
awaitin interfaceIoFuture- Parameters:
timeout- The maximum delay to wait before getting outunit- the type of unit for the delay (seconds, minutes...)- Returns:
trueif the operation is completed.- Throws:
InterruptedException- If the thread is interrupted while waiting
-
await
Wait for the asynchronous operation to complete with the specified timeout.- Specified by:
awaitin interfaceIoFuture- Parameters:
timeoutMillis- The maximum milliseconds to wait before getting out- Returns:
trueif the operation is completed.- Throws:
InterruptedException- If the thread is interrupted while waiting
-
awaitUninterruptibly
Wait for the asynchronous operation to complete uninterruptibly. The attached listeners will be notified when the operation is completed.- Specified by:
awaitUninterruptiblyin interfaceIoFuture- Returns:
- the current IoFuture
-
awaitUninterruptibly
Wait for the asynchronous operation to complete with the specified timeout uninterruptibly.- Specified by:
awaitUninterruptiblyin interfaceIoFuture- Parameters:
timeout- The maximum delay to wait before getting outunit- the type of unit for the delay (seconds, minutes...)- Returns:
trueif the operation is completed.
-
awaitUninterruptibly
public boolean awaitUninterruptibly(long timeoutMillis) Wait for the asynchronous operation to complete with the specified timeout uninterruptibly.- Specified by:
awaitUninterruptiblyin interfaceIoFuture- Parameters:
timeoutMillis- The maximum milliseconds to wait before getting out- Returns:
trueif the operation is finished.
-
await0
Wait for the Future to be ready. If the requested delay is 0 or negative, this method immediately returns the value of the 'ready' flag. Every 5 second, the wait will be suspended to be able to check if there is a deadlock or not.- Parameters:
timeoutMillis- The delay we will wait for the Future to be readyinterruptable- Tells if the wait can be interrupted or not- Returns:
trueif the Future is ready- Throws:
InterruptedException- If the thread has been interrupted when it's not allowed.
-
checkDeadLock
private void checkDeadLock()Check for a deadlock, ie look into the stack trace that we don't have already an instance of the caller. -
isDone
-
setValue
Sets the result of the asynchronous operation, and mark it as finished.- Parameters:
newValue- The result to store into the Future- Returns:
trueif the value has been set,falseif the future already has a value (thus is in ready state)
-
getValue
- Returns:
- the result of the asynchronous operation.
-
addListener
Adds an eventlistenerwhich is notified when this future is completed. If the listener is added after the completion, the listener is directly notified.- Specified by:
addListenerin interfaceIoFuture- Parameters:
listener- The listener to add- Returns:
- the current IoFuture
-
removeListener
Removes an existing eventlistenerso it won't be notified when the future is completed.- Specified by:
removeListenerin interfaceIoFuture- Parameters:
listener- The listener to remove- Returns:
- the current IoFuture
-
notifyListeners
private void notifyListeners()Notify the listeners, if we have some. -
notifyListener
-
awaitUninterruptibly().