org.jgroups.protocols
Class UDP

java.lang.Object
  extended by org.jgroups.stack.Protocol
      extended by org.jgroups.protocols.TP
          extended by org.jgroups.protocols.UDP

public class UDP
extends TP

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:

Author:
Bela Ban

Nested Class Summary
 class UDP.PacketReceiver
           
 
Nested classes/interfaces inherited from class org.jgroups.protocols.TP
TP.Bundler, TP.DefaultBundler, TP.DefaultBundler2, TP.ProtocolAdapter, TP.TransferQueueBundler, TP.TransferQueueBundler2
 
Field Summary
protected  boolean disable_loopback
           
protected  boolean ip_mcast
           
protected  int ip_ttl
           
protected  IpAddress mcast_addr
          The multicast address (mcast address and port) this member uses
protected  java.net.InetAddress mcast_group_addr
           
protected  int mcast_port
           
protected  UDP.PacketReceiver mcast_receiver
          Runnable to receive multicast packets
protected  int mcast_recv_buf_size
           
protected  int mcast_send_buf_size
           
protected  java.net.MulticastSocket mcast_sock
          IP multicast socket for receiving multicast packets
protected  java.net.DatagramSocket sock
          Socket used for sending unicast and multicast packets and receiving unicast packets The address of this socket will be our local address (local_addr)
protected  int tos
          Traffic class for sending unicast and multicast datagrams.
protected  UDP.PacketReceiver ucast_receiver
          Runnable to receive unicast packets
protected  int ucast_recv_buf_size
           
protected  int ucast_send_buf_size
           
 
Fields inherited from class org.jgroups.protocols.TP
bind_addr, bind_interface_str, bind_port, bundler, bundler_capacity, bundler_type, can_bind_to_mcast_addr, channel_name, connect_count, connectLock, default_thread_factory, diag_handler, diagnostics_addr, diagnostics_bind_interfaces, diagnostics_passcode, diagnostics_port, diagnostics_ttl, discard_incompatible_packets, enable_bundling, enable_diagnostics, enable_unicast_bundling, external_addr, external_port, f, global_thread_factory, header, last_discovery_request, LIST, local_addr, log_discard_msgs, log_discard_msgs_version, logical_addr_cache, logical_addr_cache_expiration, logical_addr_cache_max_size, loopback, max_bundle_size, max_bundle_timeout, members, MULTICAST, num_bytes_received, num_bytes_sent, num_incoming_msgs_received, num_msgs_received, num_msgs_sent, num_oob_msgs_received, OOB, oob_thread_factory, 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, physical_addr_max_fetch_attempts, port_range, preregistered_probe_handlers, print_function, receive_interfaces, receive_on_all_interfaces, singleton_name, socket_factory, suppress_log_different_cluster, suppress_log_different_version, suppress_time_different_cluster_warnings, suppress_time_different_version_warnings, 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, tick_time, timer, timer_keep_alive_time, timer_max_threads, timer_min_threads, timer_queue_max_size, timer_rejection_policy, timer_thread_factory, timer_type, up_prots, wheel_size, who_has_cache, who_has_cache_timeout
 
Fields inherited from class org.jgroups.stack.Protocol
down_prot, ergonomics, id, log, name, stack, stats, up_prot
 
Constructor Summary
UDP()
           
 
Method Summary
protected  void _send(java.net.InetAddress dest, int port, boolean mcast, byte[] data, int offset, int length)
           
protected  void bindToInterfaces(java.util.List<java.net.NetworkInterface> interfaces, java.net.MulticastSocket s, java.net.InetAddress mcastAddr)
           
protected  void closeUnicastSocket()
           
protected  java.net.DatagramSocket createDatagramSocketWithBindPort()
          Creates a DatagramSocket when bind_port > 0.
protected  java.net.DatagramSocket createEphemeralDatagramSocket()
          Creates a DatagramSocket with a random port.
protected  IpAddress createLocalAddress()
           
protected  void createSockets()
          Create UDP sender and receiver sockets.
 void destroy()
          This method is called on a Channel.close().
protected  void destroySockets()
           
protected  java.lang.String dumpSocketInfo()
           
 java.lang.String getInfo()
           
 java.net.InetAddress getMulticastAddress()
           
 int getMulticastPort()
           
 int getMulticastTTL()
          Getter for current multicast TTL
protected  PhysicalAddress getPhysicalAddress()
           
protected  void handleConfigEvent(java.util.Map<java.lang.String,java.lang.Object> map)
           
protected  void handleConnect()
           
protected  void handleDisconnect()
           
 void sendMulticast(byte[] data, int offset, int length)
          Send to all members in the group.
 void sendUnicast(PhysicalAddress dest, byte[] data, int offset, int length)
          Send a unicast to 1 member.
protected  void setBufferSize(java.net.DatagramSocket sock, int send_buf_size, int recv_buf_size)
           
 void setMaxBundleSize(int size)
           
 void setMcastPort(int mcast_port)
           
 void setMulticastAddress(java.net.InetAddress addr)
           
 void setMulticastPort(int mcast_port)
           
 void setMulticastTTL(int ttl)
          Set the ttl for multicast socket
 void start()
          Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads
 void stop()
          This method is called on a Channel.disconnect().
 boolean supportsMulticasting()
          Usually, src addresses are nulled, and the receiver simply sets them to the address of the sender.
 
Methods inherited from class org.jgroups.protocols.TP
addPhysicalAddressToCache, clearDifferentClusterCache, clearDifferentVersionCache, clearLogicalAddressCache, createThreadPool, dispatchToThreadPool, doSend, down, dumpTimerTasks, evictLogicalAddressCache, evictLogicalAddressCache, fetchLocalAddresses, getAllPhysicalAddressesFromCache, getBindAddress, getBindPort, getBundlerBufferSize, getDefaultThreadPool, getDefaultThreadPoolThreadFactory, getDifferentClusterMessages, getDifferentVersionMessages, getLogDiscardMessages, getLogDiscardMessagesVersion, getMaxBundleSize, getMaxBundleTimeout, getNumBytesReceived, getNumBytesSent, getNumMessagesReceived, getNumMessagesSent, getNumThreads, getNumTimerTasks, getOOBMaxQueueSize, getOOBMessages, getOOBPoolSize, getOOBQueueSize, getOOBThreadPool, getOOBThreadPoolKeepAliveTime, getOOBThreadPoolMaxThreads, getOOBThreadPoolMinThreads, getOOBThreadPoolThreadFactory, getPhysicalAddressFromCache, getPortRange, getReceiveInterfaces, getRegularMaxQueueSize, getRegularMessages, getRegularPoolSize, getRegularQueueSize, getSingletonName, getSocketFactory, getThreadFactory, getThreadNamingPattern, getThreadPoolKeepAliveTime, getThreadPoolMaxThreads, getThreadPoolMinThreads, getTimer, getTimerClass, getTimerKeepAliveTime, getTimerMaxThreads, getTimerMinThreads, getTimerQueueSize, getTimerThreadFactory, getTimerThreads, getUpProtocols, handleDownEvent, init, isDefaulThreadPoolEnabled, isDiscardIncompatiblePackets, isEnableBundling, isEnableUnicastBundling, isLoopback, isMulticastCapable, isOOBThreadPoolEnabled, isReceiveOnAllInterfaces, isSingleton, passMessageUp, passToAllUpProtocols, printLogicalAddressCache, printWhoHasCache, readMessage, readMessageList, receive, registerLocalAddress, registerProbeHandler, removeLogicalAddressFromCache, resetStats, send, sendToAllPhysicalAddresses, sendToSingleMember, setBindAddress, setBindPort, setBindToAllInterfaces, setDefaultThreadPool, setDefaultThreadPoolThreadFactory, setDiagnosticsHandler, setDiscardIncompatiblePackets, setEnableBundling, setEnableUnicastBundling, setInAllThreadFactories, setLogDiscardMessages, setLogDiscardMessagesVersion, setLoopback, setMaxBundleTimeout, setOOBRejectionPolicy, setOOBThreadPool, setOOBThreadPoolKeepAliveTime, setOOBThreadPoolMaxThreads, setOOBThreadPoolMinThreads, setOOBThreadPoolThreadFactory, setPortRange, setRegularRejectionPolicy, setSocketFactory, setSourceAddress, setThreadFactory, setThreadNames, setThreadPoolKeepAliveTime, setThreadPoolMaxThreads, setThreadPoolMinThreads, setThreadPoolQueueEnabled, setTimer, setTimerKeepAliveTime, setTimerMaxThreads, setTimerMinThreads, setTimerThreadFactory, shutdownThreadPool, toString, unregisterProbeHandler, unsetThreadNames, up, writeMessage, writeMessageList
 
Methods inherited from class org.jgroups.stack.Protocol
dumpStats, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getName, getProtocolStack, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, printStats, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, resetStatistics, setDownProtocol, setErgonomics, setId, setLevel, setProtocolStack, setUpProtocol, setValue, setValues, statsEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

tos

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


mcast_group_addr

protected java.net.InetAddress mcast_group_addr

mcast_port

protected int mcast_port

ip_mcast

protected boolean ip_mcast

ip_ttl

protected int ip_ttl

mcast_send_buf_size

protected int mcast_send_buf_size

mcast_recv_buf_size

protected int mcast_recv_buf_size

ucast_send_buf_size

protected int ucast_send_buf_size

ucast_recv_buf_size

protected int ucast_recv_buf_size

disable_loopback

protected boolean disable_loopback

mcast_addr

protected IpAddress mcast_addr
The multicast address (mcast address and port) this member uses


sock

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


mcast_sock

protected java.net.MulticastSocket mcast_sock
IP multicast socket for receiving multicast packets


mcast_receiver

protected UDP.PacketReceiver mcast_receiver
Runnable to receive multicast packets


ucast_receiver

protected UDP.PacketReceiver ucast_receiver
Runnable to receive unicast packets

Constructor Detail

UDP

public UDP()
Method Detail

supportsMulticasting

public boolean supportsMulticasting()
Usually, src addresses are nulled, and the receiver simply sets them to the address of the sender. However, for multiple addresses on a Windows loopback device, this doesn't work (see http://jira.jboss.com/jira/browse/JGRP-79 and the JGroups wiki for details). This must be the same value for all members of the same group. Default is true, for performance reasons

Specified by:
supportsMulticasting in class TP

setMulticastAddress

public void setMulticastAddress(java.net.InetAddress addr)

getMulticastAddress

public java.net.InetAddress getMulticastAddress()

getMulticastPort

public int getMulticastPort()

setMulticastPort

public void setMulticastPort(int mcast_port)

setMcastPort

public void setMcastPort(int mcast_port)

setMulticastTTL

public void setMulticastTTL(int ttl)
                     throws java.io.IOException
Set the ttl for multicast socket

Parameters:
ttl - the time to live for the socket.
Throws:
java.io.IOException

getMulticastTTL

public int getMulticastTTL()
Getter for current multicast TTL

Returns:

setMaxBundleSize

public void setMaxBundleSize(int size)
Overrides:
setMaxBundleSize in class TP

getInfo

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

sendMulticast

public void sendMulticast(byte[] data,
                          int offset,
                          int length)
                   throws java.lang.Exception
Description copied from class: TP
Send to all members in the group. UDP would use an IP multicast message, whereas TCP would send N messages, one for each member

Specified by:
sendMulticast in class TP
Parameters:
data - The data to be sent. This is not a copy, so don't modify it
Throws:
java.lang.Exception

sendUnicast

public void sendUnicast(PhysicalAddress dest,
                        byte[] data,
                        int offset,
                        int length)
                 throws java.lang.Exception
Description copied from class: TP
Send a unicast to 1 member. Note that the destination address is a *physical*, not a logical address

Specified by:
sendUnicast in class TP
Parameters:
dest - Must be a non-null unicast address
data - The data to be sent. This is not a copy, so don't modify it
Throws:
java.lang.Exception

_send

protected void _send(java.net.InetAddress dest,
                     int port,
                     boolean mcast,
                     byte[] data,
                     int offset,
                     int length)
              throws java.lang.Exception
Throws:
java.lang.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 TP
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 TP

destroy

public void destroy()
Description copied from class: Protocol
This method is called on a Channel.close(). Does some cleanup; after the call the VM will terminate

Overrides:
destroy in class TP

handleConnect

protected void handleConnect()
                      throws java.lang.Exception
Overrides:
handleConnect in class TP
Throws:
java.lang.Exception

handleDisconnect

protected void handleDisconnect()
Overrides:
handleDisconnect in class TP

createSockets

protected void createSockets()
                      throws java.lang.Exception
Create UDP sender and receiver sockets. Currently there are 2 sockets (sending and receiving). This is due to Linux's non-BSD compatibility in the JDK port (see DESIGN).

Throws:
java.lang.Exception

destroySockets

protected void destroySockets()

createLocalAddress

protected IpAddress createLocalAddress()

getPhysicalAddress

protected PhysicalAddress getPhysicalAddress()
Specified by:
getPhysicalAddress in class TP

bindToInterfaces

protected void bindToInterfaces(java.util.List<java.net.NetworkInterface> interfaces,
                                java.net.MulticastSocket s,
                                java.net.InetAddress mcastAddr)
Parameters:
interfaces - List. Guaranteed to have no duplicates
s -
mcastAddr -
Throws:
java.io.IOException

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

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

dumpSocketInfo

protected java.lang.String dumpSocketInfo()
                                   throws java.lang.Exception
Throws:
java.lang.Exception

setBufferSize

protected void setBufferSize(java.net.DatagramSocket sock,
                             int send_buf_size,
                             int recv_buf_size)

closeUnicastSocket

protected void closeUnicastSocket()

handleConfigEvent

protected void handleConfigEvent(java.util.Map<java.lang.String,java.lang.Object> map)


Copyright © 1998-2012 Bela Ban / Red Hat. All Rights Reserved.