Class RoutingContext

java.lang.Object
com.yahoo.messagebus.routing.RoutingContext

public class RoutingContext extends Object

This context object is what is seen by RoutingPolicy when doing both select() and merge(). It contains the necessary accessors to everything a policy is expected to need. An instance of this is created for every RoutingNode that contains a policy.

Author:
Simon Thoresen Hult
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hasRecipients

      public boolean hasRecipients()

      Returns whether or not this hop has any configured recipients.

      Returns:
      True if there is at least one recipient.
    • getNumRecipients

      public int getNumRecipients()

      Returns the number of configured recipients for this hop.

      Returns:
      The recipient count.
    • getRecipient

      public Route getRecipient(int idx)

      Returns the configured recipient at the given index.

      Parameters:
      idx - The index of the recipient to return.
      Returns:
      The reipient at the given index.
    • getAllRecipients

      public List<Route> getAllRecipients()

      Returns all configured recipients for this hop.

      Returns:
      An unmodifiable list of recipients.
    • getMatchedRecipients

      public List<Route> getMatchedRecipients()

      Returns a list of all configured recipients whose first hop matches this.

      Returns:
      A modifiable list of recipients.
    • getSelectOnRetry

      public boolean getSelectOnRetry()

      Returns whether or not the policy is required to reselect if resending occurs.

      Returns:
      True to invoke RoutingPolicy.select(RoutingContext) on resend.
    • setSelectOnRetry

      public RoutingContext setSelectOnRetry(boolean selectOnRetry)

      Sets whether or not the policy is required to reselect if resending occurs.

      Parameters:
      selectOnRetry - The value to set.
      Returns:
      This, to allow chaining.
    • getRoute

      public Route getRoute()

      Returns the route that contains the routing policy that spawned this.

      Returns:
      The route.
    • getHop

      public Hop getHop()

      Returns the hop that contains the routing policy that spawned this.

      Returns:
      The hop.
    • getDirectiveIndex

      public int getDirectiveIndex()

      Returns the index of the hop directive that spawned this.

      Returns:
      The directive index.
    • getDirective

      public PolicyDirective getDirective()

      Returns the policy directive that spawned this.

      Returns:
      The directive object.
    • getHopPrefix

      public String getHopPrefix()

      Returns the part of the route string that precedes the active policy directive. This is the same as calling getHop().getPrefix(getDirectiveIndex()).

      Returns:
      The hop prefix.
    • getHopSuffix

      public String getHopSuffix()

      Returns the remainder of the route string immediately following the active policy directive. This is the same as calling getHop().getSuffix(getDirectiveIndex()).

      Returns:
      The hop suffix.
    • getContext

      public Object getContext()

      Returns the policy specific context object.

      Returns:
      The context.
    • setContext

      public RoutingContext setContext(Object context)

      Sets a policy specific context object that will be available at merge().

      Parameters:
      context - An arbitrary object.
      Returns:
      This, to allow chaining.
    • getMessage

      public Message getMessage()

      Returns the message being routed.

      Returns:
      The message.
    • trace

      public void trace(int level, String note)

      Adds a string to the trace of the message being routed.

      Parameters:
      level - The level of the trace note.
      note - The note to add.
    • shouldTrace

      public boolean shouldTrace(int level)
      Indicates if tracing is enabled at this level.
      Parameters:
      level - the level
      Returns:
      true if tracing is enabled at this level
    • hasReply

      public boolean hasReply()

      Returns whether or not a reply is available.

      Returns:
      True if a reply is set.
    • getReply

      public Reply getReply()

      Returns the reply generated by the associated routing policy.

      Returns:
      The reply.
    • setReply

      public RoutingContext setReply(Reply reply)

      Sets the reply generated by the associated routing policy.

      Parameters:
      reply - The reply to set.
      Returns:
      This, to allow chaining.
    • setError

      public RoutingContext setError(int code, String msg)

      This is a convenience method to call setError(Error).

      Parameters:
      code - The code of the error to set.
      msg - The message of the error to set.
      Returns:
      This, to allow chaining.
    • setError

      public RoutingContext setError(Error err)

      This is a convenience method to assign an EmptyReply containing a single error to this. This also fiddles with the trace object so that the error gets written to it.

      Parameters:
      err - The error to set.
      Returns:
      This, to allow chaining.
      See Also:
    • getMessageBus

      public MessageBus getMessageBus()

      Returns the message bus instance on which this is running.

      Returns:
      The message bus.
    • hasChildren

      public boolean hasChildren()

      Returns whether or not the owning routing node has any child nodes.

      Returns:
      True if there is at least one child.
    • getNumChildren

      public int getNumChildren()

      Returns the number of children the owning routing node has.

      Returns:
      The child count.
    • getChildIterator

      public RoutingNodeIterator getChildIterator()

      Returns an iterator for the child routing nodes of the owning node.

      Returns:
      The iterator.
    • addChild

      public void addChild(Route route)

      Adds a child routing context to this based on a given route. This is the typical entry point a policy will use to select recipients during a RoutingPolicy.select(RoutingContext) invocation.

      Parameters:
      route - The route to contain in the child context.
    • addChildren

      public void addChildren(List<Route> routes)

      This is a convenience method to more easily add a list of children to this. It will simply call the addChild(com.yahoo.messagebus.routing.Route) method for each element in the list.

      Parameters:
      routes - A list of routes to add as children.
    • getMirror

      public com.yahoo.jrt.slobrok.api.IMirror getMirror()

      Returns the local mirror of the system's name server.

      Returns:
      The mirror api.
    • addConsumableError

      public void addConsumableError(int errorCode)

      Adds the given error code to the list of codes that the associated routing policy may consume. This is used to verify whether or not a resolved routing tree can succeed if sent. Because verification is only done before sending, the error types that must be added here are only those that can be generated by message bus itself.

      Parameters:
      errorCode - The code that might be consumed.
      See Also:
      • RoutingNode.getUnconsumedErrors()
      • ErrorCode
    • isConsumableError

      public boolean isConsumableError(int errorCode)

      Returns whether or not the given error code may be consumed by the associated routing policy.

      Parameters:
      errorCode - The code to check.
      Returns:
      True if the code may be consumed.
      See Also: