First, the future system is the monitoring of the completion of an asynchronous operation, that is, the completion of the SetValue () monitoring; Get/setvalue actually encapsulates the result field, so to speak, the future system actually listens to the status of the result field;
How is the future used????? Let's take a look at the source code examples:
* Iosession session = ...;
* Closefuture future = Session.close (true);
*//Wait until the connection is closed
* future.awaituninterruptibly ();
*//Now connection should is closed.
* Assert future.isclosed ();
The future system is actually the listener handle of a series of operations, only one future exception, is connectionfuture, because the connection has not been established when there is no iosession, this time, Connectionfuture is actually returned by the Connect () of the Ioconnector's creator;
The asynchronous operation of the future is implemented by wait, and wait has two ways, one is interruptible, and the other is non-disruptive, which jumps out of wait when an exception occurs, and the exception continues in the wait state until the Ready field is true.
Iofuturelistener a listener (wrapper) of a certain class of iofuture, which only exposes a api:operationcomplete, waits to be notified, and can operate on iofuture by invoking the wrapper method, such as closing; The following code is an implementation of an anonymous function that is encapsulated by the interface itself.
static iofuturelistener<iofuture> CLOSE = new Iofuturelistener<iofuture> () {
public void Operationcomplete (iofuture) {
Future.getsession (). Close (true);
}
};
Here is the UML icon for the future system:
Mina source reading of the future system