Mina source reading of the future system

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.