Class DestinationSession

  • All Implemented Interfaces:
    MessageHandler

    public final class DestinationSession
    extends java.lang.Object
    implements MessageHandler
    A session supporting receiving and replying to messages. A destination is expected to reply to every message received.
    Author:
    Simon Thoresen Hult
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void acknowledge​(Message msg)
      Conveniece method for acknowledging a message back to the sender.
      void close()
      This method unregisters this session from message bus, effectively disabling any more messages from being delivered to the message handler.
      boolean destroy()
      Sets the destroyed flag to true.
      java.lang.String getConnectionSpec()
      Returns the connection spec string for this session.
      MessageHandler getMessageHandler()
      Returns the message handler of this session.
      java.lang.String getName()
      Returns the name of this session.
      void handleMessage​(Message msg)
      This function is called when a message arrives.
      void reply​(Reply reply)
      Sends a reply to a message.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.
      • close

        public void close()
        This method unregisters this session from message bus, effectively disabling any more messages from being delivered to the message handler. After unregistering, this method calls MessageBus.sync() as to ensure that there are no threads currently entangled in the handler. This method will deadlock if you call it from the message handler.
      • acknowledge

        public void acknowledge​(Message msg)
        Conveniece method for acknowledging a message back to the sender. This is equivalent to:
             Reply ack = new EmptyReply();
             ack.swapState(msg);
             reply(ack);
         
        Messages should be acknowledged when
        • this destination has safely and permanently applied the message, or
        • an intermediate determines that the purpose of the message is fullfilled without forwarding the message
        Parameters:
        msg - The message to acknowledge back to the sender.
        See Also:
        reply(com.yahoo.messagebus.Reply)
      • reply

        public void reply​(Reply reply)
        Sends a reply to a message. The reply will propagate back to the original sender, prefering the same route as it used to reach the detination.
        Parameters:
        reply - The reply, created from the message this is a reply to.
      • getMessageHandler

        public MessageHandler getMessageHandler()
        Returns the message handler of this session.
        Returns:
        The message handler.
      • getConnectionSpec

        public java.lang.String getConnectionSpec()
        Returns the connection spec string for this session. This returns a combination of the owning message bus' own spec string and the name of this session.
        Returns:
        The connection string.
      • getName

        public java.lang.String getName()
        Returns the name of this session.
        Returns:
        The session name.
      • handleMessage

        public void handleMessage​(Message msg)
        Description copied from interface: MessageHandler
        This function is called when a message arrives.
        Specified by:
        handleMessage in interface MessageHandler
        Parameters:
        msg - The message that arrived.