org.jgroups.protocols
Class JOLSR_UDP

java.lang.Object
  extended by org.jgroups.stack.Protocol
      extended by org.jgroups.protocols.TP
          extended by org.jgroups.protocols.JOLSR_UDP
All Implemented Interfaces:
java.lang.Runnable

public class JOLSR_UDP
extends org.jgroups.protocols.TP
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 read by the UDP protocol:

Version:
$Id: JOLSR_UDP.java,v 1.144.2.1 2007/09/17 07:41:03 belaban Exp $
Author:
Bela Ban

Nested Class Summary
 class JOLSR_UDP.UcastReceiver
           
 
Nested classes/interfaces inherited from class org.jgroups.protocols.TP
org.jgroups.protocols.TP.IncomingMessageHandler, org.jgroups.protocols.TP.IncomingPacket, org.jgroups.protocols.TP.IncomingPacketHandler, org.jgroups.protocols.TP.ThreadNamingPattern
 
Field Summary
(package private)  boolean ip_mcast
          Whether to enable IP multicasting.
(package private)  int ip_ttl
          The time-to-live (TTL) for multicast datagram packets
(package private)  org.jgroups.stack.IpAddress mcast_addr
          The multicast address (mcast address and port) this member uses
(package private)  java.lang.String mcast_addr_name
          The multicast address used for sending and receiving packets
(package private)  int mcast_port
          The multicast port used for sending and receiving packets
(package private)  java.lang.Thread mcast_receiver
          The multicast receiver thread
(package private)  int mcast_recv_buf_size
          Receive buffer size of the multicast datagram socket
(package private)  int mcast_send_buf_size
          Send buffer size of the multicast datagram socket
(package private)  java.net.MulticastSocket[] mcast_send_sockets
          If we have multiple mcast send sockets, e.g. send_interfaces or send_on_all_interfaces enabled
(package private)  java.net.MulticastSocket mcast_sock
          IP multicast socket for sending and receiving multicast packets
(package private)  int num_last_ports
          Maintain a list of local ports opened by DatagramSocket.
(package private)  java.net.DatagramSocket sock
          Socket used for sending unicast packets and receiving unicast packets The address of this socket will be our local address (local_addr)
(package private)  int tos
          Traffic class for sending unicast and multicast datagrams.
(package private)  JOLSR_UDP.UcastReceiver ucast_receiver
          The unicast receiver thread
(package private)  int ucast_recv_buf_size
          Receive buffer size of the unicast datagram socket
(package private)  int ucast_send_buf_size
          Send buffer size of the unicast datagram socket
 
Fields inherited from class org.jgroups.protocols.TP
additional_data, bind_addr, bind_port, channel_name, diagnostics_addr, diagnostics_port, dis, discard_incompatible_packets, enable_bundling, enable_diagnostics, f, header, in_stream, incoming_msg_handler, incoming_msg_queue, incoming_packet_handler, incoming_packet_queue, LIST, local_addr, loopback, max_bundle_size, max_bundle_timeout, members, MULTICAST, name, num_bytes_received, num_bytes_sent, num_incoming_msgs_received, num_msgs_received, num_msgs_sent, num_oob_msgs_received, OOB, oob_thread_pool, oob_thread_pool_enabled, oob_thread_pool_keep_alive_time, oob_thread_pool_max_threads, oob_thread_pool_min_threads, oob_thread_pool_queue, oob_thread_pool_queue_enabled, oob_thread_pool_queue_max_size, oob_thread_pool_rejection_policy, pool_thread_group, port_range, receive_interfaces, receive_on_all_interfaces, send_interfaces, send_on_all_interfaces, thread_naming_pattern, thread_pool, thread_pool_enabled, thread_pool_keep_alive_time, thread_pool_max_threads, thread_pool_min_threads, thread_pool_queue, thread_pool_queue_enabled, thread_pool_queue_max_size, thread_pool_rejection_policy, timer, use_concurrent_stack, use_incoming_packet_handler, use_local_host, view
 
Fields inherited from class org.jgroups.stack.Protocol
down_prot, log, props, stack, stats, up_prot
 
Constructor Summary
JOLSR_UDP()
          Creates the JOLSR_UDP protocol, and initializes the state variables, does however not start any sockets or threads.
 
Method Summary
(package private)  void closeMulticastSocket()
           
(package private)  void closeSockets()
          Closed UDP unicast and multicast sockets
protected  java.net.DatagramSocket createDatagramSocketWithBindPort()
          Creates a DatagramSocket when bind_port > 0.
protected  java.net.DatagramSocket createEphemeralDatagramSocket()
          Creates a DatagramSocket with a random port.
 java.lang.String getInfo()
           
 java.lang.String getName()
           
protected  void handleConfigEvent(java.util.HashMap map)
           
 void postUnmarshalling(org.jgroups.Message msg, org.jgroups.Address dest, org.jgroups.Address src, boolean multicast)
           
 void postUnmarshallingList(org.jgroups.Message msg, org.jgroups.Address dest, boolean multicast)
           
 void run()
           
 void sendToAllMembers(byte[] data, int offset, int length)
           
 void sendToSingleMember(org.jgroups.Address dest, byte[] data, int offset, int length)
           
(package private)  void setBufferSizes()
           
 boolean setProperties(java.util.Properties props)
          Setup the Protocol instance acording to the configuration string.
protected  void setThreadNames()
           
 void start()
          Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads
(package private)  void startThreads()
          Starts the unicast and multicast receiver threads
 void stop()
           
(package private)  void stopThreads()
          Stops unicast and multicast receiver threads
protected  void unsetThreadNames()
           
 
Methods inherited from class org.jgroups.protocols.TP
, createThreadPool, down, dumpStats, getBindAddress, getBindToAllInterfaces, getChannelName, getIncomingKeepAliveTime, getIncomingMaxPoolSize, getIncomingMaxQueueSize, getIncomingMessages, getIncomingMinPoolSize, getIncomingPoolSize, getIncomingQueueSize, getLocalAddress, getMaxBundleSize, getMaxBundleTimeout, getNumBytesReceived, getNumBytesSent, getNumMessagesReceived, getNumMessagesSent, getOOBKeepAliveTime, getOOBMaxPoolSize, getOOBMaxQueueSize, getOOBMessages, getOOBMinPoolSize, getOOBPoolSize, getOOBQueueSize, getReceiveInterfaces, getSendInterfaces, handleDownEvent, init, isDiscardIncompatiblePackets, isEnableBundling, isLoopback, isReceiveOnAllInterfaces, isSendOnAllInterfaces, isUseIncomingPacketHandler, receive, resetStats, setBindAddress, setBindToAllInterfaces, setDiscardIncompatiblePackets, setEnableBundling, setIncomingKeepAliveTime, setIncomingMaxPoolSize, setIncomingMinPoolSize, setLoopback, setMaxBundleSize, setMaxBundleTimeout, setOOBKeepAliveTime, setOOBMaxPoolSize, setOOBMinPoolSize, toString, up
 
Methods inherited from class org.jgroups.stack.Protocol
destroy, downThreadEnabled, enableStats, getDownProtocol, getProperties, getUpProtocol, printStats, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, setDownProtocol, setPropertiesInternal, setProtocolStack, setUpProtocol, statsEnabled, upThreadEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sock

java.net.DatagramSocket sock
Socket used for
  1. sending unicast packets and
  2. receiving unicast packets
The address of this socket will be our local address (local_addr)


num_last_ports

int num_last_ports
Maintain a list of local ports opened by DatagramSocket. If this is 0, this option is turned off. If bind_port is > 0, then this option will be ignored


mcast_sock

java.net.MulticastSocket mcast_sock
IP multicast socket for sending and receiving multicast packets


mcast_send_sockets

java.net.MulticastSocket[] mcast_send_sockets
If we have multiple mcast send sockets, e.g. send_interfaces or send_on_all_interfaces enabled


tos

int tos
Traffic class for sending unicast and multicast datagrams. Valid values are (check DatagramSocket.setTrafficClass(int) ); for details):


mcast_addr

org.jgroups.stack.IpAddress mcast_addr
The multicast address (mcast address and port) this member uses


mcast_addr_name

java.lang.String mcast_addr_name
The multicast address used for sending and receiving packets


mcast_port

int mcast_port
The multicast port used for sending and receiving packets


mcast_receiver

java.lang.Thread mcast_receiver
The multicast receiver thread


ucast_receiver

JOLSR_UDP.UcastReceiver ucast_receiver
The unicast receiver thread


ip_mcast

boolean ip_mcast
Whether to enable IP multicasting. If false, multiple unicast datagram packets are sent rather than one multicast packet


ip_ttl

int ip_ttl
The time-to-live (TTL) for multicast datagram packets


mcast_send_buf_size

int mcast_send_buf_size
Send buffer size of the multicast datagram socket


mcast_recv_buf_size

int mcast_recv_buf_size
Receive buffer size of the multicast datagram socket


ucast_send_buf_size

int ucast_send_buf_size
Send buffer size of the unicast datagram socket


ucast_recv_buf_size

int ucast_recv_buf_size
Receive buffer size of the unicast datagram socket

Constructor Detail

JOLSR_UDP

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

Method Detail

getInfo

public java.lang.String getInfo()
Specified by:
getInfo in class org.jgroups.protocols.TP

getName

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

postUnmarshalling

public void postUnmarshalling(org.jgroups.Message msg,
                              org.jgroups.Address dest,
                              org.jgroups.Address src,
                              boolean multicast)
Specified by:
postUnmarshalling in class org.jgroups.protocols.TP

postUnmarshallingList

public void postUnmarshallingList(org.jgroups.Message msg,
                                  org.jgroups.Address dest,
                                  boolean multicast)
Specified by:
postUnmarshallingList in class org.jgroups.protocols.TP

run

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

sendToAllMembers

public void sendToAllMembers(byte[] data,
                             int offset,
                             int length)
                      throws java.lang.Exception
Specified by:
sendToAllMembers in class org.jgroups.protocols.TP
Throws:
java.lang.Exception

sendToSingleMember

public void sendToSingleMember(org.jgroups.Address dest,
                               byte[] data,
                               int offset,
                               int length)
                        throws java.lang.Exception
Specified by:
sendToSingleMember in class org.jgroups.protocols.TP
Throws:
java.lang.Exception

setProperties

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

Overrides:
setProperties in class org.jgroups.protocols.TP
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 java.lang.Exception
Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads

Overrides:
start in class org.jgroups.protocols.TP
Throws:
java.lang.Exception

stop

public void stop()
Overrides:
stop in class org.jgroups.protocols.TP

createDatagramSocketWithBindPort

protected java.net.DatagramSocket createDatagramSocketWithBindPort()
                                                            throws java.lang.Exception
Creates a DatagramSocket when bind_port > 0. Attempts to allocate the socket with port == bind_port, and increments until it finds a valid port, or until port_range has been exceeded

Returns:
DatagramSocket The newly created socket
Throws:
java.lang.Exception

createEphemeralDatagramSocket

protected java.net.DatagramSocket createEphemeralDatagramSocket()
                                                         throws java.net.SocketException
Creates a DatagramSocket with a random port. Because in certain operating systems, ports are reused, we keep a list of the n last used ports, and avoid port reuse

Throws:
java.net.SocketException

handleConfigEvent

protected void handleConfigEvent(java.util.HashMap map)
Overrides:
handleConfigEvent in class org.jgroups.protocols.TP

setThreadNames

protected void setThreadNames()
Overrides:
setThreadNames in class org.jgroups.protocols.TP

unsetThreadNames

protected void unsetThreadNames()
Overrides:
unsetThreadNames in class org.jgroups.protocols.TP

closeMulticastSocket

void closeMulticastSocket()

closeSockets

void closeSockets()
Closed UDP unicast and multicast sockets


setBufferSizes

void setBufferSizes()

startThreads

void startThreads()
            throws java.lang.Exception
Starts the unicast and multicast receiver threads

Throws:
java.lang.Exception

stopThreads

void stopThreads()
Stops unicast and multicast receiver threads