Package com.yahoo.messagebus.routing
Class RoutingNode
java.lang.Object
com.yahoo.messagebus.routing.RoutingNode
- All Implemented Interfaces:
ReplyHandler
This class represents a node in the routing tree that is created when a route is resolved. There will be one node per
modification of the route. For every
RoutingPolicy
there will be an instance of this that has its policy and
RoutingContext
member set. A policy is oblivious to this class, it can only access the context object.- Author:
- Simon Thoresen Hult
-
Constructor Summary
ConstructorDescriptionRoutingNode
(MessageBus mbus, Network net, Resender resender, ReplyHandler handler, Message msg) Constructs a new instance of this class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
This is a convenience method to calladdError(Error)
.void
This is a convenience method to add an error to this.void
discard()
Discards this routing node.Returns the message being routed.getRoute()
Returns the route object as it exists at this point of the tree.Returns the service address of this node.getTrace()
Returns the trace object for this node.void
handleReply
(Reply reply) Proxy through message bus in case it was destroyed in the meantime.void
send()
This is the single entry-point for sending a message along a route.void
This is a convenience method to callsetError(Error)
.void
This is a convenience method to assign anEmptyReply
containing a single error to this.void
Sets the reply of this routing node.void
setServiceAddress
(ServiceAddress serviceAddress) Sets the service address of this node.
-
Constructor Details
-
RoutingNode
public RoutingNode(MessageBus mbus, Network net, Resender resender, ReplyHandler handler, Message msg) Constructs a new instance of this class. This is the root node constructor, and will be used by the different sessions for sending messages. Note that thediscard()
functionality of this class is implemented so that it passes a null reply to the handler to notify the discard.- Parameters:
mbus
- The message bus on which we are running.net
- The network layer we are to transmit through.resender
- The resender to schedule with.handler
- The handler to receive the final reply.msg
- The message being sent.
-
-
Method Details
-
discard
public void discard()Discards this routing node. Invoking this will notify the parentSendProxy
to ensure that the corresponding message is discarded. This is a required step to ensure safe shutdown if you need to destroy a message bus instance while there are still routing nodes alive in your application. -
send
public void send()This is the single entry-point for sending a message along a route. This can only be invoked on the root node of a routing tree. It runs all the necessary selection, verification and transmission logic. Once this has been called, it guarantees that a reply is returned to the registered reply handler. -
setError
This is a convenience method to callsetError(Error)
.- Parameters:
code
- The code of the error to set.msg
- The message of the error to set.
-
setError
This is a convenience method to assign anEmptyReply
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.- See Also:
-
addError
This is a convenience method to calladdError(Error)
.- Parameters:
code
- The code of the error to add.msg
- The message of the error to add.
-
addError
This is a convenience method to add an error to this. If a reply has already been set, this method will add the error to it. If no reply is set, this method callssetError(Error)
. This method also fiddles with the trace object so that the error gets written to it.- Parameters:
err
- The error to add.
-
getMessage
Returns the message being routed. You should NEVER modify a message that is retrieved from a routing node or context, as the result of doing so is undefined.- Returns:
- The message being routed.
-
getTrace
Returns the trace object for this node. Each node has a separate trace object so that merging can be done correctly.- Returns:
- The trace object.
-
getRoute
Returns the route object as it exists at this point of the tree.- Returns:
- The route at this point.
-
setReply
Sets the reply of this routing node. This method also updates the internal state of this node; it is tagged for resending if the reply has only transient errors, and the reply'sTrace
is copied. This method does not call the parent node'snotifyMerge()
.- Parameters:
reply
- The reply to set.
-
getServiceAddress
Returns the service address of this node. This is attached by the network layer, and should only ever be present in leaf nodes.- Returns:
- The recipient address.
-
setServiceAddress
Sets the service address of this node. This is called by the network layer as this calls itsNetwork.allocServiceAddress(RoutingNode)
method.- Parameters:
serviceAddress
- The recipient address.
-
handleReply
Proxy through message bus in case it was destroyed in the meantime.- Specified by:
handleReply
in interfaceReplyHandler
- Parameters:
reply
- The reply that arrived.
-