Created
May 25, 2011 13:17
-
-
Save ThomasBurleson/990951 to your computer and use it in GitHub Desktop.
Swiz EventChains with conditionals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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() ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How is this api chaining when the client cannot chain the api calls? The 'api chaining spec' allows for client to chain api calls within one request and on response by chaining the output from one api call to another.