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 filteringStream
s on server side to the different successorNode
s 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
andSTREAM_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 policy
is set toRouterNode.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 totrue
.- Since:
- jadice server 4.3.1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RouterNode.RoutingPolicy
Routing policy if several rules evaluate totrue
for 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 String
STREAM_DESCRIPTOR_PATTERN
Pattern to access theStreamDescriptor
in therouting rules
.static String
STREAM_NUMBER_PATTERN
Pattern 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.Cardinality
getOutputCardinality()
Return the output cardinality of this node, i.e.RouterNode.RoutingPolicy
getRoutingPolicy()
List<String>
getRoutingRules()
String
getWorkerClassName()
Return the node's associatedcom.levigo.jadice.server.core.NodeWorker
full qualified class's name.void
setRoutingPolicy(RouterNode.RoutingPolicy routingPolicy)
Set the routing policy if several rules evaluate totrue
.void
setRoutingRules(List<String> routingRules)
Set the routing rules in the syntax of the Spring Expression Language.protected void
validateConfiguration()
-
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 theStreamDescriptor
in 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: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 classNode
- Returns:
- output cardinality
-
validateConfiguration
protected void validateConfiguration() throws ConfigurationException
- Overrides:
validateConfiguration
in classNode
- Throws:
ConfigurationException
-
getWorkerClassName
public String getWorkerClassName()
Description copied from class:Node
Return the node's associatedcom.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.
This behavior can be overridden in concrete subclasses.
- Overrides:
getWorkerClassName
in classNode
- Returns:
- the full qualified class name of the worker of this node.
-
-