Class 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 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 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 the discard() 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 parent SendProxy 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 call setError(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 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.
        See Also:
        setReply(Reply)
      • addError

        public void addError​(int code,
                             java.lang.String msg)
        This is a convenience method to call addError(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 calls setError(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's Trace is copied. This method does not call the parent node's notifyMerge().
        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 its Network.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 interface ReplyHandler
        Parameters:
        reply - The reply that arrived.