SPL File controlledswitch.spl

com.ibm.streamsx.plumbing > com.ibm.streamsx.plumbing 1.0.0 > com.ibm.streamsx.plumbing.switches > controlledswitch.spl

Content

Operators
Functions

Composites

composite ControlledSwitch(output OUT; input IN)

Controlled switch.

A controlled version of the SPL Standard toolkit Switch operator. When the switch is closed (state is true) tuples on its input port flow through to its output port unchanged.

When the switch is open (state is false) tuples on its input port are blocked from flowing. Blocked tuples remain on the stream and will be submitted to the output stream once the switch is closed. Opening the switch can result in upstream processing being halted due to back pressure.

Operator invocations in the same job register an interest in controlling this switch by calling registerSwitch(rstring, boolean) passing the name of this switch. Then the state of this switch is changed by calling setSwitchState(rstring, boolean).

A boolean control variable named name is created in the Job Control Plane which provides notifications and operations to control if the switch is open or closed.

Multiple invocations of ControlledSwitch can share the same name and will then be controlled by the same control variable. Any call to setSwitchState(rstring, boolean) sets the state of all switches with the same name.

In the case of failure the state of the switch is retained by the Job Control Plane.

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 ControlledSwitch(input IN; output OUT)
 {
    param
         expression<rstring> $name;
         expression<boolean> $initialState : false;
     graph
 
         stream<IN> OUT = Switch(IN ; SwitchControl)
         {
             logic state: {boolean _dummy = __initSwitch($name, $initialState);}
             param
                 status : getSwitchState($name) ;
                 initialStatus: getSwitchState($name);
             config placement: partitionColocation(getThisCompositeInstanceName());
         }
         // this issues an attribute change notification which is then
         // sent to the Switch's control port. This will then call
         // getSwitchState() to set the switch to its correct state.
         stream<MBeanNotificationBase> SwitchControl = ControlVariableChange()
         {
             param
                 name : $name;
             config placement: partitionColocation(getThisCompositeInstanceName());
         }
 }

   

Functions

boolean registerSwitch(rstring name, boolean initialState)

Register that an operator invocation will call setSwitchState(rstring, boolean) or getSwitchState(rstring). A shared boolean control variable is created with name name.

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

Parameters

Returns

SPL Source Code


 public stateful boolean registerSwitch(rstring name, boolean initialState)
 {
 	return createBooleanControlVariable(name, true, initialState) ;
 }

   

void setSwitchState(rstring name, boolean on)

Set the state of switches with control variable name. If on is true then the switch is closed. If on is false then the switch is open.

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

Any operator may invoke this method to control ControlledSwitch operator invocations within the same job, that were invoked with their parameter name set to name.

Parameters

SPL Source Code


 public stateful void setSwitchState(rstring name, boolean  on)
 {
 	setBooleanControlVariable(name, on) ;
 }

   

boolean getSwitchState(rstring name)

Get the state of a switch with control variable name.

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

Parameters

Returns

SPL Source Code


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