| 1 |
|
| 2 |
|
| 3 |
Transport Next Generation |
| 4 |
------------------------- |
| 5 |
|
| 6 |
Author: Bela Ban |
| 7 |
|
| 8 |
The next version of the transport (org.jgroups.protocols.TP) should be NIO based: TP has an NIO selector, and subclasses |
| 9 |
such as TCP or UDP only register NIO channels with TP. For example, UDP would create 2 NIO channels, a unicast and a |
| 10 |
multicast channel and register them with TP. TCP would do an accept() in a loop and, whenever a new peer connects, |
| 11 |
register the client's NIO socket channel with TP's selector. |
| 12 |
|
| 13 |
TP would therefore be a multiplexer which handles a number of connections, be they TCP or UDP connections. Therefore, |
| 14 |
the connection table functionality of TCP would be largely removed, because this is now handled by TP itself. |
| 15 |
|
| 16 |
This requires JDK 7, because NetworkChannel.open() does not yet exist in prior JDKs. To be more precise, it does exist, |
| 17 |
but only for datagram sockets (DatagramChannel.open()), not for multicast sockets (no MulticastChannel.open()). |
| 18 |
|
| 19 |
Transport NetGen should be combined with the copyless stack (https://jira.jboss.org/jira/browse/JGRP-809). On the |
| 20 |
receive side, this is done by passing the selection key to a thread from the thread pool. If the key has an attachment, |
| 21 |
it is the ByteBuffer previously created by a (possibly different) thread to receive the message. The receiver thread |
| 22 |
will then simply call read() (or receive()) on the input NIO channel and - when all bytes have been received (defined |
| 23 |
by the initial length field of a message) - unmarshall the buffer and pass the resulting message up the stack. |
| 24 |
When there is no attachment, the receiver thread creates one (according to the length field which prefixes each message) |
| 25 |
and reads the bytes available from the NIO channel into it. If the number of bytes read is equals to the expected length, |
| 26 |
the thread proceeds to unmarshalling and passing the message up. Otherwise, it attaches the ByteBuffer to the selection |
| 27 |
key and returns. Later, a (potentially) different thread will complete reading the full message and then finish the job. |
| 28 |
|
| 29 |
|