Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
package com.czw.apps.shell.view{ import com.czw.apps.common.HelloMsg; import com.czw.apps.common.PipeNames; import com.czw.apps.shell.ShellFacade; import org.puremvc.as3.multicore.interfaces.INotification; import org.puremvc.as3.multicore.patterns.facade.Facade; import org.puremvc.as3.multicore.utilities.pipes.interfaces.IPipeAware; import org.puremvc.as3.multicore.utilities.pipes.interfaces.IPipeMessage; import org.puremvc.as3.multicore.utilities.pipes.messages.Message; import org.puremvc.as3.multicore.utilities.pipes.plumbing.Junction; import org.puremvc.as3.multicore.utilities.pipes.plumbing.JunctionMediator; import org.puremvc.as3.multicore.utilities.pipes.plumbing.Pipe; import org.puremvc.as3.multicore.utilities.pipes.plumbing.TeeMerge; import org.puremvc.as3.multicore.utilities.pipes.plumbing.TeeSplit; public class ShellJunctionMediator extends JunctionMediator { public static const NAME:String="ShellJunctionMediator"; private var outMap:Object={}; public function ShellJunctionMediator() { super(NAME, new Junction()); } override public function onRegister():void { junction.registerPipe(PipeNames.STDIN,Junction.INPUT,new TeeMerge()); junction.registerPipe(PipeNames.STDOUT,Junction.OUTPUT,new TeeSplit()); junction.addPipeListener(PipeNames.STDIN,this,handlePipeMessage); } override public function listNotificationInterests():Array { var Interests:Array=super.listNotificationInterests(); Interests.push(ShellFacade.CONNECT_MODULE_TO_SHELL); Interests.push(ShellFacade.DISCONNECT_MODULE_TO_SHELL); Interests.push(ShellFacade.SEND_MSG_TO_MODULE); return Interests; } override public function handleNotification(note:INotification):void { var moduleID:String; var moduleFacade:IPipeAware; switch (note.getName()) { case ShellFacade.CONNECT_MODULE_TO_SHELL: moduleID=note.getBody() as String; moduleFacade=Facade.getInstance(moduleID) as IPipeAware; // module -> shell var moduleToShell:Pipe=new Pipe(); //moduleFacade.acceptOutputPipe(PipeNames.MODULE_TO_SHELL_PIPE, moduleToShell); moduleFacade.acceptOutputPipe(PipeNames.ANY_MODULE_TO_SHELL,moduleToShell); var shellInFitting:TeeMerge=junction.retrievePipe(PipeNames.STDIN) as TeeMerge; shellInFitting.connect(moduleToShell); // shell -> module var shellToModule:Pipe=new Pipe(); moduleFacade.acceptInputPipe(PipeNames.STDIN, shellToModule); var shellOutFitting:TeeSplit=junction.retrievePipe(PipeNames.STDOUT) as TeeSplit; shellOutFitting.connect(shellToModule); outMap[moduleID]=shellOutFitting; break; case ShellFacade.DISCONNECT_MODULE_TO_SHELL: break; case ShellFacade.SEND_MSG_TO_MODULE: //trace(note.getBody() as String); var helloMsg:HelloMsg=new HelloMsg("shell",note.getBody() as String); junction.sendMessage(PipeNames.STDOUT,helloMsg); break; default: super.handleNotification(note); } } override public function handlePipeMessage(message:IPipeMessage):void { //trace("kkkk"); trace(Message(message).getBody() as String); } }}
package com.czw.apps.modules.hello.view{ import com.czw.apps.common.HelloMsg; import com.czw.apps.common.PipeNames; import com.czw.apps.modules.hello.HelloFacade; import org.puremvc.as3.multicore.interfaces.INotification; import org.puremvc.as3.multicore.utilities.pipes.messages.Message; import org.puremvc.as3.multicore.utilities.pipes.interfaces.IPipeMessage; import org.puremvc.as3.multicore.utilities.pipes.plumbing.Junction; import org.puremvc.as3.multicore.utilities.pipes.plumbing.JunctionMediator; public class HelloModuleJunctionMediator extends JunctionMediator { public static const NAME:String="HelloModuleJunctionMediator"; public function HelloModuleJunctionMediator() { super(NAME, new Junction()); } override public function onRegister():void { } override public function listNotificationInterests():Array { var Interests:Array=super.listNotificationInterests(); Interests.push(HelloFacade.SEND_MSG_TO_SHELL); return Interests; } override public function handleNotification(note:INotification):void { switch (note.getName()) { case HelloFacade.SEND_MSG_TO_SHELL: var sendId:String=this.multitonKey; var body:String=note.getBody() as String; var helloMsg:HelloMsg=new HelloMsg(sendId, body); junction.sendMessage(PipeNames.ANY_MODULE_TO_SHELL, helloMsg); break; default: super.handleNotification(note); } } override public function handlePipeMessage(message:IPipeMessage):void { this.sendNotification(HelloFacade.SENS_MSG_TO_LABLE, Message(message).getBody() as String); } }}
package com.czw.apps.modules.hello{ import com.czw.apps.modules.hello.controller.StartupCommand; import com.czw.apps.modules.hello.controller.SendMsgToShellCommand; import com.czw.apps.modules.hello.view.components.Hello; import org.puremvc.as3.multicore.patterns.facade.Facade; import org.puremvc.as3.multicore.utilities.pipes.interfaces.IPipeAware; import org.puremvc.as3.multicore.utilities.pipes.interfaces.IPipeFitting; import org.puremvc.as3.multicore.utilities.pipes.plumbing.JunctionMediator; public class HelloFacade extends Facade implements IPipeAware { public static const STARTUP:String="startup"; public static const SEND_MSG_TO_SHELL:String="sendMsgToShell"; public static const SENS_MSG_TO_LABLE:String="snedMsgToLable"; public function HelloFacade(key:String) { super(key); } public static function getInstance(key:String):HelloFacade { if (instanceMap[key] == null) { instanceMap[key]=new HelloFacade(key); } return instanceMap[key] as HelloFacade; } override protected function initializeController():void { super.initializeController(); this.registerCommand(STARTUP, StartupCommand); //this.registerCommand(SEND_MSG_TO_SHELL, SendMsgToShellCommand); } public function startup(app:Hello):void { this.sendNotification(STARTUP, app); } public function acceptInputPipe(name:String, pipe:IPipeFitting):void { sendNotification(JunctionMediator.ACCEPT_INPUT_PIPE, pipe, name); } public function acceptOutputPipe(name:String, pipe:IPipeFitting):void { sendNotification(JunctionMediator.ACCEPT_OUTPUT_PIPE, pipe, name); } }}
<?xml version="1.0" encoding="utf-8"?><mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" layout="vertical" width="100%" height="100%" implements="com.czw.apps.common.czwIModule"> <fx:Script> <![CDATA[ import com.czw.apps.common.czwIModule; import com.czw.apps.modules.hello.HelloFacade; import org.puremvc.as3.multicore.interfaces.IFacade; import org.puremvc.as3.multicore.patterns.facade.Facade; public static const NAME:String="Hello"; private static var serial:Number=0; public static const SENDMSG:String="sendMessage"; var facade:IFacade; var moduleID:String=Hello.getNextID(); public function getID():String { return moduleID; } public function setup():void { facade=HelloFacade.getInstance(moduleID); HelloFacade(facade).startup(this); } public function treadown():void { } private static function getNextID():String { return NAME + "/" + serial++; } private function sendEvent(name:String):void { switch (name) { case SENDMSG: this.dispatchEvent(new Event(SENDMSG, true)); break; } } ]]> </fx:Script> <fx:Declarations> </fx:Declarations> <s:TextInput id="sMsg"/> <s:Label id="rMsg" color="#FB0404"/> <s:Button label="Send Msg" click="sendEvent(SENDMSG)"/> <s:Label text="{getID()}"/></mx:Module>
var moduleFacade:IPipeAware = Facade.getInstance( moduleID ) as IPipeAware;var moduleToShell:Pipe = new Pipe();moduleFacade.acceptOutputPipe(...);
var moduleToShell:Pipe=new Pipe();moduleFacade.acceptOutputPipe(PipeNames.ANY_MODULE_TO_SHELL,moduleToShell);var shellInFitting:TeeMerge=junction.retrievePipe(PipeNames.STDIN) as TeeMerge;shellInFitting.connect(moduleToShell); ///---> Return false here and it must not
override public function onRegister():void { //We need the color of the current module to setup the color filter. var helloModuleMediator:HelloModuleMediator = facade.retrieveMediator( HelloModuleMediator.NAME ) as HelloModuleMediator; var color:String = helloModuleMediator.getModuleColor(); /* * Setup for the input pipe tee merge. All input pipes registered * with as PipeConstants.STDIN will be merged on it. */ var filter:Filter = new Filter( HelloModuleColorFilterMessage.COLOR_FILTER_NAME ); trace("filter"+String(filter)); filter.setFilter( HelloModuleColorFilterMessage.filterMessageByColor as Function ); filter.setParams( { color:color }); filter.connect(new PipeListener(this,handlePipeMessage)); var teeMerge:TeeMerge = new TeeMerge(); teeMerge.connect(filter); junction.registerPipe( PipeNames.STDIN, Junction.INPUT, teeMerge ); var teeSplit:TeeSplit = new TeeSplit(); junction.registerPipe( PipeNames.HELLO_OUT_TO_HELLO, Junction.OUTPUT, teeSplit ); }