Package com.yahoo.messagebus
Class DestinationSession
java.lang.Object
com.yahoo.messagebus.DestinationSession
- All Implemented Interfaces:
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 Summary
Modifier and TypeMethodDescriptionvoid
acknowledge
(Message msg) Convenience method for acknowledging a message for its sender.void
close()
This method unregisters this session from message bus, effectively disabling any more messages from being delivered to the message handler.void
connect()
boolean
destroy()
Sets the destroyed flag to true.void
Returns the connection spec string for this session.Returns the message handler of this session.getName()
Returns the name of this session.void
handleMessage
(Message msg) This function is called when a message arrives.void
Sends a reply to a message.
-
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 callsMessageBus.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
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
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
Returns the message handler of this session.- Returns:
- The message handler.
-
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
Returns the name of this session.- Returns:
- The session name.
-
handleMessage
Description copied from interface:MessageHandler
This function is called when a message arrives.- Specified by:
handleMessage
in interfaceMessageHandler
- Parameters:
msg
- The message that arrived.
-
connect
public void connect()- Specified by:
connect
in interfaceConnectable
-
disconnect
public void disconnect()- Specified by:
disconnect
in interfaceConnectable
-