Package com.yahoo.messagebus.routing
Class RoutingNode
- java.lang.Object
-
- com.yahoo.messagebus.routing.RoutingNode
-
- All Implemented Interfaces:
ReplyHandler
public class RoutingNode extends java.lang.Object implements 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 everyRoutingPolicy
there will be an instance of this that has its policy andRoutingContext
member set. A policy is oblivious to this class, it can only access the context object.- Author:
- Simon Thoresen Hult
-
-
Constructor Summary
Constructors Constructor Description RoutingNode(MessageBus mbus, Network net, Resender resender, ReplyHandler handler, Message msg)
Constructs a new instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addError(int code, java.lang.String msg)
This is a convenience method to calladdError(Error)
.void
addError(Error err)
This is a convenience method to add an error to this.void
discard()
Discards this routing node.Message
getMessage()
Returns the message being routed.Route
getRoute()
Returns the route object as it exists at this point of the tree.ServiceAddress
getServiceAddress()
Returns the service address of this node.Trace
getTrace()
Returns the trace object for this node.void
handleReply(Reply reply)
This function is called when a reply arrives.void
send()
This is the single entry-point for sending a message along a route.void
setError(int code, java.lang.String msg)
This is a convenience method to callsetError(Error)
.void
setError(Error err)
This is a convenience method to assign anEmptyReply
containing a single error to this.void
setReply(Reply reply)
Sets the reply of this routing node.void
setServiceAddress(ServiceAddress serviceAddress)
Sets the service address of this node.
-
-
-
Constructor Detail
-
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 Detail
-
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
public void setError(int code, java.lang.String msg)
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
public void setError(Error err)
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:
setReply(Reply)
-
addError
public void addError(int code, java.lang.String msg)
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
public void addError(Error err)
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
public Message 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
public Trace 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
public Route getRoute()
Returns the route object as it exists at this point of the tree.- Returns:
- The route at this point.
-
setReply
public void setReply(Reply reply)
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
public ServiceAddress 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
public void setServiceAddress(ServiceAddress serviceAddress)
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
public void handleReply(Reply reply)
Description copied from interface:ReplyHandler
This function is called when a reply arrives.- Specified by:
handleReply
in interfaceReplyHandler
- Parameters:
reply
- The reply that arrived.
-
-