Class GMS

java.lang.Object
org.jgroups.stack.Protocol
org.jgroups.protocols.pbcast.GMS
All Implemented Interfaces:
Lifecycle, DiagnosticsHandler.ProbeHandler

public class GMS extends Protocol implements DiagnosticsHandler.ProbeHandler
Group membership protocol. Handles joins/leaves/crashes (suspicions) and emits new views accordingly. Use VIEW_ENFORCER on top of this layer to make sure new members don't receive any messages until they are members
  • Field Details

    • CLIENT

      protected static final String CLIENT
      See Also:
    • COORD

      protected static final String COORD
      See Also:
    • PART

      protected static final String PART
      See Also:
    • VIEW_PRESENT

      public static final short VIEW_PRESENT
      See Also:
    • DIGEST_PRESENT

      public static final short DIGEST_PRESENT
      See Also:
    • MERGE_VIEW

      public static final short MERGE_VIEW
      See Also:
    • DELTA_VIEW

      public static final short DELTA_VIEW
      See Also:
    • READ_ADDRS

      public static final short READ_ADDRS
      See Also:
    • join_timeout

      protected long join_timeout
    • max_join_attempts

      protected int max_join_attempts
    • all_clients_retry_timeout

      protected int all_clients_retry_timeout
    • leave_timeout

      protected long leave_timeout
    • max_leave_attempts

      @Deprecated protected int max_leave_attempts
      Deprecated.
    • merge_timeout

      protected long merge_timeout
    • use_delta_views

      protected boolean use_delta_views
    • num_prev_mbrs

      protected int num_prev_mbrs
    • num_prev_views

      protected int num_prev_views
    • view_ack_collection_timeout

      protected long view_ack_collection_timeout
    • use_flush_if_present

      protected boolean use_flush_if_present
    • log_collect_msgs

      protected boolean log_collect_msgs
    • log_view_warnings

      protected boolean log_view_warnings
    • members

      protected final Membership members
    • num_views

      protected int num_views
    • prev_views

      protected BoundedList<String> prev_views
    • impl

      protected GmsImpl impl
    • lock

      protected final Lock lock
    • impls

      protected final Map<String,GmsImpl> impls
    • merger

      protected Merger merger
    • leaver

      protected final Leaver leaver
    • tmp_members

      protected final Membership tmp_members
    • suspected_mbrs

      protected final Membership suspected_mbrs
    • membership_change_policy

      protected MembershipChangePolicy membership_change_policy
    • joining

      protected final List<Address> joining
      Members joined but for which no view has been received yet
    • leaving

      protected final List<Address> leaving
      Members excluded from group, but for which no view has been received yet
    • prev_members

      protected BoundedList<Address> prev_members
      Keeps track of old members (up to num_prev_mbrs)
    • view

      protected volatile View view
    • ltime

      protected long ltime
    • timer

      protected TimeScheduler timer
    • view_handler

      protected final ViewHandler<GmsImpl.Request> view_handler
      Class to process JOIN, LEAVE and MERGE requests
    • ack_collector

      protected final AckCollector ack_collector
      To collect VIEW_ACKs from all members
    • merge_ack_collector

      protected final AckCollector merge_ack_collector
    • flushProtocolInStack

      protected boolean flushProtocolInStack
    • first_view_sent

      protected boolean first_view_sent
  • Constructor Details

    • GMS

      public GMS()
  • Method Details

    • getJoinTimeout

      public long getJoinTimeout()
    • setJoinTimeout

      public GMS setJoinTimeout(long t)
    • getLeaveTimeout

      public long getLeaveTimeout()
    • setLeaveTimeout

      public GMS setLeaveTimeout(long t)
    • getMergeTimeout

      public long getMergeTimeout()
    • setMergeTimeout

      public GMS setMergeTimeout(long t)
    • getMaxJoinAttempts

      public int getMaxJoinAttempts()
    • setMaxJoinAttempts

      public GMS setMaxJoinAttempts(int t)
    • printLocalAddress

      public boolean printLocalAddress()
    • printLocalAddress

      public GMS printLocalAddress(boolean p)
    • printPhysicalAddress

      public boolean printPhysicalAddress()
    • printPhysicalAddress

      public GMS printPhysicalAddress(boolean p)
    • useDeltaViews

      public boolean useDeltaViews()
    • useDeltaViews

      public GMS useDeltaViews(boolean b)
    • getViewAckCollectionTimeout

      public long getViewAckCollectionTimeout()
    • setViewAckCollectionTimeout

      public GMS setViewAckCollectionTimeout(long v)
    • logCollectMessages

      public boolean logCollectMessages()
    • logCollectMessages

      public GMS logCollectMessages(boolean b)
    • logViewWarnings

      public boolean logViewWarnings()
    • logViewWarnings

      public GMS logViewWarnings(boolean b)
    • printViewDetails

      public boolean printViewDetails()
    • printViewDetails

      public GMS printViewDetails(boolean p)
    • getViewId

      public ViewId getViewId()
    • view

      public View view()
    • getViewAndDigest

      public Tuple<View,Digest> getViewAndDigest()
      Returns the current view and digest. Try to find a matching digest twice (if not found on the first try)
    • getView

      public String getView()
    • getImplementation

      public String getImplementation()
    • isCoord

      public boolean isCoord()
    • isLeaving

      public boolean isLeaving()
    • getMembershipChangePolicy

      public MembershipChangePolicy getMembershipChangePolicy()
    • setMembershipChangePolicy

      public GMS setMembershipChangePolicy(MembershipChangePolicy membership_change_policy)
    • getMergeId

      public String getMergeId()
    • isMergeInProgress

      public boolean isMergeInProgress()
    • getMerger

      public Merger getMerger()
      Only used for internal testing, don't use this method !
    • setMembershipChangePolicy

      public GMS setMembershipChangePolicy(String classname)
    • printMergeIdHistory

      public String printMergeIdHistory()
    • printPreviousMembers

      public String printPreviousMembers()
    • getViewHandlerSize

      public int getViewHandlerSize()
    • isViewHandlerSuspended

      public boolean isViewHandlerSuspended()
    • dumpViewHandlerQueue

      public String dumpViewHandlerQueue()
    • dumpViewHandlerHistory

      public String dumpViewHandlerHistory()
    • suspendViewHandler

      public void suspendViewHandler()
    • resumeViewHandler

      public void resumeViewHandler()
    • getViewHandler

      public ViewHandler<GmsImpl.Request> getViewHandler()
    • printPreviousViews

      public String printPreviousViews()
    • suspect

      public void suspect(String suspected_member)
    • _getMergeId

      public MergeId _getMergeId()
    • setLogCollectMessages

      public GMS setLogCollectMessages(boolean flag)
    • getLogCollectMessages

      public boolean getLogCollectMessages()
    • resetStats

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

      public List<Integer> requiredDownServices()
      Description copied from class: Protocol
      List of events that are required to be answered by some layer below
      Overrides:
      requiredDownServices in class Protocol
    • providedDownServices

      public List<Integer> providedDownServices()
      Description copied from class: Protocol
      List of events that are provided to layers below (they will be handled when sent from down below)
      Overrides:
      providedDownServices in class Protocol
    • setImpl

      public void setImpl(GmsImpl new_impl)
    • getImpl

      public GmsImpl getImpl()
    • init

      public void init() throws Exception
      Description copied from class: Protocol
      Called after a protocol has been created and before the protocol is started. Attributes are already set. Other protocols are not yet connected and events cannot yet be sent.
      Specified by:
      init in interface Lifecycle
      Overrides:
      init in class Protocol
      Throws:
      Exception - Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the the channel constructor will throw an exception
    • 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
    • becomeCoordinator

      public void becomeCoordinator()
    • becomeParticipant

      public void becomeParticipant()
    • becomeClient

      public void becomeClient()
    • haveCoordinatorRole

      boolean haveCoordinatorRole()
    • fixDigests

      public void fixDigests()
    • cancelMerge

      public void cancelMerge()
    • isMergeTaskRunning

      public boolean isMergeTaskRunning()
    • isMergeKillerRunning

      public boolean isMergeKillerRunning()
    • getNextView

      public View getNextView(Collection<Address> joiners, Collection<Address> leavers, Collection<Address> suspected_mbrs)
      Computes the next view. Returns a copy that has leavers and suspected_mbrs removed and joiners added.
    • computeNewMembership

      protected List<Address> computeNewMembership(List<Address> current_members, Collection<Address> joiners, Collection<Address> leavers, Collection<Address> suspects)
      Computes the regular membership
    • computeNewMembership

      protected List<Address> computeNewMembership(Collection<Collection<Address>> subviews)
      Computes a merge membership
    • castViewChangeAndSendJoinRsps

      public void castViewChangeAndSendJoinRsps(View new_view, Digest digest, Collection<Address> expected_acks, Collection<Address> joiners, JoinRsp jr)
      Broadcasts the new view and digest as VIEW messages, possibly sends JOIN-RSP messages to joiners and then waits for acks from expected_acks
      Parameters:
      new_view - the new view (View or MergeView)
      digest - the digest, can be null if new_view is not a MergeView
      expected_acks - the members from which to wait for VIEW_ACKs (self will be excluded)
      joiners - the list of members to which to send the join response (jr). If null, no JOIN_RSPs will be sent
      jr - the JoinRsp. If null (or joiners is null), no JOIN_RSPs will be sent
    • sendJoinResponses

      protected void sendJoinResponses(JoinRsp jr, Collection<Address> joiners)
    • sendJoinResponse

      public void sendJoinResponse(JoinRsp rsp, Address dest)
    • sendJoinResponse

      protected void sendJoinResponse(ByteArray marshalled_rsp, Address dest)
    • installView

      public void installView(View new_view)
    • installView

      public void installView(View new_view, Digest digest)
      Sets the new view and sends a VIEW_CHANGE event up and down the stack. If the view is a MergeView (subclass of View), then digest will be non-null and has to be set before installing the view.
    • getCoord

      protected Address getCoord()
    • determineCoordinator

      protected Address determineCoordinator()
    • determineNextCoordinator

      protected Address determineNextCoordinator()
      Returns the second-in-line
    • createDeltaView

      protected static View createDeltaView(View current_view, View next_view)
    • wouldBeNewCoordinator

      protected boolean wouldBeNewCoordinator(Address potential_new_coord)
      Checks whether the potential_new_coord would be the new coordinator (2nd in line)
    • setDigest

      public void setDigest(Digest d)
      Send down a SET_DIGEST event
    • mergeDigest

      public void mergeDigest(Digest d)
      Send down a MERGE_DIGEST event
    • getDigest

      public Digest getDigest()
      Grabs the current digest from NAKACK{2}
    • startFlush

      boolean startFlush(View view)
    • startFlush

      boolean startFlush(View view, int maxAttempts, long floor, long ceiling)
    • _startFlush

      protected boolean _startFlush(View new_view, int maxAttempts, boolean resumeIfFailed, long randomFloor, long randomCeiling)
    • stopFlush

      void stopFlush()
    • stopFlush

      void stopFlush(List<Address> members)
    • up

      public Object up(Event evt)
      Description copied from class: Protocol
      An event was received from the protocol below. Usually the current protocol will want to examine the event type and - depending on its type - perform some computation (e.g. removing headers from a MSG event type, or updating the internal membership list when receiving a VIEW_CHANGE event). Finally, the event is either a) discarded, or b) an event is sent down the stack using down_prot.down() or c) the event (or another event) is sent up the stack using up_prot.up().
      Overrides:
      up 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
    • handleProbe

      public Map<String,String> handleProbe(String... keys)
      Description copied from interface: DiagnosticsHandler.ProbeHandler
      Handles a probe. For each key that is handled, the key and its result should be in the returned map.
      Specified by:
      handleProbe in interface DiagnosticsHandler.ProbeHandler
      Returns:
      A map of keys and values. A null return value is permissible.
    • supportedKeys

      public String[] supportedKeys()
      Description copied from interface: DiagnosticsHandler.ProbeHandler
      Returns a list of supported keys
      Specified by:
      supportedKeys in interface DiagnosticsHandler.ProbeHandler
    • handle

      protected Object handle(GMS.GmsHeader hdr, Message msg)
    • initState

      protected void initState()
    • sendViewAck

      protected void sendViewAck(Address dest)
    • createViewFromDeltaView

      protected View createViewFromDeltaView(View current_view, DeltaView delta_view)
    • writeAddresses

      protected static boolean writeAddresses(View view, Digest digest)
    • determineFlags

      protected static short determineFlags(View view, Digest digest)
    • marshal

      protected static ByteArray marshal(View view, Digest digest)
    • marshal

      public static ByteArray marshal(JoinRsp join_rsp)
    • marshal

      protected static ByteArray marshal(Collection<? extends Address> mbrs)
    • marshal

      protected static ByteArray marshal(ViewId view_id)
    • readJoinRsp

      protected JoinRsp readJoinRsp(byte[] buffer, int offset, int length)
    • readMembers

      protected Collection<? extends Address> readMembers(byte[] buffer, int offset, int length)
    • readViewAndDigest

      protected Tuple<View,Digest> readViewAndDigest(byte[] buffer, int offset, int length)
    • _readViewAndDigest

      public static Tuple<View,Digest> _readViewAndDigest(byte[] buffer, int offset, int length) throws Exception
      Throws:
      Exception
    • readViewId

      protected ViewId readViewId(byte[] buffer, int offset, int length)
    • process

      protected void process(Collection<GmsImpl.Request> requests)