Package org.jgroups.protocols
Class FD_SOCK2
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.FD_SOCK2
-
- All Implemented Interfaces:
ConnectionListener,Receiver,Lifecycle,ProcessingQueue.Handler<FD_SOCK2.Request>
public class FD_SOCK2 extends Protocol implements Receiver, ConnectionListener, ProcessingQueue.Handler<FD_SOCK2.Request>
Failure detection protocol based on TCP connections, successor toFD_SOCK. The design is at ./docs/design/FD_SOCK2.txt- Author:
- Bela Ban April 27 2021
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classFD_SOCK2.BroadcastTaskTask which periodically broadcasts a list of suspected members.static classFD_SOCK2.FdHeaderprotected static classFD_SOCK2.PingDestprotected static classFD_SOCK2.Requestprotected static classFD_SOCK2.State
-
Field Summary
Fields Modifier and Type Field Description protected FD_SOCK2.BroadcastTaskbcast_taskprotected java.net.InetAddressbind_addrprotected intclient_bind_portprotected java.lang.Stringclusterprotected intconnect_timeoutprotected java.net.InetAddressexternal_addrprotected intexternal_portprotected intlingerprotected intmax_portprotected Membershipmembersprotected intmin_portprotected intnum_suspect_eventsprotected intoffsetprotected FD_SOCK2.PingDestping_destprotected Membershippingable_mbrsprotected intport_rangeprotected ProcessingQueue<FD_SOCK2.Request>req_handlerprotected booleanshutting_downprotected NioServersrvprotected BoundedList<java.lang.String>suspect_historyprotected longsuspect_msg_intervalprotected Membershipsuspected_mbrsprotected TimeSchedulertimer-
Fields 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 Constructor Description FD_SOCK2()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbroadcastSuspectMessage(java.util.List<Address> suspected_members)Sends a SUSPECT message to all group members.protected voidbroadcastUnuspectMessage(Address mbr)protected voidcloseConnectionToPingDest()protected int[]computeBindPorts(int actual_port)voidconnectionClosed(Connection conn)voidconnectionEstablished(Connection conn)protected booleanconnectTo(Address new_ping_dest, Membership mbrs)protected booleanconnectTo(IpAddress dest, Address logical_addr)protected voidconnectToNextPingDest(Address already_suspect)protected NioServercreateServer(int[] bind_ports)java.lang.Objectdown(Event evt)An event is to be sent down the stack.intgetActualBindPort()java.net.InetAddressgetBindAddress()intgetClientBindPort()java.lang.StringgetClientState()java.net.InetAddressgetExternalAddress()intgetExternalPort()intgetLinger()intgetNumSuspectedMembers()intgetOffset()protected java.util.List<IpAddress>getPhysicalAddresses(Address a)Returns the physical addresses for in range [a+offset..a+offset+port_rangejava.lang.StringgetPingDest()intgetPortRange()longgetSuspectMsgInterval()protected java.lang.Objecthandle(FD_SOCK2.FdHeader hdr, Address sender)voidhandle(FD_SOCK2.Request req)protected voidhandleView(View v)static ByteArraymessageToBuffer(Message msg)java.lang.StringprintConnections()java.lang.StringprintSuspectHistory()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, int length)Receive data from the given sendervoidresetStats()FD_SOCK2setBindAddress(java.net.InetAddress b)FD_SOCK2setClientBindPort(int c)FD_SOCK2setExternalAddress(java.net.InetAddress e)FD_SOCK2setExternalPort(int e)FD_SOCK2setHandlerToNull()Used for perf test onlyFD_SOCK2setLinger(int l)FD_SOCK2setOffset(int o)FD_SOCK2setPortRange(int p)FD_SOCK2setSuspectMsgInterval(long s)voidstart()This method is called on aJChannel.connect(String); starts work.voidstop()Called on aJChannel.disconnect(); stops work (e.g.protected voidsuspect(java.util.Collection<Address> suspects)protected voidunsuspect(Address mbr)java.lang.Objectup(Message msg)A single message was received.voidup(MessageBatch batch)Sends up a multiple messages in aMessageBatch.-
Methods inherited from class org.jgroups.stack.Protocol
accept, addPolicy, addr, addr, afterCreationHook, destroy, down, down, enableStats, getAddress, getComponents, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getPolicies, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, init, isErgonomics, level, parse, policies, providedDownServices, providedUpServices, removePolicy, requiredDownServices, requiredUpServices, resetStatistics, setAddress, setDownProtocol, setErgonomics, setId, setLevel, setPolicies, setProtocolStack, setSocketFactory, setUpProtocol, setValue, statsEnabled, toString, up
-
-
-
-
Field Detail
-
bind_addr
protected java.net.InetAddress bind_addr
-
offset
protected int offset
-
port_range
protected int port_range
-
client_bind_port
protected int client_bind_port
-
external_addr
protected java.net.InetAddress external_addr
-
external_port
protected int external_port
-
suspect_msg_interval
protected long suspect_msg_interval
-
connect_timeout
protected int connect_timeout
-
min_port
protected int min_port
-
max_port
protected int max_port
-
linger
protected int linger
-
num_suspect_events
protected int num_suspect_events
-
shutting_down
protected volatile boolean shutting_down
-
pingable_mbrs
protected final Membership pingable_mbrs
-
members
protected final Membership members
-
suspected_mbrs
protected final Membership suspected_mbrs
-
cluster
protected java.lang.String cluster
-
srv
protected NioServer srv
-
ping_dest
protected final FD_SOCK2.PingDest ping_dest
-
timer
protected TimeScheduler timer
-
bcast_task
protected final FD_SOCK2.BroadcastTask bcast_task
-
req_handler
protected final ProcessingQueue<FD_SOCK2.Request> req_handler
-
suspect_history
protected final BoundedList<java.lang.String> suspect_history
-
-
Method Detail
-
getNumSuspectedMembers
public int getNumSuspectedMembers()
-
getPingDest
public java.lang.String getPingDest()
-
getClientState
public java.lang.String getClientState()
-
getBindAddress
public java.net.InetAddress getBindAddress()
-
setBindAddress
public FD_SOCK2 setBindAddress(java.net.InetAddress b)
-
getExternalAddress
public java.net.InetAddress getExternalAddress()
-
setExternalAddress
public FD_SOCK2 setExternalAddress(java.net.InetAddress e)
-
getExternalPort
public int getExternalPort()
-
setExternalPort
public FD_SOCK2 setExternalPort(int e)
-
getSuspectMsgInterval
public long getSuspectMsgInterval()
-
setSuspectMsgInterval
public FD_SOCK2 setSuspectMsgInterval(long s)
-
getClientBindPort
public int getClientBindPort()
-
setClientBindPort
public FD_SOCK2 setClientBindPort(int c)
-
getPortRange
public int getPortRange()
-
setPortRange
public FD_SOCK2 setPortRange(int p)
-
getOffset
public int getOffset()
-
setOffset
public FD_SOCK2 setOffset(int o)
-
getLinger
public int getLinger()
-
setLinger
public FD_SOCK2 setLinger(int l)
-
setHandlerToNull
public FD_SOCK2 setHandlerToNull()
Used for perf test only
-
getActualBindPort
public int getActualBindPort()
-
printSuspectHistory
public java.lang.String printSuspectHistory()
-
printConnections
public java.lang.String printConnections()
-
start
public void start() throws java.lang.ExceptionDescription copied from class:ProtocolThis method is called on aJChannel.connect(String); starts work. Protocols are connected ready to receive events. Will be called from bottom to top.- Specified by:
startin interfaceLifecycle- Overrides:
startin classProtocol- Throws:
java.lang.Exception- Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, soJChannel.connect(String)will throw an exception
-
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.
-
resetStats
public void resetStats()
- Overrides:
resetStatsin classProtocol
-
up
public java.lang.Object up(Message msg)
Description copied from class:ProtocolA single message was received. Protocols may examine the message and do something (e.g. add a header) with it before passing it up.
-
up
public void up(MessageBatch batch)
Description copied from class:ProtocolSends up a multiple messages in aMessageBatch. The sender of the batch is always the same, and so is the destination (null == multicast messages). Messages in a batch can be OOB messages, regular messages, or mixed messages, although the transport itself will create initial MessageBatches that contain only either OOB or regular messages. The default processing below sends messages up the stack individually, based on a matching criteria (callingProtocol.accept(Message)), and - if true - callsProtocol.up(org.jgroups.Event)for that message and removes the message. If the batch is not empty, it is passed up, or else it is dropped. Subclasses should check if there are any messages destined for them (e.g. usingMessageBatch.iterator(Predicate)), then possibly remove and process them and finally pass the batch up to the next protocol. Protocols can also modify messages in place, e.g. ENCRYPT could decrypt all encrypted messages in the batch, not remove them, and pass the batch up when done.
-
down
public java.lang.Object down(Event evt)
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().
-
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- 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, int length) throws java.lang.Exception
Description copied from interface:ReceiverReceive data from the given sender
-
connectionEstablished
public void connectionEstablished(Connection conn)
- Specified by:
connectionEstablishedin interfaceConnectionListener
-
connectionClosed
public void connectionClosed(Connection conn)
- Specified by:
connectionClosedin interfaceConnectionListener
-
handle
protected java.lang.Object handle(FD_SOCK2.FdHeader hdr, Address sender)
-
createServer
protected NioServer createServer(int[] bind_ports)
-
closeConnectionToPingDest
protected void closeConnectionToPingDest()
-
handle
public void handle(FD_SOCK2.Request req) throws java.lang.Exception
- Specified by:
handlein interfaceProcessingQueue.Handler<FD_SOCK2.Request>- Throws:
java.lang.Exception
-
handleView
protected void handleView(View v)
-
connectToNextPingDest
protected void connectToNextPingDest(Address already_suspect)
-
connectTo
protected boolean connectTo(Address new_ping_dest, Membership mbrs)
-
getPhysicalAddresses
protected java.util.List<IpAddress> getPhysicalAddresses(Address a)
Returns the physical addresses for in range [a+offset..a+offset+port_range
-
messageToBuffer
public static ByteArray messageToBuffer(Message msg) throws java.lang.Exception
- Throws:
java.lang.Exception
-
computeBindPorts
protected int[] computeBindPorts(int actual_port)
-
suspect
protected void suspect(java.util.Collection<Address> suspects)
-
unsuspect
protected void unsuspect(Address mbr)
-
broadcastSuspectMessage
protected void broadcastSuspectMessage(java.util.List<Address> suspected_members)
Sends a SUSPECT message to all group members. Only the coordinator (or the next member in line if the coord itself is suspected) will react to this message by installing a new view. To overcome the unreliability of the SUSPECT message (it may be lost because we are not above any retransmission layer), the following scheme is used: after sending the SUSPECT message, it is also added to the broadcast task, which will periodically re-send the SUSPECT until a view is received in which the suspected process is not a member anymore. The reason is that - at one point - either the coordinator or another participant taking over for a crashed coordinator, will react to the SUSPECT message and issue a new view, at which point the broadcast task stops.
-
broadcastUnuspectMessage
protected void broadcastUnuspectMessage(Address mbr)
-
-