Class RoutingContext
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 Summary
Modifier and TypeMethodDescriptionvoid
Adds a child routing context to this based on a given route.void
addChildren
(List<Route> routes) This is a convenience method to more easily add a list of children to this.void
addConsumableError
(int errorCode) Adds the given error code to the list of codes that the associated routing policy may consume.Returns all configured recipients for this hop.Returns an iterator for the child routing nodes of the owning node.Returns the policy specific context object.Returns the policy directive that spawned this.int
Returns the index of the hop directive that spawned this.getHop()
Returns the hop that contains the routing policy that spawned this.Returns the part of the route string that precedes the active policy directive.Returns the remainder of the route string immediately following the active policy directive.Returns a list of all configured recipients whose first hop matches this.Returns the message being routed.Returns the message bus instance on which this is running.com.yahoo.jrt.slobrok.api.IMirror
Returns the local mirror of the system's name server.int
Returns the number of children the owning routing node has.int
Returns the number of configured recipients for this hop.getRecipient
(int idx) Returns the configured recipient at the given index.getReply()
Returns the reply generated by the associated routing policy.getRoute()
Returns the route that contains the routing policy that spawned this.boolean
Returns whether or not the policy is required to reselect if resending occurs.boolean
Returns whether or not the owning routing node has any child nodes.boolean
Returns whether or not this hop has any configured recipients.boolean
hasReply()
Returns whether or not a reply is available.boolean
isConsumableError
(int errorCode) Returns whether or not the given error code may be consumed by the associated routing policy.setContext
(Object context) Sets a policy specific context object that will be available at merge().This is a convenience method to callsetError(Error)
.This is a convenience method to assign anEmptyReply
containing a single error to this.Sets the reply generated by the associated routing policy.setSelectOnRetry
(boolean selectOnRetry) Sets whether or not the policy is required to reselect if resending occurs.boolean
shouldTrace
(int level) Indicates if tracing is enabled at this level.toString()
void
Adds a string to the trace of the message being routed.
-
Method Details
-
toString
-
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
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
Returns all configured recipients for this hop.
- Returns:
- An unmodifiable list of recipients.
-
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
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
Returns the route that contains the routing policy that spawned this.
- Returns:
- The route.
-
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
Returns the policy directive that spawned this.
- Returns:
- The directive object.
-
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
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
Returns the policy specific context object.
- Returns:
- The context.
-
setContext
Sets a policy specific context object that will be available at merge().
- Parameters:
context
- An arbitrary object.- Returns:
- This, to allow chaining.
-
getMessage
Returns the message being routed.
- Returns:
- The message.
-
trace
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
Returns the reply generated by the associated routing policy.
- Returns:
- The reply.
-
setReply
Sets the reply generated by the associated routing policy.
- Parameters:
reply
- The reply to set.- Returns:
- This, to allow chaining.
-
setError
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
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
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
Returns an iterator for the child routing nodes of the owning node.
- Returns:
- The iterator.
-
addChild
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)
invokation.- Parameters:
route
- The route to contain in the child context.
-
addChildren
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:
-