Class DestinationSession

java.lang.Object
com.yahoo.messagebus.DestinationSession
All Implemented Interfaces:
Connectable, MessageHandler

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

    • 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)
      Convenience method for acknowledging a message for its 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 fulfilled without forwarding the message.
      Parameters:
      msg - The message to acknowledge back to the sender.
      See Also:
    • reply

      public void reply(Reply reply)
      Sends a reply to a message. The reply will propagate back to the original sender, preferring the same route as it used to reach the destination.
      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 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 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.
    • connect

      public void connect()
      Specified by:
      connect in interface Connectable
    • disconnect

      public void disconnect()
      Specified by:
      disconnect in interface Connectable