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 class
FD_SOCK2.BroadcastTask
Task which periodically broadcasts a list of suspected members.static class
FD_SOCK2.FdHeader
protected static class
FD_SOCK2.PingDest
protected static class
FD_SOCK2.Request
protected static class
FD_SOCK2.State
-
Field Summary
Fields Modifier and Type Field Description protected FD_SOCK2.BroadcastTask
bcast_task
protected java.net.InetAddress
bind_addr
protected int
client_bind_port
protected java.lang.String
cluster
protected int
connect_timeout
protected java.net.InetAddress
external_addr
protected int
external_port
protected int
linger
protected int
max_port
protected Membership
members
protected int
min_port
protected int
num_suspect_events
protected int
offset
protected FD_SOCK2.PingDest
ping_dest
protected Membership
pingable_mbrs
protected int
port_range
protected ProcessingQueue<FD_SOCK2.Request>
req_handler
protected boolean
shutting_down
protected NioServer
srv
protected BoundedList<java.lang.String>
suspect_history
protected long
suspect_msg_interval
protected Membership
suspected_mbrs
protected TimeScheduler
timer
-
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 void
broadcastSuspectMessage(java.util.List<Address> suspected_members)
Sends a SUSPECT message to all group members.protected void
broadcastUnuspectMessage(Address mbr)
protected void
closeConnectionToPingDest()
protected int[]
computeBindPorts(int actual_port)
void
connectionClosed(Connection conn)
void
connectionEstablished(Connection conn)
protected boolean
connectTo(Address new_ping_dest, Membership mbrs)
protected boolean
connectTo(IpAddress dest, Address logical_addr)
protected void
connectToNextPingDest(Address already_suspect)
protected NioServer
createServer(int[] bind_ports)
java.lang.Object
down(Event evt)
An event is to be sent down the stack.int
getActualBindPort()
java.net.InetAddress
getBindAddress()
int
getClientBindPort()
java.lang.String
getClientState()
java.net.InetAddress
getExternalAddress()
int
getExternalPort()
int
getLinger()
int
getNumSuspectedMembers()
int
getOffset()
protected java.util.List<IpAddress>
getPhysicalAddresses(Address a)
Returns the physical addresses for in range [a+offset..a+offset+port_rangejava.lang.String
getPingDest()
int
getPortRange()
long
getSuspectMsgInterval()
protected java.lang.Object
handle(FD_SOCK2.FdHeader hdr, Address sender)
void
handle(FD_SOCK2.Request req)
protected void
handleView(View v)
static ByteArray
messageToBuffer(Message msg)
java.lang.String
printConnections()
java.lang.String
printSuspectHistory()
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
resetStats()
FD_SOCK2
setBindAddress(java.net.InetAddress b)
FD_SOCK2
setClientBindPort(int c)
FD_SOCK2
setExternalAddress(java.net.InetAddress e)
FD_SOCK2
setExternalPort(int e)
FD_SOCK2
setLinger(int l)
FD_SOCK2
setOffset(int o)
FD_SOCK2
setPortRange(int p)
FD_SOCK2
setSuspectMsgInterval(long s)
void
start()
This method is called on aJChannel.connect(String)
; starts work.void
stop()
Called on aJChannel.disconnect()
; stops work (e.g.protected void
suspect(java.util.Collection<Address> suspects)
protected void
unsuspect(Address mbr)
java.lang.Object
up(Message msg)
A single message was received.void
up(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)
-
getActualBindPort
public int getActualBindPort()
-
printSuspectHistory
public java.lang.String printSuspectHistory()
-
printConnections
public java.lang.String printConnections()
-
start
public void start() throws java.lang.Exception
Description copied from class:Protocol
This 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:
start
in interfaceLifecycle
- Overrides:
start
in 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:Protocol
Called on aJChannel.disconnect()
; stops work (e.g. by closing multicast socket). Will be called from top to bottom.
-
resetStats
public void resetStats()
- Overrides:
resetStats
in classProtocol
-
up
public java.lang.Object up(Message msg)
Description copied from class:Protocol
A 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:Protocol
Sends 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:Protocol
An 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: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.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:Receiver
Receive data from the given sender
-
connectionEstablished
public void connectionEstablished(Connection conn)
- Specified by:
connectionEstablished
in interfaceConnectionListener
-
connectionClosed
public void connectionClosed(Connection conn)
- Specified by:
connectionClosed
in 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:
handle
in 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)
-
-