Class SEQUENCER2

  • All Implemented Interfaces:
    Lifecycle

    public class SEQUENCER2
    extends Protocol
    Implementation of total order protocol using a sequencer_uum. Todo 1: on a sequencer change, the new coordinator needs to determine the highest seqno from all members Todo 2: on a sequencer change, if a member has pendindg messages in the forward-queue, they need to be resent Todo 3: this protocol is currently broken, as a new member doesn't get the highest seqno and thus creates its table at offset=0, which means it will queue all messages higher than 0, and eventually run out of memory!!!
    Author:
    Bela Ban
    • Field Detail

      • coord

        protected volatile Address coord
      • view

        protected volatile View view
      • is_coord

        protected volatile boolean is_coord
      • seqno

        protected final java.util.concurrent.atomic.AtomicLong seqno
      • fwd_queue

        protected final java.util.concurrent.BlockingQueue<Message> fwd_queue
      • seqno_reqs

        protected final java.util.concurrent.atomic.AtomicInteger seqno_reqs
      • running

        protected volatile boolean running
      • BATCH_ACCUMULATOR

        protected static final java.util.function.BiConsumer<MessageBatch,​Message> BATCH_ACCUMULATOR
      • request_msgs

        protected long request_msgs
      • response_msgs

        protected long response_msgs
      • bcasts_sent

        protected long bcasts_sent
      • bcasts_received

        protected long bcasts_received
      • bcasts_delivered

        protected long bcasts_delivered
      • sent_requests

        protected long sent_requests
      • received_requests

        protected long received_requests
      • sent_responses

        protected long sent_responses
      • received_responses

        protected long received_responses
    • Constructor Detail

      • SEQUENCER2

        public SEQUENCER2()
    • Method Detail

      • isCoordinator

        public boolean isCoordinator()
      • getCoordinator

        public Address getCoordinator()
      • getFwdQueueSize

        public int getFwdQueueSize()
      • start

        public void start()
                   throws java.lang.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:
        java.lang.Exception - Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, so JChannel.connect(String) will throw an exception
      • 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 using down_prot.down().
        Overrides:
        down in class Protocol
      • down

        public java.lang.Object down​(Message msg)
        Description copied from class: Protocol
        A message is sent down the stack. Protocols may examine the message and do something (e.g. add a header) with it, before passing it down.
        Overrides:
        down in class Protocol
      • up

        public java.lang.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 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.
        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
      • handleViewChange

        protected void handleViewChange​(View v)
      • sendSeqnoRequest

        protected void sendSeqnoRequest​(int num_seqnos)
      • sendSeqnoResponse

        protected void sendSeqnoResponse​(Address original_sender,
                                         long seqno,
                                         int num_seqnos)
      • broadcast

        protected void broadcast​(Message msg,
                                 long seqno)
      • deliverBatch

        protected void deliverBatch​(MessageBatch batch)