|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jgroups.stack.Protocol
org.jgroups.protocols.UDP_NIO
public class UDP_NIO
Multicast transport. Similar to UDP, but binds to multiple (or all) interfaces for sending and receiving
multicast and unicast traffic.
The list of interfaces can be set via a property (comma-delimited list of IP addresses or "all" for all
interfaces). Note that this class only works under JDK 1.4 and higher.
For each of the interfaces listed we create a Listener, which listens on the group multicast address and creates
a unicast datagram socket. The address of this member is determined at startup time, and is the host name plus
a timestamp (LogicalAddress). It does not change during the lifetime of the process. The LogicalAddress contains
a list of all unicast socket addresses to which we can send back unicast messages. When we send a message, the
Listener adds the sender's return address. When we receive a message, we add that address to our routing cache, which
contains logical addresses and physical addresses. When we need to send a unicast address, we first check whether
the logical address has a physical address associated with it in the cache. If so, we send a message to that address.
If not, we send the unicast message to all physical addresses contained in the LogicalAddress.
UDP_NIO guarantees that - in scenarios with multiple subnets and multi-homed machines - members do see each other.
There is some overhead in multicasting the same message on multiple interfaces, and potentially sending a unicast
on multiple interfaces as well, but the advantage is that we don't need stuff like bind_addr any longer. Plus,
the unicast routing caches should ensure that unicasts are only sent via 1 interface in almost all cases.
Nested Class Summary | |
---|---|
static class |
UDP_NIO.Connector
Manages a multicast and unicast socket on a given interface (NIC). |
static class |
UDP_NIO.ConnectorTable
Manages a bunch of Connectors |
static class |
UDP_NIO.MulticastReceiver
|
static class |
UDP_NIO.MyReceiver
|
static class |
UDP_NIO.Unmarshaller
|
Field Summary |
---|
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_NIO()
Creates the UDP_NIO protocol, and initializes the state variables, does however not start any sockets or threads. |
Method Summary | |
---|---|
java.util.List |
determineAllBindInterfaces()
|
java.lang.String |
determineDefaultBindInterface()
Return the first non-loopback interface |
void |
down(Event evt)
Caller by the layer above this layer. |
java.lang.String |
getName()
|
void |
init()
Called after instance has been created (null constructor) and before protocol is started. |
static void |
main(java.lang.String[] args)
|
void |
receive(java.net.DatagramPacket packet)
Called when data has been received on a socket. |
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 |
void |
startUpHandler()
This prevents the up-handler thread to be created, which essentially is superfluous: messages are received from the network rather than from a layer below. |
void |
stop()
This method is called on a Channel.disconnect() . |
java.lang.String |
toString()
debug only |
void |
up(Event evt)
handle the UP event. |
Methods inherited from class org.jgroups.stack.Protocol |
---|
destroy, downThreadEnabled, dumpStats, enableStats, getDownProtocol, getDownQueue, getProperties, getUpProtocol, getUpQueue, handleSpecialDownEvent, isTrace, isWarn, passDown, passUp, printStats, providedDownServices, providedUpServices, receiveDownEvent, receiveUpEvent, requiredDownServices, requiredUpServices, resetStats, 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 |
Constructor Detail |
---|
public UDP_NIO()
Method Detail |
---|
public java.lang.String toString()
toString
in class java.lang.Object
public void receive(java.net.DatagramPacket packet)
buf
must be processed on a separate thread, it needs to be copied.
This method might be called concurrently by multiple threads, so it has to be reentrant
public java.lang.String getName()
getName
in class Protocol
public void init() throws java.lang.Exception
Protocol
init
in class Protocol
java.lang.Exception
- Thrown if protocol cannot be initialized successfully. This will cause the
ProtocolStack to fail, so the channel constructor will throw an exceptionpublic void start() throws java.lang.Exception
start
in class Protocol
java.lang.Exception
- Thrown if protocol cannot be started successfully. This will cause the ProtocolStack
to fail, so Channel.connect(String)
will throw an exceptionpublic void stop()
Protocol
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
stop
in class Protocol
public boolean setProperties(java.util.Properties props)
setProperties
in class Protocol
public void startUpHandler()
startUpHandler
in class Protocol
public void up(Event evt)
up
in class Protocol
evt
- - the event being send from the stackpublic void down(Event evt)
down
in class Protocol
public java.lang.String determineDefaultBindInterface() throws java.net.SocketException
java.net.SocketException
public java.util.List determineAllBindInterfaces() throws java.net.SocketException
java.net.SocketException
public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |