10.4. Robust Connection

In Chapter 6, the concept of Comet and nonblocking IO was briefly introduced. The context there was scalable messaging and real-time data pushing. In this section, I extend the discussion to a more generic discussion on nonblocking IO in Java. The concepts here can be leveraged to build nonblocking channels that will work well with most existing channel types and could also serve well to create nonblocking socket connections between a Flex application and a BlazeDS server. Non-blocking channels allow for a greater number of connections to be served provided they are not all active at the same time always. LCDS uses NIO channels for connection scalability. You can include the same robustness in BlazeDS as well. Only Java NIO fundamentals are covered in this section.

As a result of JSR 51 efforts and starting with Java 1.4, a new IO package is available in Java. It's appropriately called the New IO, or NIO for short. The NIO package includes a number of new improvements to the traditional IO in Java. The one that we are interested in the context of this section is the ability to create nonblocking sockets, which allows input/output operations on a channel without blocking the underlying processes. This is a great new feature. Traditional multi-threaded servers for processing multiple simultaneous client requests can now be replaced in many situations with nonblocking sockets.

NIO nonblocking channels utilize a java.nio.Buffer to read and write data. A Buffer ...

Get Professional BlazeDS: Creating Rich Internet Applications with Flex® and Java® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.