org.jgroups.protocols

Class UDP1_4

Implemented Interfaces:
org.jgroups.protocols.Receiver

public class UDP1_4
extends Protocol
implements org.jgroups.protocols.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 (LogicalAddress1_4). It does not change during the lifetime of the process. The LogicalAddress1_4 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 LogicalAddress1_4.
UDP1_4 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: UDP1_4.java,v 1.18 2004/07/05 14:17:16 belaban Exp $ todo: sending of dummy packets
Author:
Bela Ban Oct 2003

Nested Class Summary

static class
UDP1_4.Connector
Manages a multicast and unicast socket on a given interface (NIC).
static class
UDP1_4.ConnectorTable
Manages a bunch of Connectors
static class
UDP1_4.Mailman
static class
UDP1_4.MulticastReceiver
static class
UDP1_4.MyReceiver
static class
UDP1_4.Unmarshaller

Field Summary

protected static Log
log

Fields inherited from class org.jgroups.stack.Protocol

down_handler, down_prot, down_queue, down_thread, down_thread_prio, log, observer, props, stack, up_handler, up_prot, up_queue, up_thread, up_thread_prio

Constructor Summary

UDP1_4()
Public constructor.

Method Summary

List
determineAllBindInterfaces()
String
determineDefaultBindInterface()
Return the first non-loopback interface
void
down(Event evt)
Caller by the layer above this layer.
String
getName()
void
init()
Called after instance has been created (null constructor) and before protocol is started.
static void
main(String[] args)
void
receive(DatagramPacket packet)
Called when data has been received on a socket.
boolean
setProperties(Properties props)
Setup the Protocol instance acording to the configuration string The following properties are being read by the UDP protocol param mcast_addr - the multicast address to use default is 224.0.0.200 param mcast_port - (int) the port that the multicast is sent on default is 7500 param ip_mcast - (boolean) flag whether to use IP multicast - default is true param ip_ttl - Set the default time-to-live for multicast packets sent out on this socket.
void
start()
Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads
void
startUpHandler()
DON'T REMOVE ! 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.
void
stop()
This method is called on a Channel.disconnect().
String
toString()
debug only
void
up(Event evt)
handle the UP event.

Methods inherited from class org.jgroups.stack.Protocol

destroy, down, getDownProtocol, getDownQueue, getName, getProperties, getUpProtocol, getUpQueue, handleSpecialDownEvent, init, passDown, passUp, providedDownServices, providedUpServices, receiveDownEvent, receiveUpEvent, requiredDownServices, requiredUpServices, setDownProtocol, setObserver, setProperties, setPropertiesInternal, setProtocolStack, setUpProtocol, start, startDownHandler, startUpHandler, stop, stopInternal, up

Field Details

log

protected static Log log

Constructor Details

UDP1_4

public UDP1_4()
Public constructor. creates the UDP protocol, and initializes the state variables, does however not start any sockets or threads

Method Details

determineAllBindInterfaces

public List determineAllBindInterfaces()
            throws SocketException

determineDefaultBindInterface

public String determineDefaultBindInterface()
            throws SocketException
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).
Overrides:
down in interface Protocol

getName

public String getName()
Overrides:
getName in interface Protocol

init

public void init()
            throws Exception
Called after instance has been created (null constructor) and before protocol is started. Properties are already set. Other protocols are not yet connected and events cannot yet be sent.
Overrides:
init in interface Protocol

main

public static void main(String[] args)

receive

public void receive(DatagramPacket packet)
Called when data has been received on a socket. When the callback returns, the buffer will be reused: therefore, if buf must be processed on a separate thread, it needs to be copied. This method might be called concurrently by multiple threads, so it has to be reentrant
Specified by:
receive in interface org.jgroups.protocols.Receiver
Parameters:
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 param mcast_addr - the multicast address to use default is 224.0.0.200 param mcast_port - (int) the port that the multicast is sent on default is 7500 param ip_mcast - (boolean) flag whether to use IP multicast - default is true param ip_ttl - Set the default time-to-live for multicast packets sent out on this socket. default is 32
Overrides:
setProperties in interface 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()
            throws Exception
Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads
Overrides:
start in interface Protocol

startUpHandler

public void startUpHandler()
DON'T REMOVE ! 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.
Overrides:
startUpHandler in interface Protocol

stop

public void stop()
This method is called on a Channel.disconnect(). Stops work (e.g. by closing multicast socket). Will be called from top to bottom. This means that at the time of the method invocation the neighbor protocol below is still working. This method will replace the STOP, STOP_OK, CLEANUP and CLEANUP_OK events. The ProtocolStack guarantees that when this method is called all messages in the down queue will have been flushed
Overrides:
stop in interface Protocol

toString

public String toString()
debug only

up

public void up(Event evt)
handle the UP event.
Overrides:
up in interface Protocol
Parameters:
evt - - the event being send from the stack

Copyright B) 2001,2002 www.jgroups.com . All Rights Reserved.