-
-
Save nsdevaraj/a840cea1258e019176d8 to your computer and use it in GitHub Desktop.
The processor file should denote it's slave number
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
<?xml version="1.0" encoding="utf-8"?> | |
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" | |
xmlns:s="library://ns.adobe.com/flex/spark" | |
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" | |
addedToStage="init()" width="1" height="1"> | |
<fx:Script> | |
<![CDATA[ | |
private var sendConn:LocalConnection; | |
private var receiveConn:LocalConnection; | |
private var myCount:int; | |
private var channelName:String; | |
private const CHANNEL:String = 'channel'; | |
private const COMMONHANDLER:String = "lcHandler"; | |
private function init():void { | |
sendConn = new LocalConnection(); | |
receiveConn = new LocalConnection(); | |
receiveConn.allowDomain('*'); | |
receiveConn.allowInsecureDomain('*'); | |
receiveConn.client = this; | |
var myUrl:String = stage.loaderInfo.url; | |
var tmp:Array=myUrl.split("/"); | |
var myName:String=tmp[tmp.length-1].split(".swf")[0]; | |
myCount = myName.split("_")[1]; | |
try { | |
receiveConn.connect(CHANNEL+myCount); | |
} catch (error:ArgumentError) { | |
} | |
} | |
public function lcHandler(msg:Object):void { | |
var frontCount:int =(myCount+1); | |
var backCount:int =(myCount-1); | |
if(msg.isProcessed){ | |
//processed from successor processor | |
channelName= CHANNEL+backCount.toString(); | |
sendMessage(channelName,msg); | |
}else if(msg.destination == myCount){ | |
//processed by same processor | |
channelName= CHANNEL+backCount.toString(); | |
processMessage(msg); | |
}else{ | |
//to be processed by successor processor | |
channelName= CHANNEL+frontCount.toString(); | |
sendMessage(channelName,msg); | |
} | |
} | |
private function processMessage(msg:Object):void { | |
var obj:Object = msg.transmittedObj; | |
//processing Object | |
obj.c = obj.a + obj.b; | |
msg.processedAt = new Date().time; | |
msg.isProcessed =true; | |
sendMessage(channelName,msg); | |
} | |
private function sendMessage(channelName:String,msg:Object):void { | |
sendConn.send(channelName,COMMONHANDLER,msg); | |
} | |
]]> | |
</fx:Script> | |
</s:Application> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment