Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: why module don't connect to shell?  (Read 12405 times)
czw888
Newbie
*
Posts: 7


View Profile Email
« on: May 26, 2010, 09:01:16 »

 I have a difficult to use puremvc multicore core now.blow is my code:
 
1.ShellJunctionMediator
:
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);

}
}
}

2. HelloModuleJunctionMediator
:
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);
}
}
}

3.HelloFacade
:
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);

}


}
}

4.Hello.mxml
:
<?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>

  why i can from module send message to shell,but can not from shell send message to module ?Do you have the error before?Please help to me!!!!
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: May 26, 2010, 04:57:34 »

Don't try to retrieve other facades and work with them. The Module Facade isn't supposed to be PipeAware, the Module itself is. Have a look at the plumbing code in the Sea of Arrows player (http://seaofarrows.com/srcview/).

Start with:
com.seaofarrows.musicplayer.shell.controller.PlumbCommand

-=Cliff>
Logged
czw888
Newbie
*
Posts: 7


View Profile Email
« Reply #2 on: May 26, 2010, 11:57:00 »

But i see the demo:http://www.tekool.net/blogfiles/flash-modules-with-puremvc-pipes/project/PureMVC_FlashModulesAndPipes.html that is using Module Facade implements PipeAware.Why the demo is not problem
Logged
czw888
Newbie
*
Posts: 7


View Profile Email
« Reply #3 on: May 27, 2010, 12:00:26 »

Sorry.The Demo link is http://www.tekool.net/blogfiles/puremvc_flex_modules_and_pipes/project/PureMVC_FlexModulesAndPipes.html
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #4 on: May 27, 2010, 02:22:02 »

Cliff,

in PipeWorks and Sea of Arrows Music Player, you implement IPipeAware on the main module view. This was my choice to use IPipeAware on Facade. In multicore applications, I like to use Facade to manage the Pipe setup too, I think that this is its role as a Facade to mask the complexity under PureMVC Pipe setup and to offer a simplified API to connect/disconnect them.

Also, doing this the main Module view do not have to know PureMVC at all while implementing IPipeAware neither it has to knowledge of the Pipes package. I also found worst to break PureMVC best practices in using facade.sendNotification in a view (the module main view) than to implements IPipeAware on Facade.

A great advantage of this method is also that to setup pipe on a new module, the main Junction mediator do not have to call the module mediator and so the view to setup pipes, you only have to write :
:
var moduleFacade:IPipeAware = Facade.getInstance( moduleID ) as IPipeAware;
var moduleToShell:Pipe = new Pipe();
moduleFacade.acceptOutputPipe(...);

Now Cliff, as you are quite more experienced than me and write the framework by yourself, if you think that's a serious issue to do this, let me know. To be honest, when writing the Flash/FlexModulesAndPipes demos, I first give a try to the two versions, one using IPipeAware on module view, the other on Facade and had the two working well. The Facade version was quite easier to use when you have to dynamically load/unload Flex modules. But I can update my demos, even if it will represent some hard work to do that. ;)

Rich, as you contact me through my website, I will have a look to your project this evening and try to understand your problem. Note that this is not related to the IPipeAware implementation problem we discuss above.

« Last Edit: May 27, 2010, 02:24:01 by Tek » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: May 27, 2010, 06:20:45 »

Here, I believe that having the module send a note into the facade that it already knows is the lesser of two evils.

-=Cliff>
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #6 on: May 27, 2010, 01:57:59 »

Rich,

from the tests I did at home this evening, it seems that your problem is that your ANY_MODULE_TO_SHELL pipe doesn't connect correctly with the Shell teeMerge input pipe.

Look for your problem here :

:
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

Sorry I couldn't help more, I have problems with my Flash Builder install, I can't debug it more. You'll have to do the rest yourself.

Hope this helps.

Logged
czw888
Newbie
*
Posts: 7


View Profile Email
« Reply #7 on: May 27, 2010, 09:29:12 »

Hi Tek

     For you example,on HelloModuleJunctionMediator
:
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 );

}

If there is no filter, how do teeMerge connect to Pipe.And if there is no module to module,how can teeSplit write.
Logged
Pages: [1]
Print