Class RouterNode
- java.lang.Object
-
- com.levigo.jadice.server.internal.NodeInternal
-
- com.levigo.jadice.server.Node
-
- com.levigo.jadice.server.nodes.RouterNode
-
public class RouterNode extends Node
This node can be used as simple but powerful way of dynamically routing or filteringStreams on server side to the different successorNodes 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
StreamDescriptoror 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
truefor every stream with MIME type "application/pdf" #streamNumber == 1- Evaluates to
trueonly for the 2nd stream (counting starts at zero!) true- Always evaluates to
truefor 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_PATTERNandSTREAM_NUMBER_PATTERN.Rules and successor nodes stick together in the following way. If the nth rule evaluates to
true:- the incoming stream will be forwarded to the nth
successor node. - the rules n+1…N will only be evaluated if the
routing policyis set toRouterNode.RoutingPolicy.EVERY_MATCH.
Default value of the routing policy is
RouterNode.RoutingPolicy.FIRST_MATCHso that the incoming stream will only be forwarded to the first node of which the corresponding rule evaluates totrue.- Since:
- jadice server 4.3.1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRouterNode.RoutingPolicyRouting policy if several rules evaluate totruefor a given stream.-
Nested classes/interfaces inherited from class com.levigo.jadice.server.Node
Node.Cardinality
-
-
Field Summary
Fields Modifier and Type Field Description static StringSTREAM_DESCRIPTOR_PATTERNPattern to access theStreamDescriptorin therouting rules.static StringSTREAM_NUMBER_PATTERNPattern to access the stream number in therouting rules.
Caveat: Counting is zero-based!
-
Constructor Summary
Constructors Constructor Description RouterNode()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Node.CardinalitygetOutputCardinality()Return the output cardinality of this node, i.e.RouterNode.RoutingPolicygetRoutingPolicy()List<String>getRoutingRules()StringgetWorkerClassName()Return the node's associatedcom.levigo.jadice.server.core.NodeWorkerfull qualified class's name.voidsetRoutingPolicy(RouterNode.RoutingPolicy routingPolicy)Set the routing policy if several rules evaluate totrue.voidsetRoutingRules(List<String> routingRules)Set the routing rules in the syntax of the Spring Expression Language.protected voidvalidateConfiguration()-
Methods inherited from class com.levigo.jadice.server.Node
addTransportReceiver, appendSuccessor, apply, equals, getInputCardinality, getJob, getPredecessors, getSubsidiaryNodes, getSuccessors, getTransportSender, getUUID, hashCode, initialize, prependPredecessor, remove
-
-
-
-
Field Detail
-
STREAM_DESCRIPTOR_PATTERN
public static final String STREAM_DESCRIPTOR_PATTERN
Pattern to access theStreamDescriptorin therouting rules.- See Also:
- Constant Field Values
-
STREAM_NUMBER_PATTERN
public static final String STREAM_NUMBER_PATTERN
Pattern to access the stream number in therouting rules.
Caveat: Counting is zero-based!- See Also:
- Constant Field Values
-
-
Method Detail
-
setRoutingPolicy
public void setRoutingPolicy(RouterNode.RoutingPolicy routingPolicy)
Set the routing policy if several rules evaluate totrue.- Parameters:
routingPolicy- only the first match is considered iff value is set toRouterNode.RoutingPolicy.EVERY_MATCH(default value)
-
getRoutingPolicy
public RouterNode.RoutingPolicy getRoutingPolicy()
-
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)
-
getOutputCardinality
public Node.Cardinality getOutputCardinality()
Description copied from class:NodeReturn 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:
getOutputCardinalityin classNode- Returns:
- output cardinality
-
validateConfiguration
protected void validateConfiguration() throws ConfigurationException- Overrides:
validateConfigurationin classNode- Throws:
ConfigurationException
-
getWorkerClassName
public String getWorkerClassName()
Description copied from class:NodeReturn the node's associatedcom.levigo.jadice.server.core.NodeWorkerfull 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.
This behavior can be overridden in concrete subclasses.
- Overrides:
getWorkerClassNamein classNode- Returns:
- the full qualified class name of the worker of this node.
-
-