org.javagroups.protocols
Class UDP

java.lang.Object
  extended byorg.javagroups.stack.Protocol
      extended byorg.javagroups.protocols.UDP
All Implemented Interfaces:
java.lang.Runnable

public class UDP
extends Protocol
implements java.lang.Runnable

IP multicast transport based on UDP. Messages to the group (msg.dest == null) will be multicast (to all group members), whereas point-to-point messages (msg.dest != null) will be unicast to a single member. Uses a multicast and a unicast socket.

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
param use_packet_handler - If set, the mcast and ucast receiver threads just put the datagram's payload (a byte buffer) into a queue, from where a separate thread will dequeue and handle them (unmarshal and pass up). This frees the receiver threads from having to do message unmarshalling; this time can now be spent receiving packets. If you have lots of retransmissions because of network input buffer overflow, consider setting this property to true (default is false).

Author:
Bela Ban

Nested Class Summary
 class UDP.UcastReceiver
           
 
Field Summary
 
Fields inherited from class org.javagroups.stack.Protocol
down_handler, down_prot, down_queue, down_thread, down_thread_prio, observer, props, stack, up_handler, up_prot, up_queue, up_thread, up_thread_prio
 
Constructor Summary
UDP()
          public constructor.
 
Method Summary
 void down(Event evt)
          Caller by the layer above this layer.
 java.lang.String getName()
           
 void init()
          Called after instance has been created (null constructor) and before protocol is started.
 void run()
           
 boolean setProperties(java.util.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().
 java.lang.String toString()
          debug only
 void up(Event evt)
          handle the UP event.
 
Methods inherited from class org.javagroups.stack.Protocol
destroy, getDownProtocol, getDownQueue, getProperties, getUpProtocol, getUpQueue, passDown, passUp, providedDownServices, providedUpServices, receiveDownEvent, receiveUpEvent, requiredDownServices, requiredUpServices, setDownProtocol, setObserver, setPropertiesInternal, setProtocolStack, setUpProtocol, startDownHandler, stopInternal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UDP

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

Method Detail

toString

public java.lang.String toString()
debug only


run

public void run()
Specified by:
run in interface java.lang.Runnable

getName

public java.lang.String getName()
Specified by:
getName in class Protocol

init

public void init()
          throws java.lang.Exception
Description copied from class: Protocol
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 class Protocol
Throws:
java.lang.Exception - Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the channel constructor will throw an exception

start

public void start()
           throws java.lang.Exception
Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads

Overrides:
start in class Protocol
Throws:
java.lang.Exception - Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, so Channel.connect(String) will throw an exception

stop

public void stop()
Description copied from class: Protocol
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 class Protocol

setProperties

public boolean setProperties(java.util.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 class 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

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 class Protocol

up

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

Overrides:
up in class Protocol
Parameters:
evt - - the event being send from the stack

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 class Protocol


Copyright © 2001,2002 www.javagroups.com . All Rights Reserved.