Saturday, 21 February 2009

Java New IO: Channels

Channels (which came in JDK1.4) represent connections to entities capable of performing I/O operations e.g. files and sockets; and selectors, for multiplexed non-blocking I/O operations. It uses an idiom from telecommunications.

What is this business of multiplexing I/O operations?

In electronics, a multiplexer is an electronic component that performs multiplexing: selects one of many digital or analog input signals and outputs to a single line. Demultiplexers do the reverse. Ther term originated in telegraphy and became used widely in the context of computer networks. The two main forms of multiplexing are time-division (turn-taking) multiplexing (TDM) and frequency-division multiplexing (non-overlapping frequency ranges for different signals) aka FDM. Both are methods of "sharing a medium" / "sharing the airwaves".

The Java Selector class is a multiplexor of SelectableChannel objects. These implement the Channel interface, a nexus for I/O operations (nexus = form of connection. the hub).

Some of the interesting types of Channels are GatheringByteChannels and ScatteringByteChannels. Within this melee of channels we also see DatagramChannel and ServerSocketChannel in the mix.

Read the original JSR for the NIO library. NIO2 is currently in development (the expert group includes Sun, Doug Lea, IBM Google). By the way, Doug has a very interesting paper on design patterns for avionics control systems

To see how NIO may change in Java7 see the Draft API documentation.

No comments:

Blog Archive