Package org.jgroups.protocols
Class UDP
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.TP
-
- org.jgroups.protocols.UDP
-
- All Implemented Interfaces:
AdditionalJmxObjects,DiagnosticsHandler.ProbeHandler
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:
- param mcast_addr - the multicast address to use; default is 228.8.8.8.
- param mcast_port - (int) the port that the multicast is sent on; default is 7600
- param ip_mcast - (boolean) flag whether to use IP multicast; default is true.
- param ip_ttl - the default time-to-live for multicast packets sent out on this socket; default is 8.
- param use_packet_handler - boolean, defaults to false. 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.
- Author:
- Bela Ban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classUDP.PacketReceiver
-
Field Summary
Fields Modifier and Type Field Description protected booleandisable_loopbackprotected booleanip_mcastprotected intip_ttlprotected static booleanis_androidprotected static booleanis_macprotected IpAddressmcast_addrThe multicast address (mcast address and port) this member usesprotected java.net.InetAddressmcast_group_addrprotected static java.lang.StringMCAST_NAMEprotected intmcast_portprotected UDP.PacketReceiver[]mcast_receiversRunnable to receive multicast packetsprotected intmcast_recv_buf_sizeprotected intmcast_send_buf_sizeprotected java.net.MulticastSocketmcast_sockIP multicast socket for receiving multicast packetsprotected intmulticast_receiver_threadsprotected java.net.MulticastSocketsockSocket used for sending unicast and multicast packets and receiving unicast packets The address of this socket will be our local address (local_addr)protected SuppressLog<java.net.InetAddress>suppress_log_out_of_buffer_spaceprotected longsuppress_time_out_of_buffer_spaceprotected inttosTraffic class for sending unicast and multicast datagrams.protected static java.lang.StringUCAST_NAMEprotected UDP.PacketReceiver[]ucast_receiversRunnable to receive unicast packetsprotected intucast_recv_buf_sizeprotected intucast_send_buf_sizeprotected intunicast_receiver_threads-
Fields inherited from class org.jgroups.protocols.TP
avg_batch_size, bind_addr, bind_port, bundler, bundler_capacity, bundler_num_spins, bundler_type, bundler_wait_strategy, cluster_name, connectLock, diag_enable_tcp, diag_enable_udp, diag_handler, diagnostics_addr, diagnostics_bind_addr, diagnostics_bind_interfaces, diagnostics_passcode, diagnostics_port, diagnostics_port_range, diagnostics_ttl, drop_when_full, enable_diagnostics, external_addr, external_port, header, internal_pool, internal_thread_factory, is_trace, last_discovery_request, LIST, local_addr, local_physical_addr, log_discard_msgs, log_discard_msgs_version, logical_addr_cache, logical_addr_cache_expiration, logical_addr_cache_max_size, logical_addr_cache_reaper, logical_addr_cache_reaper_interval, loopback_copy, loopback_separate_thread, max_bundle_size, members, message_processing_policy, MIN_WAIT_BETWEEN_DISCOVERIES, MSG_OVERHEAD, msg_processing_max_buffer_size, msg_processing_policy, msg_stats, MULTICAST, port_range, preregistered_probe_handlers, print_function, receive_interfaces, receive_on_all_interfaces, socket_factory, spawn_thread_on_full_pool, suppress_log_different_cluster, suppress_log_different_version, suppress_time_different_cluster_warnings, suppress_time_different_version_warnings, thread_dump_path, thread_dumps, thread_dumps_threshold, thread_factory, thread_naming_pattern, thread_pool, thread_pool_enabled, thread_pool_keep_alive_time, thread_pool_max_threads, thread_pool_min_threads, time_service, time_service_interval, timer, timer_handle_non_blocking_tasks, use_common_fork_join_pool, use_fibers, use_fork_join_pool, use_ip_addrs, view, who_has_cache, who_has_cache_timeout
-
Fields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, log, stack, stats, up_prot
-
-
Constructor Summary
Constructors Constructor Description UDP()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_send(java.net.InetAddress dest, int port, byte[] data, int offset, int length)protected voidbindToInterfaces(java.util.List<java.net.NetworkInterface> interfaces, java.net.MulticastSocket s, java.net.InetAddress mcastAddr)<T extends UDP>
TclearDroppedMessagesCache()protected voidcloseUnicastSocket()protected IpAddresscreateLocalAddress()protected java.net.MulticastSocketcreateMulticastSocket(java.lang.String service_name, int port)protected java.net.MulticastSocketcreateMulticastSocketWithBindPort()Creates a DatagramSocket when bind_port > 0.protected UDP.PacketReceiver[]createReceivers(int num, java.net.DatagramSocket sock, java.lang.String name)protected voidcreateSockets()Creates the UDP sender and receiver socketsprotected voiddestroySockets()java.lang.Objectdown(Event evt)An event is to be sent down the stack.protected java.lang.StringdumpSocketInfo()protected static java.lang.reflect.MethodfindMethod(java.lang.Class<?> clazz, java.lang.String method_name, java.lang.Class<?>... parameters)protected static intgetBufferSize(java.net.DatagramSocket s, boolean send)intgetDroppedMessages()java.lang.StringgetInfo()intgetMcastReceiverThreads()java.net.InetAddressgetMulticastAddress()intgetMulticastPort()intgetMulticastTTL()protected PhysicalAddressgetPhysicalAddress()intgetUcastReceiverThreads()protected voidhandleConfigEvent(java.util.Map<java.lang.String,java.lang.Object> map)protected voidhandleConnect()voidinit()Called after instance has been created (null constructor) and before protocol is started.voidsendMulticast(byte[] data, int offset, int length)Send to all members in the group.voidsendUnicast(PhysicalAddress dest, byte[] data, int offset, int length)Send a unicast to 1 member.protected voidsetBufferSize(java.net.DatagramSocket sock, int send_buf_size, int recv_buf_size)protected voidsetCorrectSocketBufferSize(java.net.MulticastSocket s, int buf_size, int new_size, boolean send, boolean mcast)protected <T extends UDP>
TsetInterface(java.net.InetAddress intf, java.net.MulticastSocket s)<T extends TP>
TsetMaxBundleSize(int size)<T extends UDP>
TsetMcastPort(int mcast_port)<T extends UDP>
TsetMcastReceiverThreads(int num)<T extends UDP>
TsetMulticastAddress(java.net.InetAddress a)<T extends UDP>
TsetMulticasting(boolean fl)<T extends UDP>
TsetMulticastPort(int mcast_port)<T extends UDP>
TsetMulticastTTL(int ttl)Set the ttl for multicast socketprotected <T extends UDP>
TsetTimeToLive(int ttl, java.net.MulticastSocket s)<T extends UDP>
TsetUcastReceiverThreads(int num)voidstart()Creates the unicast and multicast sockets and starts the unicast and multicast receiver threadsprotected voidstartMcastReceiverThreads()protected voidstartThreads()protected voidstartUcastReceiverThreads()voidstop()This method is called on aJChannel.disconnect().protected voidstopMcastReceiverThreads()protected voidstopThreads()protected voidstopUcastReceiverThreads()booleansupportsMulticasting()Whether or not hardware multicasting is supported-
Methods inherited from class org.jgroups.protocols.TP
_send, addPhysicalAddressToCache, addPhysicalAddressToCache, avgBatchSize, bundler, bundlerNumSpins, bundlerNumSpins, bundlerStats, bundlerStatsReset, bundlerWaitStrategy, bundlerWaitStrategy, clearDifferentClusterCache, clearDifferentVersionCache, clearLogicalAddressCache, createBundler, createDiagnosticsHandler, createThreadPool, destroy, diagEnableTcp, diagEnableUdp, diagTcpEnabled, disableDiagnostics, doSend, down, dumpTimerTasks, enableBlockingTimerTasks, enableDiagnostics, evictLogicalAddressCache, evictLogicalAddressCache, fetchLocalAddresses, fetchPhysicalAddrs, fetchResponsesFromDiscoveryProtocol, getAllPhysicalAddressesFromCache, getAvgBatchSize, getBindAddress, getBindPort, getBundler, getBundlerBufferSize, getBundlerCapacity, getBundlerClass, getClusterName, getClusterNameAscii, getDiagnosticsHandler, getDifferentClusterMessages, getDifferentVersionMessages, getDropWhenFull, getInternalThreadPool, getInternalThreadPoolSize, getInternalThreadPoolSizeLargest, getInternalThreadPoolThreadFactory, getJmxObjects, getLocalAddress, getLocalPhysicalAddress, getLogDiscardMessages, getLogDiscardMessagesVersion, getMaxBundleSize, getMessageProcessingMaxBufferSize, getMessageStats, getNumberOfThreadDumps, getNumMessagesSent, getNumThreads, getNumTimerTasks, getPhysicalAddressFromCache, getPortRange, getReceiveInterfaces, getSocketFactory, getThreadDumpsThreshold, getThreadFactory, getThreadNamingPattern, getThreadPool, getThreadPoolKeepAliveTime, getThreadPoolMaxThreads, getThreadPoolMinThreads, getThreadPoolSize, getThreadPoolSizeActive, getThreadPoolSizeLargest, getThreadPoolThreadFactory, getTimer, getTimerClass, getTimerThreads, getTimeService, getUseIpAddresses, handleDisconnect, handleMessageBatch, handleProbe, handleSingleMessage, incrBatchesSent, incrNumSingleMsgsSent, isDiagnosticsEnabled, isDiagnosticsRunning, isDiagUdEnabled, isLogicalAddressCacheReaperRunning, isMulticastCapable, isReceiveOnAllInterfaces, localAddress, loggerType, loopback, passBatchUp, passMessageUp, printLogicalAddressCache, printWhoHasCache, processBatch, receive, receive, registerLocalAddress, registerProbeHandler, removeCancelledTimerTasks, removeLogicalAddressFromCache, resetStats, resetThreadDumps, runInNewThread, send, sendToMembers, sendToSingleMember, setBindAddress, setBindPort, setBindToAllInterfaces, setBundler, setBundlerCapacity, setDiagnosticsEnabled, setDiagnosticsHandler, setDropWhenFull, setInAllThreadFactories, setInternalThreadPool, setInternalThreadPoolThreadFactory, setLevel, setLogDiscardMessages, setLogDiscardMessagesVersion, setMessageProcessingPolicy, setPortRange, setSocketFactory, setSourceAddress, setThreadDumpsThreshold, setThreadFactory, setThreadNames, setThreadPool, setThreadPoolKeepAliveTime, setThreadPoolMaxThreads, setThreadPoolMinThreads, setThreadPoolThreadFactory, setTimer, setTimeService, shutdownThreadPool, startDiagnostics, stopDiagnostics, submitToThreadPool, submitToThreadPool, supportedKeys, timestamp, toString, unicastDestMismatch, unregisterProbeHandler, unsetThreadNames, useFibers, versionMatch, view
-
Methods inherited from class org.jgroups.stack.Protocol
accept, afterCreationHook, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getProtocolStack, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, resetStatistics, setDownProtocol, setErgonomics, setId, setProtocolStack, setUpProtocol, setValue, statsEnabled, up, up, up
-
-
-
-
Field Detail
-
tos
protected int tos
Traffic class for sending unicast and multicast datagrams. Valid values are (checkDatagramSocket.setTrafficClass(int)); for details):IPTOS_LOWCOST (0x02), decimal 2IPTOS_RELIABILITY (0x04)<, decimal 4/li>IPTOS_THROUGHPUT (0x08), decimal 8IPTOS_LOWDELAY (0x10), decimal 16
-
UCAST_NAME
protected static final java.lang.String UCAST_NAME
- See Also:
- Constant Field Values
-
MCAST_NAME
protected static final java.lang.String MCAST_NAME
- See Also:
- Constant Field Values
-
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
-
suppress_time_out_of_buffer_space
protected long suppress_time_out_of_buffer_space
-
unicast_receiver_threads
protected int unicast_receiver_threads
-
multicast_receiver_threads
protected int multicast_receiver_threads
-
mcast_addr
protected IpAddress mcast_addr
The multicast address (mcast address and port) this member uses
-
sock
protected java.net.MulticastSocket sock
Socket used for- sending unicast and multicast packets and
- receiving unicast packets
-
mcast_sock
protected java.net.MulticastSocket mcast_sock
IP multicast socket for receiving multicast packets
-
mcast_receivers
protected UDP.PacketReceiver[] mcast_receivers
Runnable to receive multicast packets
-
ucast_receivers
protected UDP.PacketReceiver[] ucast_receivers
Runnable to receive unicast packets
-
suppress_log_out_of_buffer_space
protected SuppressLog<java.net.InetAddress> suppress_log_out_of_buffer_space
-
is_android
protected static final boolean is_android
-
is_mac
protected static final boolean is_mac
-
-
Method Detail
-
supportsMulticasting
public boolean supportsMulticasting()
Description copied from class:TPWhether or not hardware multicasting is supported- Specified by:
supportsMulticastingin classTP
-
setMulticasting
public <T extends UDP> T setMulticasting(boolean fl)
-
setMulticastAddress
public <T extends UDP> T setMulticastAddress(java.net.InetAddress a)
-
getMulticastAddress
public java.net.InetAddress getMulticastAddress()
-
getMulticastPort
public int getMulticastPort()
-
setMulticastPort
public <T extends UDP> T setMulticastPort(int mcast_port)
-
setMcastPort
public <T extends UDP> T setMcastPort(int mcast_port)
-
setMulticastTTL
public <T extends UDP> T setMulticastTTL(int ttl)
Set the ttl for multicast socket- Parameters:
ttl- the time to live for the socket.
-
getMulticastTTL
public int getMulticastTTL()
-
setMaxBundleSize
public <T extends TP> T setMaxBundleSize(int size)
- Overrides:
setMaxBundleSizein classTP
-
getDroppedMessages
public int getDroppedMessages()
-
clearDroppedMessagesCache
public <T extends UDP> T clearDroppedMessagesCache()
-
setUcastReceiverThreads
public <T extends UDP> T setUcastReceiverThreads(int num)
-
getUcastReceiverThreads
public int getUcastReceiverThreads()
-
setMcastReceiverThreads
public <T extends UDP> T setMcastReceiverThreads(int num)
-
getMcastReceiverThreads
public int getMcastReceiverThreads()
-
sendMulticast
public void sendMulticast(byte[] data, int offset, int length) throws java.lang.ExceptionDescription copied from class:TPSend 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:
sendMulticastin classTP- 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:TPSend a unicast to 1 member. Note that the destination address is a *physical*, not a logical address- Specified by:
sendUnicastin classTP- Parameters:
dest- Must be a non-null unicast addressdata- 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, byte[] data, int offset, int length) throws java.lang.Exception- Throws:
java.lang.Exception
-
down
public java.lang.Object down(Event evt)
Description copied from class:ProtocolAn event is to be sent down the stack. A protocol may want to examine its type and perform some action on it, depending on the event's type. If the event is a message MSG, then the protocol may need to add a header to it (or do nothing at all) before sending it down the stack usingdown_prot.down().
-
init
public void init() throws java.lang.ExceptionDescription copied from class:ProtocolCalled 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.
-
start
public void start() throws java.lang.ExceptionCreates the unicast and multicast sockets and starts the unicast and multicast receiver threads- Overrides:
startin classTP- Throws:
java.lang.Exception- Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, soJChannel.connect(String)will throw an exception
-
stop
public void stop()
Description copied from class:ProtocolThis method is called on aJChannel.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
-
handleConnect
protected void handleConnect() throws java.lang.Exception- Overrides:
handleConnectin classTP- Throws:
java.lang.Exception
-
setCorrectSocketBufferSize
protected void setCorrectSocketBufferSize(java.net.MulticastSocket s, int buf_size, int new_size, boolean send, boolean mcast) throws java.net.SocketException- Throws:
java.net.SocketException
-
findMethod
protected static java.lang.reflect.Method findMethod(java.lang.Class<?> clazz, java.lang.String method_name, java.lang.Class<?>... parameters)
-
createSockets
protected void createSockets() throws java.lang.ExceptionCreates the UDP sender and receiver sockets- Throws:
java.lang.Exception
-
destroySockets
protected void destroySockets()
-
createReceivers
protected UDP.PacketReceiver[] createReceivers(int num, java.net.DatagramSocket sock, java.lang.String name)
-
createLocalAddress
protected IpAddress createLocalAddress()
-
setTimeToLive
protected <T extends UDP> T setTimeToLive(int ttl, java.net.MulticastSocket s)
-
setInterface
protected <T extends UDP> T setInterface(java.net.InetAddress intf, java.net.MulticastSocket s)
-
getPhysicalAddress
protected PhysicalAddress getPhysicalAddress()
- Specified by:
getPhysicalAddressin classTP
-
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
-
createMulticastSocketWithBindPort
protected java.net.MulticastSocket createMulticastSocketWithBindPort() throws java.lang.ExceptionCreates 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
-
createMulticastSocket
protected java.net.MulticastSocket createMulticastSocket(java.lang.String service_name, int port) throws java.lang.Exception- 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)
-
getBufferSize
protected static int getBufferSize(java.net.DatagramSocket s, boolean send)
-
closeUnicastSocket
protected void closeUnicastSocket()
-
startThreads
protected void startThreads() throws java.lang.Exception- Throws:
java.lang.Exception
-
startUcastReceiverThreads
protected void startUcastReceiverThreads()
-
startMcastReceiverThreads
protected void startMcastReceiverThreads()
-
stopThreads
protected void stopThreads()
-
stopUcastReceiverThreads
protected void stopUcastReceiverThreads()
-
stopMcastReceiverThreads
protected void stopMcastReceiverThreads()
-
handleConfigEvent
protected void handleConfigEvent(java.util.Map<java.lang.String,java.lang.Object> map) throws java.net.SocketException- Throws:
java.net.SocketException
-
-