Package org.jgroups.stack
Class GossipRouter
- java.lang.Object
-
- org.jgroups.blocks.cs.ReceiverAdapter
-
- org.jgroups.stack.GossipRouter
-
- All Implemented Interfaces:
ConnectionListener,Receiver
public class GossipRouter extends ReceiverAdapter implements ConnectionListener
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 protected static classGossipRouter.Entrystatic classGossipRouter.TLSClientAuth
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.ConcurrentMap<java.lang.String,java.util.concurrent.ConcurrentMap<Address,GossipRouter.Entry>>address_mappingsprotected intbacklogprotected java.net.InetAddressbind_addrprotected org.jgroups.stack.GossipRouter.DumpMessagesdump_msgsprotected booleanemit_suspect_eventsprotected longexpiry_timeprotected booleanjmxprotected longlinger_timeoutprotected Loglogprotected intmax_lengthprotected static java.util.function.BiConsumer<java.lang.Short,Message>MSG_CONSUMERprotected intportprotected java.util.concurrent.atomic.AtomicBooleanrunningprotected BaseServerserverprotected longsock_read_timeoutprotected SocketFactorysocket_factoryprotected ThreadFactorythread_factoryprotected java.util.Timertimerprotected booleanuse_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 voidaddAddressMapping(Address sender, java.lang.String group, Address addr, PhysicalAddress phys_addr, java.lang.String logical_name)intbacklog()GossipRouterbacklog(int backlog)java.lang.StringbindAddress()GossipRouterbindAddress(java.net.InetAddress addr)voidconnectionClosed(Connection conn)voidconnectionEstablished(Connection conn)protected static voiddump(GossipData data)java.lang.StringdumpAddresssMappings()org.jgroups.stack.GossipRouter.DumpMessagesdumpMessages()GossipRouterdumpMessages(org.jgroups.stack.GossipRouter.DumpMessages flag)java.lang.StringdumpRoutingTable()booleanemitSuspectEvents()GossipRouteremitSuspectEvents(boolean flag)longexpiryTime()GossipRouterexpiryTime(long t)protected voidhandleGetMembersRequest(Address sender, java.io.DataInput in)protected voidhandleRegister(Address sender, java.io.DataInput in)protected voidhandleUnregister(java.io.DataInput in)booleanjmx()GossipRouterjmx(boolean flag)longlingerTimeout()GossipRouterlingerTimeout(long t)AddresslocalAddress()static voidmain(java.lang.String[] args)intmaxLength()GossipRoutermaxLength(int len)intport()GossipRouterport(int port)protected GossipDatareadRequest(java.io.DataInput in)protected GossipDatareadRequest(java.io.DataInput in, GossipType type)voidreceive(Address sender, byte[] buf, int offset, int length)Delivers a message from a given sender to the applicationvoidreceive(Address sender, java.io.DataInput in)protected voidremoveAddressMapping(java.lang.String group, Address addr)protected voidremoveFromAddressMappings(Address client_addr)protected voidroute(java.lang.String group, Address dest, byte[] msg, int offset, int length)booleanrunning()protected voidsendToAllMembersInGroup(java.util.Set<java.util.Map.Entry<Address,GossipRouter.Entry>> dests, byte[] buf, int offset, int len)protected voidsendToAllMembersInGroup(java.util.Set<java.util.Map.Entry<Address,GossipRouter.Entry>> dests, GossipData request)protected voidsendToMember(Address dest, byte[] buf, int offset, int len)protected voidsendToMember(Address dest, GossipData request)SocketFactorysocketFactory()GossipRoutersocketFactory(SocketFactory sf)longsocketReadTimeout()GossipRoutersocketReadTimeout(long t)GossipRouterstart()Lifecycle operation.voidstop()Always called before destroy().ThreadFactorythreadPoolFactory()GossipRouterthreadPoolFactory(ThreadFactory f)booleanuseNio()GossipRouteruseNio(boolean flag)-
Methods inherited from class org.jgroups.blocks.cs.ReceiverAdapter
receive
-
-
-
-
Field Detail
-
bind_addr
protected java.net.InetAddress bind_addr
-
port
protected int port
-
expiry_time
protected long expiry_time
-
linger_timeout
protected long linger_timeout
-
sock_read_timeout
protected long sock_read_timeout
-
thread_factory
protected ThreadFactory thread_factory
-
socket_factory
protected SocketFactory socket_factory
-
backlog
protected int backlog
-
jmx
protected boolean jmx
-
use_nio
protected boolean use_nio
-
emit_suspect_events
protected boolean emit_suspect_events
-
dump_msgs
protected org.jgroups.stack.GossipRouter.DumpMessages dump_msgs
-
max_length
protected int max_length
-
server
protected BaseServer server
-
running
protected final java.util.concurrent.atomic.AtomicBoolean running
-
timer
protected java.util.Timer timer
-
log
protected final Log log
-
address_mappings
protected final java.util.concurrent.ConcurrentMap<java.lang.String,java.util.concurrent.ConcurrentMap<Address,GossipRouter.Entry>> address_mappings
-
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)
-
lingerTimeout
public long lingerTimeout()
-
lingerTimeout
public GossipRouter lingerTimeout(long t)
-
socketReadTimeout
public long socketReadTimeout()
-
socketReadTimeout
public GossipRouter socketReadTimeout(long t)
-
threadPoolFactory
public ThreadFactory threadPoolFactory()
-
threadPoolFactory
public GossipRouter threadPoolFactory(ThreadFactory f)
-
socketFactory
public SocketFactory socketFactory()
-
socketFactory
public GossipRouter socketFactory(SocketFactory sf)
-
backlog
public int backlog()
-
backlog
public GossipRouter backlog(int backlog)
-
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 org.jgroups.stack.GossipRouter.DumpMessages dumpMessages()
-
dumpMessages
public GossipRouter dumpMessages(org.jgroups.stack.GossipRouter.DumpMessages flag)
-
maxLength
public int maxLength()
-
maxLength
public GossipRouter maxLength(int len)
-
running
public boolean running()
-
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()
-
dumpAddresssMappings
public java.lang.String dumpAddresssMappings()
-
receive
public void receive(Address sender, byte[] buf, int offset, int length)
Description copied from interface:ReceiverDelivers a message from a given sender to the application- Specified by:
receivein interfaceReceiver- Overrides:
receivein 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.io.DataInput in) throws java.lang.Exception
- Specified by:
receivein interfaceReceiver- Overrides:
receivein classReceiverAdapter- Throws:
java.lang.Exception
-
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:
connectionClosedin interfaceConnectionListener
-
connectionEstablished
public void connectionEstablished(Connection conn)
- Specified by:
connectionEstablishedin 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)
-
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)
-
sendToMember
protected void sendToMember(Address dest, GossipData request)
-
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
-
-