SPL File ControlledChangeover.spl

com.ibm.streamsx.plumbing > switches 1.0.0 > com.ibm.streamsx.plumbing.sample.switches > ControlledChangeover.spl

Content

Operators

Composites

composite ControlledChangeoverSample

Sample showing use of com.ibm.streamsx.plumbing.switches::ControlledChangeover.

A ChangeoverDataFlow containing a ControlledChangeover that is controlled by a separate subgraph using the composite ControlFlow.

The ControlFlow composite randomly changes the state of the switch with tuples flowing through one output port about 30% of the time and the remainder the other output port.

The ControlledChangeover's state is changed by execution of the com.ibm.streamsx.plumbing.switches::setSwitchState(rstring,boolean) function. The setSwitchState is tied to the instance of ControlledChangeover by the switch's name: sampleSwitch.

When running the sample the tuple flow rate can be visualized using Streams console or Streams studio.

For example here is a view of ControlledChangeoverSample in Streams console. When running tuple flow will randomly switch between the streams in the red circle.



SPL Source Code


 public composite ControlledChangeoverSample
 {
 	graph
 		() as JCP = JobControlPlane()
 		{
 		}
 
 		// DataFlow with controlled switch
 		@spl_category(name = "data")
 		() as DF = ChangeoverDataFlow()
 		{
 		}
 
 		// Flow that controls DataFlow
 		// Note they are not connected using streams,
 		// only indirectly through the control mechanisms
 		// provided by JobControlPlane
 		@spl_note(id = "0", text =
 			"Flow that controls DataFlow by opening and closing the switch.")
 		@spl_category(name = "control")
 		() as CF = ControlFlow()
 		{
 		}
 
 }

   

composite ChangeoverDataFlow

The data flow that will demonstrate use of ControlledSwitch. A Beacon operator submits tuples around 100 per second through a com.ibm.streamsx.plumbing.switches::ControlledSwitch and out to a sink operator. Using Streams Studio or the Streams Console you can watch the rate of tuples into the sink operator change based upon the control signals from the separate ControlFlow composite.

SPL Source Code


 public composite ChangeoverDataFlow
 {
 	graph
 		stream<int64 a> Data = Beacon()
 		{
 			param
 				period : 0.01 ;
 		}
 
 		(stream<Data> MDClose; stream<Data> MDOpen) as MD = ControlledChangeover(Data)
 		{
 			param
 				name : "sampleSwitch" ;
                                 initialState : true;
 		}
 
 		() as ChangeoverClosed = Custom(MDClose) { }
 		() as ChangeoverOpened = Custom(MDOpen) { }
 
 }