Class SourceSession

java.lang.Object
com.yahoo.messagebus.SourceSession
All Implemented Interfaces:
MessageBus.SendBlockedMessages, ReplyHandler

public final class SourceSession extends Object implements ReplyHandler, MessageBus.SendBlockedMessages
A session supporting sending new messages.
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()
      Reject all new messages and wait until no messages are pending. Before returning, this method calls destroy().
    • send

      public Result send(Message message)

      Sends a new message. Calling this immediately causes one of three possible results:

      • A result is returned indicating that the message is accepted. In this case, a reply to the message is guaranteed to be produced on this session within a timeout limit. That reply may indicate either success or failure.
      • A result is returned indicating that the message is not accepted. This is a transient failure, retrying the same operation after some wait period should cause it to be accepted.
      • An exception is thrown, indicating a non-transient error which is not expected to be fixed before some corrective action is taken.

      A source client should typically do some equivalent of:

      do { Result result = sourceSession.send(message); if (!result.isAccepted()) // Do something else or wait a while } while (!result.isAccepted());
      Parameters:
      message - the message to send
      Returns:
      the result of initiating sending of this message
    • trySend

      public boolean trySend()
      Description copied from interface: MessageBus.SendBlockedMessages
      Do what you want, but dont block. You will be called regularly until you signal you are done
      Specified by:
      trySend in interface MessageBus.SendBlockedMessages
      Returns:
      true unless you are done
    • sendBlocking

      public Result sendBlocking(Message msg) throws InterruptedException
      This is a blocking proxy to the send(Message) method. This method blocks until the message is accepted by the send queue. Note that the message timeout does not activate by calling this method. This method will also return if this session is closed or the calling thread is interrupted.
      Parameters:
      msg - the message to send
      Returns:
      the result of initiating send
      Throws:
      InterruptedException - thrown if the calling thread is interrupted
    • handleReply

      public void handleReply(Reply reply)
      Description copied from interface: ReplyHandler
      This function is called when a reply arrives.
      Specified by:
      handleReply in interface ReplyHandler
      Parameters:
      reply - The reply that arrived.
    • send

      public Result send(Message msg, Route route)
      This is a convenience function to assign a given route to the given message, and then pass it to the other send(Message) method of this session.
      Parameters:
      msg - the message to send
      route - the route to assign to the message
      Returns:
      the immediate result of the attempt to send this message
    • send

      public Result send(Message msg, String routeName)
      This is a convenience method to call send(Message,String,boolean) with a false value for the 'parseIfNotFound' parameter.
      Parameters:
      msg - the message to send
      routeName - the route to assign to the message
      Returns:
      the immediate result of the attempt to send this message
    • send

      public Result send(Message msg, String routeName, boolean parseIfNotFound)
      This is a convenience function to assign a named route to the given message, and then pass it to the other send(Message) method of this session. If the route could not be found this methods returns with an appropriate error, unless the 'parseIfNotFound' argument is true. In that case, the route name is passed through to the Route factory method Route.parse(java.lang.String).
      Parameters:
      msg - the message to send
      routeName - the route to assign to the message
      parseIfNotFound - whether or not to parse routeName as a route if it could not be found
      Returns:
      the immediate result of the attempt to send this message
    • getReplyHandler

      public ReplyHandler getReplyHandler()
      Returns the reply handler of this session
    • getPendingCount

      public int getPendingCount()
      Returns the number of messages sent that have not been replied to yet
    • setTimeout

      public SourceSession setTimeout(double timeout)
      Sets the number of seconds a message can be attempted sent until it times out.
      Parameters:
      timeout - the number of seconds allowed.
      Returns:
      this, to allow chaining.
    • getThrottlePolicy

      public ThrottlePolicy getThrottlePolicy()