Operator Switch

Primitive operator image not displayed. Problem loading file: ../../image/tk$spl/op$spl.utility$Switch.svg

The Switch operator is used to temporarily stop tuples from flowing. The switch is either open (tuples are blocked) or closed (tuples are flowing).

The Switch operator can be used to hold tuples until a downstream operator is ready to process them.

Checkpointed data

When the Switch operator is checkpointed, logic state variables (if present) are saved in checkpoint.

Behavior in a consistent region

The Switch operator is not supported in a consistent region.

Checkpointing behavior in an autonomous region

When the Switch operator is in an autonomous region and configured with config checkpoint : periodic(T) clause, a background thread in SPL Runtime checkpoints the operator every T seconds, and such periodic checkpointing activity is asynchronous to tuple processing. Upon restart, the operator restores its state from the last checkpoint.

When the Switch operator is in an autonomous region and configured with config checkpoint : operatorDriven clause, no checkpoint is taken at runtime. Upon restart, the operator restores to its initial state.

Such checkpointing behavior is subject to change in the future.

Examples

This example uses the Switch operator.


composite Main {                                                                                   
  graph                                                                                            
                                                                                               
    // SPL Operator used to read initialization data                                               
    stream<MappingData> M = FileSource() {param file : "initData";}                                
                                                                                               
    // Source of tuples to be processed                                                            
    stream<Data> = .....                                                                           
                                                                                               
    // Switch to hold up Data tuples until downstream operator is initialized                      
    // initialStatus defaults to false (Switch is open/blocked)                                    
    stream<Data> SData = Switch (Data; Control) {                                                  
        param status : true;     
        // any Control tuple causes the switch to allow tuples to flow
    }                                                                                              
                                                                                               
    (stream<ProcessedData> PData; 
     stream<int32 dummy> Control) = Custom (SData; M) {               
        logic state : { mutable map<rstring,rstring> dataMap; }                                    
            // use the initialization data to set up data structures                               
            onTuple M: insertM (dataMap, M.key, M.value);                                          
            // let the SData tuples start flowing when we hit the end of the initialization data   
            onPunct M: submit ({ dummy = 1}, Control);                                             
            onTuple SData: { /* process input using initialized dataMap */                         
                submit ({ m = dataMap[SData.k]}, PData);                                           
                           }                                                                       
    }                                                                                              
}                         

Summary

Ports
This operator has 2 input ports and 1 output port.
Windowing
This operator does not accept any windowing configurations.
Parameters
This operator supports 2 parameters.

Required: status

Optional: initialStatus

Metrics
This operator does not report any metrics.

Properties

Implementation
C++
Threading
Always - Operator always provides a single threaded execution context.

Input Ports

Ports (0)

The Switch operator has two input ports. The first input port is the data port and holds the tuples to be switched.

Properties

Ports (1)

The second input port is the control port and is used to open and close the switch.

Properties

Output Ports

Assignments
This operator does not allow assignments to output attributes.
Ports (0)

The Switch operator is configurable with a single output port. The schema of the output port must match that of the first input port.

Properties

Parameters

This operator supports 2 parameters.

Required: status

Optional: initialStatus

initialStatus

Specifies whether the operator starts in the open or closed. If you do not specify this parameter, the default value is false, which means tuples are blocked.

Properties

status

Specifies whether the switch is open or closed. The expression is evaluated each time that a tuple arrives on the second (control) port. If the expression has a value of true, the switch allows tuples to flow through. If the expression has a value of false, the switch prevents tuples from flowing.

Properties

Code Templates

Switch

stream<${dataStream}> ${outputStream} = Switch(${dataStream};${controlStream})   {
            param
                state: ${state};
        }