Package org.jgroups.protocols
Class UDP
java.lang.Object
org.jgroups.stack.Protocol
org.jgroups.protocols.TP
org.jgroups.protocols.UDP
- All Implemented Interfaces:
Lifecycle,DiagnosticsHandler.ProbeHandler
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 239.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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected intprotected static final booleanprotected static final booleanprotected IpAddressThe multicast address (mcast address and port) this member usesprotected InetAddressprotected static final Stringprotected intprotected UDP.PacketReceiver[]Runnable to receive multicast packetsprotected intprotected intprotected MulticastSocketIP multicast socket for receiving multicast packetsprotected intprotected MulticastSocketSocket 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<InetAddress> protected longprotected intTraffic class for sending unicast and multicast datagrams.protected static final Stringprotected UDP.PacketReceiver[]Runnable to receive unicast packetsprotected intprotected intprotected intFields inherited from class org.jgroups.protocols.TP
async_executor, bind_addr, bind_port, bundler, bundler_type, cluster_name, connectLock, diag_handler, external_addr, external_port, header, is_trace, last_discovery_request, LIST, local_physical_addr, local_transport, local_transport_class, 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, members, message_processing_policy, MIN_WAIT_BETWEEN_DISCOVERIES, msg_factory, msg_factory_class, MSG_OVERHEAD, msg_processing_policy, msg_stats, MULTICAST, port_range, print_function, receive_interfaces, receive_on_all_interfaces, rtt, socket_factory, suppress_log_different_cluster, suppress_log_different_version, suppress_time_different_cluster_warnings, suppress_time_different_version_warnings, thread_factory, thread_naming_pattern, thread_pool, time_service, time_service_interval, timer, timer_handle_non_blocking_tasks, use_virtual_threads, view, who_has_cache, who_has_cache_timeoutFields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, local_addr, log, policies, stack, stats, up_prot -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void_send(InetAddress dest, int port, byte[] data, int offset, int length) <T extends UDP>
T(package private) voidprotected voidprotected IpAddressprotected MulticastSocketcreateMulticastSocket(String service_name, int port) protected MulticastSocketCreates a DatagramSocket when bind_port > 0.protected UDP.PacketReceiver[]createReceivers(int num, DatagramSocket sock, String name) protected voidCreates the UDP sender and receiver socketsprotected voidbooleandisableLoopback(boolean d) An event is to be sent down the stack.protected Stringprotected static MethodfindMethod(Class<?> clazz, String method_name, Class<?>... parameters) protected static intgetBufferSize(DatagramSocket s, boolean send) intgetInfo()intgetIpTTL()intintintintintprotected PhysicalAddresslongintgetTos()intintintprotected voidhandleConfigEvent(Map<String, Object> map) protected voidvoidinit()Called after a protocol has been created and before the protocol is started.booleanipMcast()ipMcast(boolean i) protected voidjoinGroupOnInterfaces(List<NetworkInterface> interfaces, MulticastSocket s, InetAddress mcast_addr) Joins a multicast address on all interfacesvoidsendToAll(byte[] data, int offset, int length) Fetches the physical addrs for all mbrs and sends the msg to each physical address.voidsendUnicast(PhysicalAddress dest, byte[] data, int offset, int length) Send a unicast to a member.protected voidsetBufferSize(DatagramSocket sock, int send_buf_size, int recv_buf_size) (package private) voidprotected voidsetCorrectSocketBufferSize(MulticastSocket s, int buf_size, int new_size, boolean send, boolean mcast) setIpTTL(int i) <T extends UDP>
TsetMcastReceiverThreads(int num) setMcastRecvBufSize(int m) setMcastSendBufSize(int m) <T extends UDP>
T<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>
TsetSuppressTimeOutOfBufferSpace(long s) protected <T extends UDP>
TsetTimeToLive(int ttl, MulticastSocket s) setTos(int t) <T extends UDP>
TsetUcastReceiverThreads(int num) setUcastRecvBufSize(int u) setUcastSendBufSize(int u) voidstart()Creates the unicast and multicast sockets and starts the unicast and multicast receiver threadsprotected voidprotected voidprotected voidvoidstop()Called on aJChannel.disconnect(); stops work (e.g.protected voidprotected voidprotected voidbooleanWhether hardware multicasting is supportedMethods inherited from class org.jgroups.protocols.TP
_send, addPhysicalAddressToCache, addPhysicalAddressToCache, bundler, clearDifferentClusterCache, clearDifferentVersionCache, clearLogicalAddressCache, createBundler, createDiagnosticsHandler, defaultHeaders, destroy, disableDiagnostics, doSend, down, dumpTimerTasks, enableBlockingTimerTasks, enableDiagnostics, enableStats, evictLogicalAddressCache, evictLogicalAddressCache, fetchLocalAddresses, fetchPhysicalAddrs, fetchResponsesFromDiscoveryProtocol, getAllPhysicalAddressesFromCache, getAsyncExecutor, getBindAddr, getBindAddress, getBindPort, getBundler, getBundlerClass, getBundlerType, getClusterName, getClusterNameAscii, getDiagnosticsHandler, getDifferentClusterMessages, getDifferentVersionMessages, getExternalAddr, getExternalPort, getLocalPhysicalAddress, getLocalTransport, getLogDiscardMessages, getLogDiscardMessagesVersion, getLogicalAddrCacheExpiration, getLogicalAddrCacheMaxSize, getLogicalAddrCacheReaperInterval, getLogicalAddressCache, getMessageFactory, getMessageFactoryClass, getMessageProcessingPolicy, getMessageStats, getMsgFactoryClass, getNumberOfThreadDumps, getNumMcastMsgsReceived, getNumMcastMsgsSent, getNumRejectedMsgs, getNumThreads, getNumTimerTasks, getNumUcastMsgsReceived, getNumUcastMsgsSent, getPhysicalAddressFromCache, getPortRange, getReceiveInterfaces, getRTT, getSocketFactory, getSuppressTimeDifferentClusterWarnings, getSuppressTimeDifferentVersionWarnings, getThreadFactory, getThreadNamingPattern, getThreadPool, getTimer, getTimerClass, getTimerThreads, getTimeService, getTimeServiceInterval, getWhoHasCacheTimeout, handleDisconnect, handleMessageBatch, handleProbe, handleSingleMessage, isLogicalAddressCacheReaperRunning, isMulticastCapable, isReceiveOnAllInterfaces, isTrace, isTrace, localPhysicalAddress, logDiscardMsgs, logDiscardMsgs, logDiscardMsgsVersion, logDiscardMsgsVersion, loggerType, loopback, loopbackCopy, loopbackCopy, loopbackSeparateThread, loopbackSeparateThread, passBatchUp, passMessageUp, printLogicalAddressCache, printWhoHasCache, processBatch, receive, receive, receiveOnAllInterfaces, receiveOnAllInterfaces, registerLocalAddress, registerProbeHandler, removeCancelledTimerTasks, removeLogicalAddressFromCache, resetStats, sameCluster, sendTo, setAddress, setAsyncExecutor, setBindAddr, setBindAddress, setBindPort, setBindToAllInterfaces, setBundler, setBundlerType, setDiagnosticsHandler, setExternalAddr, setExternalPort, setInAllThreadFactories, setLevel, setLocalTransport, setLocalTransport, setLogDiscardMessages, setLogDiscardMessagesVersion, setLogicalAddrCacheExpiration, setLogicalAddrCacheMaxSize, setLogicalAddrCacheReaperInterval, setMessageFactory, setMessageProcessingPolicy, setMsgFactoryClass, setPortRange, setSocketFactory, setSourceAddress, setSuppressTimeDifferentClusterWarnings, setSuppressTimeDifferentVersionWarnings, setThreadFactory, setThreadNames, setThreadPool, setTimer, setTimeService, setTimeServiceInterval, setWhoHasCacheTimeout, startDiagnostics, stopDiagnostics, supportedKeys, timestamp, toString, unicastDestMismatch, unregisterProbeHandler, unsetThreadNames, useVirtualThreads, useVirtualThreads, versionMatch, viewMethods inherited from class org.jgroups.stack.Protocol
accept, addPolicy, addr, addr, afterCreationHook, down, getAddress, getComponents, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getPolicies, getProtocolStack, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, policies, providedDownServices, providedUpServices, removePolicy, requiredDownServices, requiredUpServices, resetStatistics, setDownProtocol, setErgonomics, setId, setPolicies, setProtocolStack, setUpProtocol, setValue, statsEnabled, up, up, up
-
Field Details
-
tos
protected int tosTraffic class for sending unicast and multicast datagrams. Valid values are (checkDatagramSocket.setTrafficClass(int)); for details):IPTOS_LOWCOST (0x02), decimal 2IPTOS_RELIABILITY (0x04), decimal 4IPTOS_THROUGHPUT (0x08), decimal 8IPTOS_LOWDELAY (0x10), decimal 16
-
UCAST_NAME
- See Also:
-
MCAST_NAME
- See Also:
-
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
The multicast address (mcast address and port) this member uses -
sock
Socket used for- sending unicast and multicast packets and
- receiving unicast packets
-
mcast_sock
IP multicast socket for receiving multicast packets -
mcast_receivers
Runnable to receive multicast packets -
ucast_receivers
Runnable to receive unicast packets -
suppress_log_out_of_buffer_space
-
is_android
protected static final boolean is_android -
is_mac
protected static final boolean is_mac
-
-
Constructor Details
-
UDP
public UDP()
-
-
Method Details
-
supportsMulticasting
public boolean supportsMulticasting()Description copied from class:TPWhether hardware multicasting is supported- Specified by:
supportsMulticastingin classTP
-
setMulticasting
-
setMulticastAddress
-
getMulticastAddress
-
getMulticastPort
public int getMulticastPort() -
setMulticastPort
-
getTos
public int getTos() -
setTos
-
getMcastGroupAddr
-
setMcastGroupAddr
-
ipMcast
public boolean ipMcast() -
ipMcast
-
getIpTTL
public int getIpTTL() -
setIpTTL
-
getMcastSendBufSize
public int getMcastSendBufSize() -
setMcastSendBufSize
-
getMcastRecvBufSize
public int getMcastRecvBufSize() -
setMcastRecvBufSize
-
getUcastSendBufSize
public int getUcastSendBufSize() -
setUcastSendBufSize
-
getUcastRecvBufSize
public int getUcastRecvBufSize() -
setUcastRecvBufSize
-
disableLoopback
public boolean disableLoopback() -
disableLoopback
-
getSuppressTimeOutOfBufferSpace
public long getSuppressTimeOutOfBufferSpace() -
setSuppressTimeOutOfBufferSpace
-
setMulticastTTL
Set the ttl for multicast socket- Parameters:
ttl- the time to live for the socket.
-
getMulticastTTL
public int getMulticastTTL() -
getDroppedMessages
public int getDroppedMessages() -
clearDroppedMessagesCache
-
setUcastReceiverThreads
-
getUcastReceiverThreads
public int getUcastReceiverThreads() -
setMcastReceiverThreads
-
getMcastReceiverThreads
public int getMcastReceiverThreads() -
getInfo
-
sendToAll
Description copied from class:TPFetches the physical addrs for all mbrs and sends the msg to each physical address. Asks discovery for missing members' physical addresses if needed -
sendUnicast
Description copied from class:TPSend a unicast to a 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:
Exception
-
_send
protected void _send(InetAddress dest, int port, byte[] data, int offset, int length) throws Exception - Throws:
Exception
-
down
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
Description copied from class:ProtocolCalled after a protocol has been created and before the protocol is started. Attributes are already set. Other protocols are not yet connected and events cannot yet be sent. -
start
Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads -
stop
public void stop()Description copied from class:ProtocolCalled on aJChannel.disconnect(); stops work (e.g. by closing multicast socket). Will be called from top to bottom. -
handleConnect
- Overrides:
handleConnectin classTP- Throws:
Exception
-
setCorrectSocketBufferSize
protected void setCorrectSocketBufferSize(MulticastSocket s, int buf_size, int new_size, boolean send, boolean mcast) throws SocketException - Throws:
SocketException
-
findMethod
-
createSockets
Creates the UDP sender and receiver sockets- Throws:
Exception
-
destroySockets
protected void destroySockets() -
createReceivers
-
createLocalAddress
-
setTimeToLive
-
setNetworkInterface
-
getPhysicalAddress
- Specified by:
getPhysicalAddressin classTP
-
joinGroupOnInterfaces
protected void joinGroupOnInterfaces(List<NetworkInterface> interfaces, MulticastSocket s, InetAddress mcast_addr) Joins a multicast address on all interfaces- Parameters:
interfaces- The interfaces to join mcast_addr:mcast_ports- The MulticastSocket to join onmcast_addr- The multicast address to join
-
createMulticastSocketWithBindPort
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:
Exception
-
createMulticastSocket
- Throws:
Exception
-
dumpSocketInfo
- Throws:
Exception
-
setBufferSizes
- Throws:
SocketException
-
setBufferSize
-
getBufferSize
-
closeMulticastSocket
void closeMulticastSocket() -
closeUnicastSocket
protected void closeUnicastSocket() -
startThreads
- Throws:
Exception
-
startUcastReceiverThreads
protected void startUcastReceiverThreads() -
startMcastReceiverThreads
protected void startMcastReceiverThreads() -
stopThreads
protected void stopThreads() -
stopUcastReceiverThreads
protected void stopUcastReceiverThreads() -
stopMcastReceiverThreads
protected void stopMcastReceiverThreads() -
handleConfigEvent
- Throws:
SocketException
-