public class RouterNode extends Node
This node can be used as simple but powerful way of dynamically routing or filtering
Stream
s on server side to the different successor Node
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'
true
for every stream with MIME type "application/pdf"#streamNumber == 1
true
only for the 2nd stream (counting starts at
zero!)true
true
for any stream. Useful as a fallback rule for the last
node in the evaluation chain if no previous rule matched.STREAM_DESCRIPTOR_PATTERN
and STREAM_NUMBER_PATTERN
.
Rules and successor nodes stick together in the following way. If the nth rule
evaluates to true
:
successor node
.routing policy
is set to
RouterNode.RoutingPolicy.EVERY_MATCH
.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
.
Modifier and Type | Class and Description |
---|---|
static class |
RouterNode.RoutingPolicy
Routing policy if several rules evaluate to
true for a given stream. |
Node.Cardinality
Modifier and Type | Field and Description |
---|---|
static String |
STREAM_DESCRIPTOR_PATTERN
Pattern to access the
StreamDescriptor in the routing
rules . |
static String |
STREAM_NUMBER_PATTERN
Pattern to access the stream number in the
routing rules .
Caveat: Counting is zero-based! |
Constructor and Description |
---|
RouterNode() |
Modifier and Type | Method and 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 associated
NodeWorker full qualified class's
name. |
void |
setRoutingPolicy(RouterNode.RoutingPolicy routingPolicy)
Set the routing policy if several rules evaluate to
true . |
void |
setRoutingRules(List<String> routingRules)
Set the routing rules in the syntax of the Spring Expression Language.
|
protected void |
validateConfiguration() |
addTransportReceiver, appendSuccessor, apply, equals, getInputCardinality, getJob, getPredecessors, getSubsidiaryNodes, getSuccessors, getTransportSender, getUUID, hashCode, initialize, prependPredecessor, remove
public static final String STREAM_DESCRIPTOR_PATTERN
StreamDescriptor
in the routing
rules
.public static final String STREAM_NUMBER_PATTERN
routing rules
.
Caveat: Counting is zero-based!public void setRoutingPolicy(RouterNode.RoutingPolicy routingPolicy)
true
.routingPolicy
- only the first match is considered iff value is set to
RouterNode.RoutingPolicy.EVERY_MATCH
(default value)public RouterNode.RoutingPolicy getRoutingPolicy()
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.
routingRules
- The rules that are parsed and evaluated on server sideNode.appendSuccessor(Node)
public Node.Cardinality getOutputCardinality()
Node
getOutputCardinality
in class Node
protected void validateConfiguration() throws ConfigurationException
validateConfiguration
in class Node
ConfigurationException
public String getWorkerClassName()
Node
Return the node's associated
NodeWorker
full qualified class's
name. By default, the worker class name is
This behavior can be overridden in concrete subclasses.
getWorkerClassName
in class Node
Copyright © 2017 levigo holding gmbh. All rights reserved.