Class Sequencer

  • All Implemented Interfaces:
    MessageHandler, ReplyHandler

    public class Sequencer
    extends java.lang.Object
    implements MessageHandler, ReplyHandler
    Sequencing is implemented as a message handler that is configured in a source session in that session's chain of linked message handlers. Each message that carries a sequencing id is queued in an internal list of messages for that id, and messages are only sent when they are at the front of their list. When a reply arrives, the current front of the list is removed and the next message, if any, is sent.
    Author:
    Simon Thoresen Hult
    • Constructor Summary

      Constructors 
      Constructor Description
      Sequencer​(MessageHandler sender)
      Constructs a new sequencer on top of the given async sender.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean destroy()
      Sets the destroyed flag to true.
      void handleMessage​(Message msg)
      All messages pass through this handler when being sent by the owning source session.
      void handleReply​(Reply reply)
      Lookup the sequencing id of an incoming reply to pop the front of the corresponding queue, and then send the next message in line, if any.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Sequencer

        public Sequencer​(MessageHandler sender)
        Constructs a new sequencer on top of the given async sender.
        Parameters:
        sender - The underlying sender.
    • Method Detail

      • destroy

        public boolean destroy()
        Sets the destroyed flag to true. The very first time this method is called, it cleans up all its dependencies. Even if you retain a reference to this object, all of its content is allowed to be garbage collected.
        Returns:
        True if content existed and was destroyed.
      • handleMessage

        public void handleMessage​(Message msg)
        All messages pass through this handler when being sent by the owning source session. In case the message has no sequencing-id, it is simply passed through to the next handler in the chain. Sequenced messages are sent only if there is no queue for their id, otherwise they are queued.
        Specified by:
        handleMessage in interface MessageHandler
        Parameters:
        msg - the message to send.
      • handleReply

        public void handleReply​(Reply reply)
        Lookup the sequencing id of an incoming reply to pop the front of the corresponding queue, and then send the next message in line, if any.
        Specified by:
        handleReply in interface ReplyHandler
        Parameters:
        reply - The reply received.