Class RouterNode


  • public class RouterNode
    extends Node
    This node can be used as simple but powerful way of dynamically routing or filtering Streams on server side to the different successor Nodes depending on the streams' meta data. The decision which way a stream goes is based on rules in the Spring Expression Language (SpEL) syntax. These outgoing streams and their stream descriptors are multiplexed (if necessary) but not modified in any other way.

    The base of this rules can be the StreamDescriptor or what number of stream it is. These rules must be a Boolean expression. Due to the SpEL it is not necessary to write those expression as java code, it also supports property access using standard 'dot' notation.

    Examples

    #streamDescriptor.getMimeType().equals("application/pdf") or in 'dot' notation #streamDescriptor.mimeType == 'application/pdf'
    Evaluates to true for every stream with MIME type "application/pdf"
    #streamNumber == 1
    Evaluates to true only for the 2nd stream (counting starts at zero!)
    true
    Always evaluates to true for any stream. Useful as a fallback rule for the last node in the evaluation chain if no previous rule matched.

    The variables to access the StreamDescriptor or the stream number are also provided as constants STREAM_DESCRIPTOR_PATTERN and STREAM_NUMBER_PATTERN.

    Rules and successor nodes stick together in the following way. If the nth rule evaluates to true:

    1. the incoming stream will be forwarded to the nth successor node.
    2. the rules n+1…N will only be evaluated if the routing policy is set to RouterNode.RoutingPolicy.EVERY_MATCH.

    Default value of the routing policy is RouterNode.RoutingPolicy.FIRST_MATCH so that the incoming stream will only be forwarded to the first node of which the corresponding rule evaluates to true.

    Since:
    jadice server 4.3.1.0
    • Constructor Detail

      • RouterNode

        public RouterNode()
    • Method Detail

      • setRoutingRules

        public void setRoutingRules​(List<String> routingRules)
        Set the routing rules in the syntax of the Spring Expression Language.

        Caveat: The number of rules must correspond to the number of successor nodes.

        Parameters:
        routingRules - The rules that are parsed and evaluated on server side
        See Also:
        Node.appendSuccessor(Node)
      • getRoutingRules

        public List<String> getRoutingRules()
      • getOutputCardinality

        public Node.Cardinality getOutputCardinality()
        Description copied from class: Node
        Return the output cardinality of this node, i.e. how many bundles (not streams!) it expects to produce. By default, nodes are "pipe-style", i.e. one input, one output.
        Overrides:
        getOutputCardinality in class Node
        Returns:
        output cardinality
      • getWorkerClassName

        public String getWorkerClassName()
        Description copied from class: Node
        Return the node's associated com.levigo.jadice.server.core.NodeWorker full qualified class's name. By default, the worker class name is
        • The same as the node name with the trailing "Node" replaced by "Worker" if the node name ends in "Node"
        • The node class name with an appended "Worker" otherwise.
        The package name of the worker class is the name of the Node's package with an appended ".worker".

        This behavior can be overridden in concrete subclasses.

        Overrides:
        getWorkerClassName in class Node
        Returns:
        the full qualified class name of the worker of this node.