public class FD_SOCK extends Protocol implements Runnable
The main feature of this protocol is that no ping messages need to be exchanged between any 2 peers, and failure detection relies entirely on TCP sockets. The advantage is that no activity will take place between 2 peers as long as they are alive (i.e. have their server sockets open). The disadvantage is that hung servers or crashed routers will not cause sockets to be closed, therefore they won't be detected. The FD_SOCK protocol will work for groups where members are on different hosts
The costs involved are 2 additional threads: one that monitors the client side of the socket connection (to monitor a peer) and another one that manages the server socket. However, those threads will be idle as long as both peers are running.
Modifier and Type | Class and Description |
---|---|
protected class |
FD_SOCK.BroadcastTask
Task that periodically broadcasts a list of suspected members to the group.
|
protected static class |
FD_SOCK.ClientConnectionHandler
Handles a client connection; multiple client can connect at the same time
|
static class |
FD_SOCK.FdHeader |
protected class |
FD_SOCK.ServerSocketHandler
Handles the server-side of a client-server socket connection.
|
after_creation_hook, down_prot, ergonomics, id, log, name, stack, stats, up_prot
Constructor and Description |
---|
FD_SOCK() |
Modifier and Type | Method and Description |
---|---|
protected void |
broadcastSuspectMessage(Address suspected_mbr)
Sends a SUSPECT message to all group members.
|
protected void |
broadcastUnuspectMessage(Address mbr) |
protected Address |
determineCoordinator() |
protected Address |
determinePingDest() |
Object |
down(Event evt)
An event is to be sent down the stack.
|
protected IpAddress |
fetchPingAddress(Address mbr)
Attempts to obtain the ping_addr first from the cache, then by unicasting q request to
mbr ,
then by multicasting a request to all members. |
protected void |
getCacheFromCoordinator()
Determines coordinator C.
|
String |
getLocalAddress() |
String |
getMembers() |
int |
getNumSuspectedMembers() |
int |
getNumSuspectEventsGenerated() |
String |
getPingableMembers() |
String |
getPingDest() |
String |
getSuspectedMembers() |
protected void |
handleSocketClose(Exception ex) |
void |
init()
Called after instance has been created (null constructor) and before protocol is started.
|
protected void |
interruptPingerThread(boolean sendTerminationSignal)
Interrupts the pinger thread.
|
boolean |
isLogSuspectedMessages() |
boolean |
isNodeCrashMonitorRunning() |
protected boolean |
isPingerThreadRunning() |
static Buffer |
marshal(Map<Address,IpAddress> addrs) |
String |
printCache() |
String |
printSuspectHistory() |
protected Map<Address,IpAddress> |
readAddresses(byte[] buffer,
int offset,
int length) |
void |
resetStats() |
void |
run()
Runs as long as there are 2 members and more.
|
protected void |
sendIHaveSockMessage(Address dst,
Address mbr,
IpAddress addr)
Sends or broadcasts a I_HAVE_SOCK response.
|
protected void |
sendPingSignal(int signal) |
protected void |
sendPingTermination() |
void |
setLogSuspectedMessages(boolean log_suspected_msgs) |
protected boolean |
setupPingSocket(IpAddress dest)
Creates a socket to
dest , and assigns it to ping_sock. |
protected static String |
signalToString(int signal) |
void |
start()
This method is called on a
Channel.connect(String) . |
boolean |
startNodeCrashMonitor() |
protected boolean |
startPingerThread()
Does *not* need to be synchronized on pinger_mutex because the caller (down()) already has the mutex acquired
|
protected void |
startServerSocket() |
void |
stop()
This method is called on a
Channel.disconnect() . |
protected void |
stopPingerThread() |
void |
stopServerSocket(boolean graceful) |
protected void |
suspect(Set<Address> suspects) |
protected void |
teardownPingSocket() |
protected void |
unsuspect(Address mbr) |
Object |
up(Event evt)
An event was received from the layer below.
|
accept, afterCreationHook, destroy, dumpStats, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, printStats, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, resetStatistics, setDownProtocol, setErgonomics, setId, setLevel, setProtocolStack, setSocketFactory, setUpProtocol, setValue, setValues, statsEnabled, up
protected static final int NORMAL_TERMINATION
protected static final int ABNORMAL_TERMINATION
protected InetAddress bind_addr
protected InetAddress external_addr
protected int external_port
protected String bind_interface_str
protected long get_cache_timeout
protected long suspect_msg_interval
protected int num_tries
protected int start_port
protected int client_bind_port
protected int port_range
protected boolean keep_alive
protected int sock_conn_timeout
protected int num_suspect_events
protected final BoundedList<String> suspect_history
protected volatile boolean srv_sock_sent
protected final Promise<Map<Address,IpAddress>> get_cache_promise
protected volatile boolean got_cache_from_coord
protected Address local_addr
protected ServerSocket srv_sock
protected FD_SOCK.ServerSocketHandler srv_sock_handler
protected IpAddress srv_sock_addr
protected Address ping_dest
protected Socket ping_sock
protected InputStream ping_input
protected volatile Thread pinger_thread
protected final ConcurrentMap<Address,IpAddress> cache
protected final Object sock_mutex
protected TimeScheduler timer
protected final FD_SOCK.BroadcastTask bcast_task
protected volatile boolean regular_sock_close
protected volatile boolean shuttin_down
protected boolean log_suspected_msgs
public String getLocalAddress()
public String getMembers()
public String getPingableMembers()
public String getSuspectedMembers()
public int getNumSuspectedMembers()
public String getPingDest()
public int getNumSuspectEventsGenerated()
public boolean isNodeCrashMonitorRunning()
public boolean isLogSuspectedMessages()
public void setLogSuspectedMessages(boolean log_suspected_msgs)
public String printSuspectHistory()
public String printCache()
public boolean startNodeCrashMonitor()
public void init() throws Exception
Protocol
public void start() throws Exception
Protocol
Channel.connect(String)
. Starts work.
Protocols are connected and queues are ready to receive events.
Will be called from bottom to top. This call will replace
the START and START_OK events.start
in class Protocol
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 flushedpublic void resetStats()
resetStats
in class Protocol
public Object up(Event evt)
Protocol
down_prot.down()
or c) the event (or another event) is sent up
the stack using up_prot.up()
.public Object down(Event evt)
Protocol
down_prot.down()
. In case of a GET_ADDRESS event (which tries to
retrieve the stack's address from one of the bottom layers), the layer may need to send
a new response event back up the stack using up_prot.up()
.public void run()
protected boolean isPingerThreadRunning()
protected void unsuspect(Address mbr)
protected void handleSocketClose(Exception ex)
protected boolean startPingerThread()
protected void interruptPingerThread(boolean sendTerminationSignal)
Oct 29 2001 (bela): completely removed Thread.interrupt(), but used socket close on all OSs. This makes this code portable and we don't have to check for OSs.
protected void stopPingerThread()
protected void sendPingTermination()
protected void sendPingSignal(int signal)
public void stopServerSocket(boolean graceful)
protected boolean setupPingSocket(IpAddress dest)
dest
, and assigns it to ping_sock. Also assigns ping_inputprotected void teardownPingSocket()
protected void getCacheFromCoordinator()
protected void broadcastSuspectMessage(Address suspected_mbr)
protected void broadcastUnuspectMessage(Address mbr)
protected void sendIHaveSockMessage(Address dst, Address mbr, IpAddress addr)
protected IpAddress fetchPingAddress(Address mbr)
mbr
,
then by multicasting a request to all members.protected Address determinePingDest()
protected Address determineCoordinator()
protected static String signalToString(int signal)
Copyright © 2019 JBoss, a division of Red Hat. All rights reserved.