SPL File exprshedder.spl

com.ibm.streamsx.plumbing > com.ibm.streamsx.plumbing 1.0.0 > com.ibm.streamsx.plumbing.shedders > exprshedder.spl

Content

Operators
  • ExpressionLoadShedder: Controllable load shedder that sheds (drops) tuples based upon evaluating an expression.
Functions

Composites

composite ExpressionLoadShedder(output Out; input In)

Controllable load shedder that sheds (drops) tuples based upon evaluating an expression. Tuple that are not shed are copied from the input port to the output port without modification. Punctuation marks are always forwarded from In to Out.

This operator creates a boolean control variable named name. Initially the variable is set to false which means no tuples will be shed. If the variable is changed to true then tuples will be shed. The selection of tuples to shed is defined by expr. If

The control variable may be shared across multiple invocations of ExpreessionLoadShedder, by invoking them with the same value for name. name is scoped to the job.

The shedding mode is changed by calling the function setExpressionShedderMode(rstring, boolean) from any operator in same job. Thus the logic that determines the shedding mode does not define a stream connection to this operator, instead the Job Control Plane, through the the control variable, provides the control mechanism. When the job is first submitted the shedding mode is set to false, so no tuples will be shed. Upon any failure, the shedding is maintained by the control variable.

Java primitive operators may also change the shedding mode by modifying the control variable using functionality in the com.ibm.streams.operator.control.variable package.

Multiple ExpressionLoadShedder operator may share the same control variable, by being invoked with the same value for the name parameter.

Any application that invokes this operator must include a single invocation of the spl.control::JobControlPlane operator.

Parameters

Input Ports

Output Ports

SPL Source Code


 public composite ExpressionLoadShedder(input In ; output Out)
 {
 	param
 		expression<rstring> $name ;
 		expression<boolean> $expr ;
 	graph
 
 		(stream<In> Out) as LoadShedder = Custom(In)
 		{
 			logic
 				state :
 				{
 				    rstring _name = $name;
 					boolean __unused = __initExpressionShedder(_name) ;
 					mutable boolean currentShed = false;
 				}
 
 				onTuple In :
 				{
 				    boolean shed = getExpressionShedderMode(_name);
 					if(!shed)
 					{
 						submit(In, Out) ;
 					}
 					else if (!($expr))
 					{
 					   submit(In, Out) ;
 					}
 					
 					if (shed != currentShed) {
 					    setCustomMetricValue("shedding", shed ? 1l : 0l) ;
 					    currentShed = shed;
 					}
 
 				}
 			}
 }

   

Functions

boolean registerExpressionShedder(rstring name)

Register that an operator invocation will call setExpressionShedderMode(rstring, boolean) or getExpressionShedderMode(rstring). A sharedboolean control variable is created with name name.

This function must be called in the logic state section of any operator invocation that calls setExpressionShedderMode or getExpressionShedderMode.

Parameters

Returns

SPL Source Code


 public stateful boolean registerExpressionShedder(rstring name)
 {
 	createBooleanControlVariable(name, true, false) ;
 	return true ;
 }

   

void setExpressionShedderMode(rstring name, boolean shed)

Set the shedding mode for ExpressionLoadShedder operator invocations using control variable name. If shed is false, then no tuples will be shed. If shed is true then any tuple that evaluates the operator invocation's expression to true will be shed

Any operator that invokes this must call registerExpressionShedder(rstring) in its logic state section, passing the same value for name. Any operator may invoke this method to control ExpressionLoadShedder operator invocations within the same job, that were invoked with their parameter name set to name.

Parameters

SPL Source Code


 public stateful void setExpressionShedderMode(rstring name, boolean shed)
 {
 	setBooleanControlVariable(name, shed) ;
 }

   

boolean getExpressionShedderMode(rstring name)

Get the shedding mode for ExpressionLoadShedder operator invocations using control variable name.

Any operator that invokes this must call registerExpressionShedder(rstring) in its logic state section, passing the same value for name.

Parameters

Returns

SPL Source Code


 public boolean getExpressionShedderMode(rstring name)
 {
 	return getBooleanControlVariable(name) ;
 }