org.jgroups.protocols

Class UDP_NIO

public class UDP_NIO extends Protocol implements Receiver

Multicast transport. Similar to UDP, but binds to multiple (or all) interfaces for sending and receiving multicast and unicast traffic.
The list of interfaces can be set via a property (comma-delimited list of IP addresses or "all" for all interfaces). Note that this class only works under JDK 1.4 and higher.
For each of the interfaces listed we create a Listener, which listens on the group multicast address and creates a unicast datagram socket. The address of this member is determined at startup time, and is the host name plus a timestamp (LogicalAddress). It does not change during the lifetime of the process. The LogicalAddress contains a list of all unicast socket addresses to which we can send back unicast messages. When we send a message, the Listener adds the sender's return address. When we receive a message, we add that address to our routing cache, which contains logical addresses and physical addresses. When we need to send a unicast address, we first check whether the logical address has a physical address associated with it in the cache. If so, we send a message to that address. If not, we send the unicast message to all physical addresses contained in the LogicalAddress.
UDP_NIO guarantees that - in scenarios with multiple subnets and multi-homed machines - members do see each other. There is some overhead in multicasting the same message on multiple interfaces, and potentially sending a unicast on multiple interfaces as well, but the advantage is that we don't need stuff like bind_addr any longer. Plus, the unicast routing caches should ensure that unicasts are only sent via 1 interface in almost all cases.

Version: $Id: UDP_NIO.java,v 1.4 2005/08/11 12:43:47 belaban Exp $

Author: Bela Ban Oct 2003

Nested Class Summary
static classUDP_NIO.Connector
Manages a multicast and unicast socket on a given interface (NIC).
static classUDP_NIO.ConnectorTable
Manages a bunch of Connectors
static classUDP_NIO.MulticastReceiver
static classUDP_NIO.MyReceiver
static classUDP_NIO.Unmarshaller
Constructor Summary
UDP_NIO()
Creates the UDP_NIO protocol, and initializes the state variables, does however not start any sockets or threads.
Method Summary
ListdetermineAllBindInterfaces()
StringdetermineDefaultBindInterface()
Return the first non-loopback interface
voiddown(Event evt)
Caller by the layer above this layer.
StringgetName()
voidinit()
static voidmain(String[] args)
voidreceive(DatagramPacket packet)
booleansetProperties(Properties props)
Setup the Protocol instance acording to the configuration string.
voidstart()
Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads
voidstartUpHandler()
This prevents the up-handler thread to be created, which essentially is superfluous: messages are received from the network rather than from a layer below.
voidstop()
StringtoString()
debug only
voidup(Event evt)
handle the UP event.

Constructor Detail

UDP_NIO

public UDP_NIO()
Creates the UDP_NIO protocol, and initializes the state variables, does however not start any sockets or threads.

Method Detail

determineAllBindInterfaces

public List determineAllBindInterfaces()

determineDefaultBindInterface

public String determineDefaultBindInterface()
Return the first non-loopback interface

down

public void down(Event evt)
Caller by the layer above this layer. Usually we just put this Message into the send queue and let one or more worker threads handle it. A worker thread then removes the Message from the send queue, performs a conversion and adds the modified Message to the send queue of the layer below it, by calling Down).

getName

public String getName()

init

public void init()

main

public static void main(String[] args)

receive

public void receive(DatagramPacket packet)

setProperties

public boolean setProperties(Properties props)
Setup the Protocol instance acording to the configuration string. The following properties are being read by the UDP protocol:

Returns: true if no other properties are left. false if the properties still have data in them, ie , properties are left over and not handled by the protocol stack

start

public void start()
Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads

startUpHandler

public void startUpHandler()
This prevents the up-handler thread to be created, which essentially is superfluous: messages are received from the network rather than from a layer below. DON'T REMOVE !

stop

public void stop()

toString

public String toString()
debug only

up

public void up(Event evt)
handle the UP event.

Parameters: evt - the event being send from the stack

Copyright ? 1998-2005 Bela Ban. All Rights Reserved.