|
|||||||||
| Home >> All >> org >> jgroups >> [ protocols overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.jgroups.protocols
Class UDP

java.lang.Objectorg.jgroups.stack.Protocol
org.jgroups.protocols.TP
org.jgroups.protocols.UDP
- All Implemented Interfaces:
- java.lang.Runnable
- public class UDP
- extends TP
- implements java.lang.Runnable
- 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 32.
- 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 | |
class |
UDP.UcastReceiver
|
| Nested classes inherited from class org.jgroups.protocols.TP |
TP.IncomingMessageHandler, TP.IncomingPacketHandler, TP.IncomingQueueEntry, TP.OutgoingPacketHandler |
| 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 |
private static org.jgroups.util.BoundedList |
last_ports_used
BoundedList |
(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) java.net.MulticastSocket |
mcast_recv_sock
IP multicast socket for receiving multicast packets |
(package private) int |
mcast_send_buf_size
Send buffer size of the multicast datagram socket |
(package private) java.net.MulticastSocket |
mcast_send_sock
IP multicast socket for sending multicast packets |
(package private) java.net.MulticastSocket[] |
mcast_send_sockets
If we have multiple mcast send sockets, e.g. |
(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) 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.stack.Protocol |
down_handler, down_prot, down_queue, down_thread, down_thread_prio, log, observer, props, stack, stats, trace, up_handler, up_prot, up_queue, up_thread, up_thread_prio, warn |
| Constructor Summary | |
UDP()
Creates the UDP protocol, and initializes the state variables, does however not start any sockets or threads. |
|
| Method Summary | |
private void |
_send(java.net.InetAddress dest,
int port,
boolean mcast,
byte[] data,
int offset,
int length)
|
private void |
bindToInterfaces(java.util.List interfaces,
java.net.MulticastSocket s,
java.net.InetAddress mcastAddr)
|
(package private) void |
closeMulticastSocket()
|
private void |
closeSocket()
|
(package private) void |
closeSockets()
Closed UDP unicast and multicast sockets |
private java.net.DatagramSocket |
createDatagramSocketWithBindPort()
Creates a DatagramSocket when bind_port > 0. |
private java.net.DatagramSocket |
createEphemeralDatagramSocket()
Creates a DatagramSocket with a random port. |
private void |
createSockets()
Create UDP sender and receiver sockets. |
private java.lang.String |
dumpSocketInfo()
|
java.lang.String |
getInfo()
|
private org.jgroups.util.BoundedList |
getLastPortsUsed()
|
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()
This method will be called by whoever wishes to run your class implementing Runnable. |
void |
sendToAllMembers(byte[] data,
int offset,
int length)
Send to all members in the group. |
void |
sendToSingleMember(org.jgroups.Address dest,
byte[] data,
int offset,
int length)
Send to all members in the group. |
private void |
setBufferSize(java.net.DatagramSocket sock,
int send_buf_size,
int recv_buf_size)
|
(package private) void |
setBufferSizes()
|
boolean |
setProperties(java.util.Properties props)
Setup the Protocol instance acording to the configuration string. |
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()
This method is called on a Channel.disconnect()> Channel.disconnect() 55 . |
(package private) void |
stopThreads()
Stops unicast and multicast receiver threads |
| Methods inherited from class org.jgroups.stack.Protocol |
destroy, downThreadEnabled, enableStats, getDownProtocol, getDownQueue, getProperties, getUpProtocol, getUpQueue, handleSpecialDownEvent, init, isTrace, isWarn, passDown, passUp, printStats, providedDownServices, providedUpServices, receiveDownEvent, receiveUpEvent, requiredDownServices, requiredUpServices, setDownProtocol, setObserver, setPropertiesInternal, setProtocolStack, setTrace, setUpProtocol, setWarn, startDownHandler, statsEnabled, stopInternal, 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
- sending unicast packets and
- receiving unicast packets
last_ports_used
private static org.jgroups.util.BoundedList last_ports_used
- BoundedList
of the last 100 ports used. This is to avoid reusing a port for DatagramSocket
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_recv_sock
java.net.MulticastSocket mcast_recv_sock
- IP multicast socket for receiving multicast packets
mcast_send_sock
java.net.MulticastSocket mcast_send_sock
- IP multicast socket for sending 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):IPTOS_LOWCOST (0x02), decimal 2IPTOS_RELIABILITY (0x04)<, decimal 4/LI>IPTOS_THROUGHPUT (0x08), decimal 8IPTOS_LOWDELAY (0x10), decimal 16
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
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 |
UDP
public UDP()
- Creates the UDP protocol, and initializes the
state variables, does however not start any sockets or threads.
| Method Detail |
setProperties
public boolean setProperties(java.util.Properties props)
- Setup the Protocol instance acording to the configuration string.
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 - Set the default time-to-live for multicast packets sent out on this socket. default is 32
- Overrides:
setPropertiesin classTP
getLastPortsUsed
private org.jgroups.util.BoundedList getLastPortsUsed()
run
public void run()
- Description copied from interface:
java.lang.Runnable - This method will be called by whoever wishes to run your class
implementing Runnable. Note that there are no restrictions on what
you are allowed to do in the run method, except that you cannot
throw a checked exception.
- Specified by:
runin interfacejava.lang.Runnable
getInfo
public java.lang.String getInfo()
sendToAllMembers
public void sendToAllMembers(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:
sendToAllMembersin classTP
sendToSingleMember
public void sendToSingleMember(org.jgroups.Address dest, 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:
sendToSingleMemberin classTP
postUnmarshalling
public void postUnmarshalling(org.jgroups.Message msg, org.jgroups.Address dest, org.jgroups.Address src, boolean multicast)
- Specified by:
postUnmarshallingin classTP
postUnmarshallingList
public void postUnmarshallingList(org.jgroups.Message msg, org.jgroups.Address dest, boolean multicast)
- Specified by:
postUnmarshallingListin classTP
_send
private void _send(java.net.InetAddress dest, int port, boolean mcast, byte[] data, int offset, int length) throws java.lang.Exception
getName
public java.lang.String getName()
start
public void start()
throws java.lang.Exception
- Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads
stop
public void stop()
- Description copied from class:
org.jgroups.stack.Protocol - This method is called on a Channel.disconnect()>
Channel.disconnect()55 . 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
createSockets
private 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).
bindToInterfaces
private void bindToInterfaces(java.util.List interfaces, java.net.MulticastSocket s, java.net.InetAddress mcastAddr) throws java.io.IOException
createEphemeralDatagramSocket
private 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
createDatagramSocketWithBindPort
private 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
dumpSocketInfo
private java.lang.String dumpSocketInfo() throws java.lang.Exception
setBufferSizes
void setBufferSizes()
setBufferSize
private void setBufferSize(java.net.DatagramSocket sock, int send_buf_size, int recv_buf_size)
closeSockets
void closeSockets()
- Closed UDP unicast and multicast sockets
closeMulticastSocket
void closeMulticastSocket()
closeSocket
private void closeSocket()
startThreads
void startThreads()
throws java.lang.Exception
- Starts the unicast and multicast receiver threads
stopThreads
void stopThreads()
- Stops unicast and multicast receiver threads
handleConfigEvent
protected void handleConfigEvent(java.util.HashMap map)
- Overrides:
handleConfigEventin classTP
|
|||||||||
| Home >> All >> org >> jgroups >> [ protocols overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC