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>

Failure detection protocol based on TCP connections, successor to FD_SOCK. The design is at ./docs/design/FD_SOCK2.txt
  • Field Details

    • bind_addr

      protected InetAddress bind_addr
    • offset

      protected int offset
    • port_range

      protected int port_range
    • client_bind_port

      protected int client_bind_port
    • external_addr

      protected 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 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<String> suspect_history
  • Constructor Details

    • FD_SOCK2

      public FD_SOCK2()
  • Method Details

    • getNumSuspectedMembers

      public int getNumSuspectedMembers()
    • getPingDest

      public String getPingDest()
    • getClientState

      public String getClientState()
    • getBindAddress

      public InetAddress getBindAddress()
    • setBindAddress

      public FD_SOCK2 setBindAddress(InetAddress b)
    • getExternalAddress

      public InetAddress getExternalAddress()
    • setExternalAddress

      public FD_SOCK2 setExternalAddress(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 String printSuspectHistory()
    • printConnections

      public String printConnections()
    • start

      public void start() throws Exception
      Description copied from class: Protocol
      This method is called on a JChannel.connect(String); starts work. Protocols are connected ready to receive events. Will be called from bottom to top.
      Specified by:
      start in interface Lifecycle
      Overrides:
      start in class Protocol
      Throws:
      Exception - Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, so JChannel.connect(String) will throw an exception
    • stop

      public void stop()
      Description copied from class: Protocol
      Called on a JChannel.disconnect(); stops work (e.g. by closing multicast socket). Will be called from top to bottom.
      Specified by:
      stop in interface Lifecycle
      Overrides:
      stop in class Protocol
    • resetStats

      public void resetStats()
      Overrides:
      resetStats in class Protocol
    • up

      public 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.
      Overrides:
      up in class Protocol
    • up

      public void up(MessageBatch batch)
      Description copied from class: Protocol
      Sends up a multiple messages in a MessageBatch. 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 (calling Protocol.accept(Message)), and - if true - calls Protocol.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. using MessageBatch.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.

      Overrides:
      up in class Protocol
      Parameters:
      batch - The message batch
    • down

      public 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 using down_prot.down().
      Overrides:
      down in class Protocol
    • 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 interface Receiver
      Parameters:
      sender - The sender of the message
      buf - 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 starts
      length - The length of the received data
    • receive

      public void receive(Address sender, DataInput in, int length) throws Exception
      Description copied from interface: Receiver
      Receive data from the given sender
      Specified by:
      receive in interface Receiver
      Parameters:
      sender - The sender
      in - The data input from which to read
      length - The number of bytes to read
      Throws:
      Exception
    • connectionEstablished

      public void connectionEstablished(Connection conn)
      Specified by:
      connectionEstablished in interface ConnectionListener
    • connectionClosed

      public void connectionClosed(Connection conn)
      Specified by:
      connectionClosed in interface ConnectionListener
    • handle

      protected 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 Exception
      Specified by:
      handle in interface ProcessingQueue.Handler<FD_SOCK2.Request>
      Throws:
      Exception
    • handleView

      protected void handleView(View v)
    • connectToNextPingDest

      protected void connectToNextPingDest(Address already_suspect)
    • connectTo

      protected boolean connectTo(Address new_ping_dest, Membership mbrs)
    • connectTo

      protected boolean connectTo(IpAddress dest, Address logical_addr)
    • getPhysicalAddresses

      protected 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 Exception
      Throws:
      Exception
    • computeBindPorts

      protected int[] computeBindPorts(int actual_port)
    • suspect

      protected void suspect(Collection<Address> suspects)
    • unsuspect

      protected void unsuspect(Address mbr)
    • broadcastSuspectMessage

      protected void broadcastSuspectMessage(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)