ThomasBurleson
5/25/2011 - 1:17 PM

Swiz EventChains with conditionals

Swiz EventChains with conditionals

/**
* Here is the same method; but it now uses the static 
* EventChain::createEventChain() to do the dirty work...
* 
*/
[EventHandler(event="DeviceEvent.LOAD_SUMMARY",properties="device,filters,forceLoad")]
public function workflow_loadDeviceSummaries(device:DeviceVO=null, filterIDs:Array=null, force:Boolean=false):IAsynchronousOperation
{
  logger.debug( "workflow_loadDeviceSummaries( )" );

  device ||= model.selected;

    if (device == null) return null;

  var evTests : Event = new DeviceEvent(DeviceEvent.LOAD_TESTS, device, filterIDs);
  var evSnaps : Event = new DeviceEvent(DeviceEvent.LOAD_SNAPSHOTS, device );
  var events  : Array = [ ];

	  if ( force || !device.hasTests )                              events.push( evTests );
	  if ( force || !device.hasSeverities || !device.hasSnapshots ) events.push( evSnaps );

  // Use the static EventChain::createEventChain() to do the dirty work...
 
  var chain : IChain = EventChain.createEventChain(events, dispatcher, ChainType.PARALLEL);

  return new AsynchronousChainOperation( chain.start() );
}
[EventHandler(event="DeviceEvent.LOAD_SUMMARY",properties="device,filters,forceLoad")]
/**
 *  Here is an example of Parallel chaining. Developers should not that the workflow() method returns
 *  IAsynchronousOperation to allow workflow() to be itself chained with other eventHandlers.
 *  
 *    - DeviceEvent extends AsynchronousEvent. 
 *    - FunctionChainStep is also available
 *  
 *  Here we get Device Snapshot information (includes upTimes and durationInState)
 */
public function workflow_loadDeviceSummaries(device:DeviceVO=null, filterIDs:Array=null, force:Boolean=false):IAsynchronousOperation
{
	logger.debug( "workflow_loadDeviceSummaries( )" );
	
	device ||= model.selected;

	  if (device == null) return null;
	
	var evTests   : Event   = new DeviceEvent(DeviceEvent.LOAD_TESTS,  	   device, filterIDs);
	var evSnaps   : Event   = new DeviceEvent(DeviceEvent.LOAD_SNAPSHOTS,  device );
	
	var chain     : IChain  = new EventChain(dispatcher, ChainType.PARALLEL);
	
	if ( force || !device.hasTests )                               chain.addStep( new EventChainStep(evTests) );		
        if ( force || !device.hasSeverities || !device.hasSnapshots )  chain.addStep( new EventChainStep(evSnaps) );	

	chain.start();
	
	return new AsynchronousChainOperation(chain);
}