Package org.jgroups.stack
Class GossipRouter
- java.lang.Object
-
- org.jgroups.blocks.cs.ReceiverAdapter
-
- org.jgroups.stack.GossipRouter
-
- All Implemented Interfaces:
ConnectionListener
,Receiver
,DiagnosticsHandler.ProbeHandler
public class GossipRouter extends ReceiverAdapter implements ConnectionListener, DiagnosticsHandler.ProbeHandler
Router for TCP based group comunication (using layer TCP instead of UDP). Instead of the TCP layer sending packets point-to-point to each other member, it sends the packet to the router which - depending on the target address - multicasts or unicasts it to the group / or single member. This class is especially interesting for applets which cannot directly make connections (neither UDP nor TCP) to a host different from the one they were loaded from. Therefore, an applet would create a normal channel plus protocol stack, but the bottom layer would have to be the TCP layer which sends all packets point-to-point (over a TCP connection) to the router, which in turn forwards them to their end location(s) (also over TCP). A centralized router would therefore have to be running on the host the applet was loaded from. An alternative for running JGroups in an applet (IP multicast is not allows in applets as of 1.2), is to use point-to-point UDP communication via the gossip server. However, then the appplet has to be signed which involves additional administrative effort on the part of the user. Note that a GossipRouter is also a good way of running JGroups in Amazon's EC2 environment which (as of summer 09) doesn't support IP multicasting.- Since:
- 2.1.1
- Author:
- Bela Ban, Vladimir Blagojevic, Ovidiu Feodorov
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GossipRouter.DumpMessages
protected static class
GossipRouter.Entry
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,java.util.concurrent.ConcurrentMap<Address,GossipRouter.Entry>>
address_mappings
protected java.net.InetAddress
bind_addr
protected DiagnosticsHandler
diag
protected GossipRouter.DumpMessages
dump_msgs
protected boolean
emit_suspect_events
protected long
expiry_time
protected boolean
jmx
protected int
linger_timeout
protected Log
log
protected int
max_length
protected int
max_send_queue
protected static java.util.function.BiConsumer<java.lang.Short,Message>
MSG_CONSUMER
protected boolean
non_blocking_sends
protected java.util.Map<Address,ByteArrayDataOutputStream>
output_streams
protected int
port
protected long
reaper_interval
protected int
recv_buf_size
protected java.util.concurrent.atomic.AtomicBoolean
running
protected BaseServer
server
protected SocketFactory
socket_factory
protected ThreadFactory
thread_factory
protected TLS
tls
protected boolean
use_nio
-
Constructor Summary
Constructors Constructor Description GossipRouter(java.lang.String bind_addr, int local_port)
GossipRouter(java.net.InetAddress bind_addr, int local_port)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addAddressMapping(Address sender, java.lang.String group, Address addr, PhysicalAddress phys_addr, java.lang.String logical_name)
java.lang.String
bindAddress()
GossipRouter
bindAddress(java.net.InetAddress addr)
void
connectionClosed(Connection conn)
void
connectionEstablished(Connection conn)
DiagnosticsHandler
diagHandler()
protected static void
dump(GossipData data)
java.lang.String
dumpAddressMappings()
GossipRouter.DumpMessages
dumpMessages()
GossipRouter
dumpMessages(boolean d)
GossipRouter
dumpMessages(GossipRouter.DumpMessages flag)
java.lang.String
dumpRoutingTable()
boolean
emitSuspectEvents()
GossipRouter
emitSuspectEvents(boolean flag)
long
expiryTime()
GossipRouter
expiryTime(long t)
protected ByteArrayDataOutputStream
getOutputStream(Address mbr, int size)
protected void
handleGetMembersRequest(Address sender, java.io.DataInput in)
protected void
handleHeartbeat(Address sender)
java.util.Map<java.lang.String,java.lang.String>
handleProbe(java.lang.String... keys)
Handles a probe.protected void
handleRegister(Address sender, java.io.DataInput in)
protected void
handleUnregister(java.io.DataInput in)
GossipRouter
init()
boolean
jmx()
GossipRouter
jmx(boolean flag)
int
lingerTimeout()
GossipRouter
lingerTimeout(int t)
Address
localAddress()
static void
main(java.lang.String[] args)
int
maxLength()
GossipRouter
maxLength(int len)
int
maxSendQueue()
GossipRouter
maxSendQueue(int s)
boolean
nonBlockingSends()
GossipRouter
nonBlockingSends(boolean b)
int
numRegisteredClients()
int
numRegisteredClusters()
int
port()
GossipRouter
port(int port)
protected GossipData
readRequest(java.io.DataInput in)
protected GossipData
readRequest(java.io.DataInput in, GossipType type)
long
reaperInterval()
GossipRouter
reaperInterval(long t)
void
receive(Address sender, byte[] buf, int offset, int length)
Delivers a message from a given sender to the applicationvoid
receive(Address sender, java.io.DataInput in, int length)
Receive data from the given sendervoid
receive(Address sender, java.nio.ByteBuffer buf)
Delivers a message from a given sender to the applicationint
recvBufferSize()
GossipRouter
recvBufferSize(int s)
protected void
removeAddressMapping(java.lang.String group, Address addr)
protected void
removeFromAddressMappings(Address client_addr)
protected void
route(java.lang.String group, Address dest, byte[] msg, int offset, int length)
protected void
route(java.lang.String group, Address dest, java.nio.ByteBuffer buf)
boolean
running()
protected void
sendToAllMembersInGroup(java.util.Set<java.util.Map.Entry<Address,GossipRouter.Entry>> dests, byte[] buf, int offset, int len)
protected void
sendToAllMembersInGroup(java.util.Set<java.util.Map.Entry<Address,GossipRouter.Entry>> dests, java.nio.ByteBuffer buf)
protected void
sendToAllMembersInGroup(java.util.Set<java.util.Map.Entry<Address,GossipRouter.Entry>> dests, GossipData request)
protected void
sendToMember(Address dest, byte[] buf, int offset, int len)
protected void
sendToMember(Address dest, java.nio.ByteBuffer buf)
protected void
sendToMember(Address dest, GossipData request)
SocketFactory
socketFactory()
GossipRouter
socketFactory(SocketFactory sf)
GossipRouter
start()
Lifecycle operation.void
stop()
Always called before destroy().java.lang.String[]
supportedKeys()
Returns a list of supported keysThreadFactory
threadPoolFactory()
GossipRouter
threadPoolFactory(ThreadFactory f)
TLS
tls()
GossipRouter
tls(TLS t)
boolean
useNio()
GossipRouter
useNio(boolean flag)
-
-
-
Field Detail
-
bind_addr
protected java.net.InetAddress bind_addr
-
port
protected int port
-
expiry_time
protected long expiry_time
-
reaper_interval
protected long reaper_interval
-
linger_timeout
protected int linger_timeout
-
thread_factory
protected ThreadFactory thread_factory
-
socket_factory
protected SocketFactory socket_factory
-
recv_buf_size
protected int recv_buf_size
-
jmx
protected boolean jmx
-
use_nio
protected boolean use_nio
-
emit_suspect_events
protected boolean emit_suspect_events
-
dump_msgs
protected GossipRouter.DumpMessages dump_msgs
-
max_length
protected int max_length
-
server
protected BaseServer server
-
running
protected final java.util.concurrent.atomic.AtomicBoolean running
-
log
protected final Log log
-
diag
protected DiagnosticsHandler diag
-
tls
protected TLS tls
-
non_blocking_sends
protected boolean non_blocking_sends
-
max_send_queue
protected int max_send_queue
-
address_mappings
protected final java.util.Map<java.lang.String,java.util.concurrent.ConcurrentMap<Address,GossipRouter.Entry>> address_mappings
-
output_streams
protected final java.util.Map<Address,ByteArrayDataOutputStream> output_streams
-
MSG_CONSUMER
protected static final java.util.function.BiConsumer<java.lang.Short,Message> MSG_CONSUMER
-
-
Method Detail
-
localAddress
public Address localAddress()
-
bindAddress
public java.lang.String bindAddress()
-
bindAddress
public GossipRouter bindAddress(java.net.InetAddress addr)
-
port
public int port()
-
port
public GossipRouter port(int port)
-
expiryTime
public long expiryTime()
-
expiryTime
public GossipRouter expiryTime(long t)
-
reaperInterval
public long reaperInterval()
-
reaperInterval
public GossipRouter reaperInterval(long t)
-
lingerTimeout
public int lingerTimeout()
-
lingerTimeout
public GossipRouter lingerTimeout(int t)
-
recvBufferSize
public int recvBufferSize()
-
recvBufferSize
public GossipRouter recvBufferSize(int s)
-
threadPoolFactory
public ThreadFactory threadPoolFactory()
-
threadPoolFactory
public GossipRouter threadPoolFactory(ThreadFactory f)
-
socketFactory
public SocketFactory socketFactory()
-
socketFactory
public GossipRouter socketFactory(SocketFactory sf)
-
jmx
public boolean jmx()
-
jmx
public GossipRouter jmx(boolean flag)
-
useNio
public boolean useNio()
-
useNio
public GossipRouter useNio(boolean flag)
-
emitSuspectEvents
public boolean emitSuspectEvents()
-
emitSuspectEvents
public GossipRouter emitSuspectEvents(boolean flag)
-
dumpMessages
public GossipRouter.DumpMessages dumpMessages()
-
dumpMessages
public GossipRouter dumpMessages(GossipRouter.DumpMessages flag)
-
dumpMessages
public GossipRouter dumpMessages(boolean d)
-
maxLength
public int maxLength()
-
maxLength
public GossipRouter maxLength(int len)
-
diagHandler
public DiagnosticsHandler diagHandler()
-
tls
public TLS tls()
-
tls
public GossipRouter tls(TLS t)
-
nonBlockingSends
public boolean nonBlockingSends()
-
nonBlockingSends
public GossipRouter nonBlockingSends(boolean b)
-
maxSendQueue
public int maxSendQueue()
-
maxSendQueue
public GossipRouter maxSendQueue(int s)
-
running
public boolean running()
-
numRegisteredClusters
public int numRegisteredClusters()
-
numRegisteredClients
public int numRegisteredClients()
-
init
public GossipRouter init() throws java.lang.Exception
- Throws:
java.lang.Exception
-
start
public GossipRouter start() throws java.lang.Exception
Lifecycle operation. Called after create(). When this method is called, the managed attributes have already been set.
Brings the Router into a fully functional state.- Throws:
java.lang.Exception
-
stop
public void stop()
Always called before destroy(). Close connections and frees resources.
-
dumpRoutingTable
public java.lang.String dumpRoutingTable()
-
dumpAddressMappings
public java.lang.String dumpAddressMappings()
-
receive
public void receive(Address sender, byte[] buf, int offset, int length)
Description copied from interface:Receiver
Delivers a message from a given sender to the application- Specified by:
receive
in interfaceReceiver
- Overrides:
receive
in classReceiverAdapter
- Parameters:
sender
- The sender of the messagebuf
- The buffer. An application typically de-serializes data from the buffer into objects used by the application. Note that when receive() returns, it is not safe to use the buffer any longer; if an application needs to use a buffer after this callback returns, it must make a copy.offset
- The offset at which the received data startslength
- The length of the received data
-
receive
public void receive(Address sender, java.nio.ByteBuffer buf)
Description copied from interface:Receiver
Delivers a message from a given sender to the application- Specified by:
receive
in interfaceReceiver
- Parameters:
sender
- The sender of the messagebuf
- The buffer. An application typically de-serializes data from the buffer into objects used by the application. Note that when receive() returns, it is not safe to use the buffer any longer; if an application needs to use a buffer after this callback returns, it must make a copy. Note that buf could be a direct ByteBuffer.
-
receive
public void receive(Address sender, java.io.DataInput in, int length) throws java.lang.Exception
Description copied from interface:Receiver
Receive data from the given sender
-
handleProbe
public java.util.Map<java.lang.String,java.lang.String> handleProbe(java.lang.String... keys)
Description copied from interface:DiagnosticsHandler.ProbeHandler
Handles a probe. For each key that is handled, the key and its result should be in the returned map.- Specified by:
handleProbe
in interfaceDiagnosticsHandler.ProbeHandler
- Returns:
- Map
. A map of keys and values. A null return value is permissible.
-
supportedKeys
public java.lang.String[] supportedKeys()
Description copied from interface:DiagnosticsHandler.ProbeHandler
Returns a list of supported keys- Specified by:
supportedKeys
in interfaceDiagnosticsHandler.ProbeHandler
-
getOutputStream
protected ByteArrayDataOutputStream getOutputStream(Address mbr, int size)
-
handleHeartbeat
protected void handleHeartbeat(Address sender)
-
handleRegister
protected void handleRegister(Address sender, java.io.DataInput in)
-
handleUnregister
protected void handleUnregister(java.io.DataInput in)
-
handleGetMembersRequest
protected void handleGetMembersRequest(Address sender, java.io.DataInput in)
-
dump
protected static void dump(GossipData data)
-
connectionClosed
public void connectionClosed(Connection conn)
- Specified by:
connectionClosed
in interfaceConnectionListener
-
connectionEstablished
public void connectionEstablished(Connection conn)
- Specified by:
connectionEstablished
in interfaceConnectionListener
-
readRequest
protected GossipData readRequest(java.io.DataInput in)
-
readRequest
protected GossipData readRequest(java.io.DataInput in, GossipType type)
-
addAddressMapping
protected void addAddressMapping(Address sender, java.lang.String group, Address addr, PhysicalAddress phys_addr, java.lang.String logical_name)
-
removeAddressMapping
protected void removeAddressMapping(java.lang.String group, Address addr)
-
removeFromAddressMappings
protected void removeFromAddressMappings(Address client_addr)
-
route
protected void route(java.lang.String group, Address dest, byte[] msg, int offset, int length)
-
route
protected void route(java.lang.String group, Address dest, java.nio.ByteBuffer buf)
-
sendToAllMembersInGroup
protected void sendToAllMembersInGroup(java.util.Set<java.util.Map.Entry<Address,GossipRouter.Entry>> dests, GossipData request)
-
sendToAllMembersInGroup
protected void sendToAllMembersInGroup(java.util.Set<java.util.Map.Entry<Address,GossipRouter.Entry>> dests, byte[] buf, int offset, int len)
-
sendToAllMembersInGroup
protected void sendToAllMembersInGroup(java.util.Set<java.util.Map.Entry<Address,GossipRouter.Entry>> dests, java.nio.ByteBuffer buf)
-
sendToMember
protected void sendToMember(Address dest, GossipData request)
-
sendToMember
protected void sendToMember(Address dest, java.nio.ByteBuffer buf)
-
sendToMember
protected void sendToMember(Address dest, byte[] buf, int offset, int len)
-
main
public static void main(java.lang.String[] args) throws java.lang.Exception
- Throws:
java.lang.Exception
-
-