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: Having a Hard Time with Pipes  (Read 16168 times)
mikebritton
Full Member
***
Posts: 42


View Profile Email
« on: June 09, 2008, 11:45:42 »

I don't know what it is, but I can't figure out how to get a simple message to a module from my shell and vice-versa.  I'm working in Flash AS3 only, no Flex.  I'd post code here, but last time I did, the post was removed.  Can anyone give me a step-by-step process?

I must be in a rut because here I am a week later without a clear handle on this.

The demo is great, but as I try to port my architecture to an implementation with Pipes, the complexity of tracing through the demo to decide how to move forward is not conducive to good learning.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: June 12, 2008, 06:06:39 »

Hi Mike,

I do plan to put together some sequence diagrams on the PipeWorks demo, I've just been swamped with other work since introducing it.

If you're having trouble just understanding how to use the Pipes utility itself, don't try to unravel the demo. Instead, study the unit tests.

The pipes utility has a very thorough set of unit tests which are well- documented and exercise all the moving parts.

Caveat: JunctionMediator may not be tested yet, I just moved it into the utility from the demo the other day.

But you'll see the unit tests dealing with things on a much more granular level: simple actions with lots of assertions in each test.

That should prepare you for deconstructing the demo.

-=Cliff>
Logged
mikebritton
Full Member
***
Posts: 42


View Profile Email
« Reply #2 on: June 14, 2008, 10:58:23 »

The Unit Tests are more helpful.  I also ran across a nice chart showing a basic implementation:

Logged
riafan
Courseware Beta
Jr. Member
***
Posts: 19


View Profile WWW Email
« Reply #3 on: June 15, 2008, 08:10:28 »

You can get info on that diagram, in context, at http://www.joshuaostrom.com/2008/06/13/pipe-architecture/

Regarding an overview of using pipe's I posted at
http://www.joshuaostrom.com/2008/06/15/understanding-puremvc-pipes/.

This diagram would probably be better for those trying to conceptualize the architecture.  The diagram illustrates an app that loads two 'child' modules.




Hope that helps!!!

« Last Edit: June 16, 2008, 05:20:34 by riafan » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: June 16, 2008, 10:09:15 »

That's a good one. And thanks for posting the tutorial so quickly, Josh.

I absolutely will be producing some more tangible docs for Pipes shortly, I've just been swamped since releasing it.

One note about the first diagram, is that in the simplest case, you could drop the Tees from the i/o pipes on the application and have it just be two pipes. You'd only need to add those Tees when you go to the next level of having the application collaborate with multiple modules you show in the diagram at the bottom.

Cheers,
-=Cliff>
Logged
riafan
Courseware Beta
Jr. Member
***
Posts: 19


View Profile WWW Email
« Reply #5 on: June 16, 2008, 10:19:02 »

Agreed. 

The first diagram (that Mike posted above) was pertaining to an implementation that allows an application to load modules that, in turn, load modules (a parent, child, grandchild implementation).  Probably can [should] be safely ignored for anyone just getting their feet wet [pun??] in pipes.

Thanks again for this great utility Cliff!!

BTW, I'm happy to report it's [the Pipes utility] working *great* in the enterprise app(s) I'm working on.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #6 on: June 16, 2008, 10:32:28 »

BTW, Josh, I added a link to your tutorial on the Pipes page.

-=Cliff>
Logged
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #7 on: June 17, 2008, 07:43:25 »

I love those diagrams Josh. Great job cementing the plumbing metaphor with virtual PVC (PMVC!).
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
riafan
Courseware Beta
Jr. Member
***
Posts: 19


View Profile WWW Email
« Reply #8 on: June 17, 2008, 09:41:35 »

Thanks, glad the diagrams helped (a picture is worth 1024 words :) ). 

I went ahead and posted the 'pipes' version of the mortgage app.

http://www.joshuaostrom.com/2008/06/17/pipe-demo-mortgage-app/

I apologize for all the linking!!
Logged
mikebritton
Full Member
***
Posts: 42


View Profile Email
« Reply #9 on: June 25, 2008, 07:49:36 »

I'm still trying to get a basic, boilerplate example working.  Here it is: http://www.mikebritton.com/downloads/pipes_boilerplate.rar

This is a non-Flex, AS3 example.  Main.as should be set as the default application.  I want to establish two-way communication between my Shell and a module, AppAModule.  If anyone could take a look and let me know what I'm doing wrong, I'd sure appreciate it.
Logged
mikebritton
Full Member
***
Posts: 42


View Profile Email
« Reply #10 on: June 25, 2008, 12:35:45 »

In JunctionPrepCommand, after registering my Mediators and adding the module to Shell, I'm sending a MODULES_LOADED Notification:

:
override public function execute( note:INotification ):void
{
var app:Shell = note.getBody() as Shell;

facade.registerMediator( new ApplicationMediator( app ) );
facade.registerMediator( new AppAModuleMediator() );

var amm:AppAModuleMediator = facade.retrieveMediator(AppAModuleMediator.NAME) as AppAModuleMediator;

app.addAppA(amm.appa);

facade.registerMediator( new ShellJunctionMediator() );

sendNotification( ApplicationFacade.MODULES_LOADED, app.appa );
}


My ShellJunctionMediator receives this Notification, creates the Pipes and connects them.

:
case ApplicationFacade.MODULES_LOADED:
var appam:AppAModule = note.getBody() as AppAModule;
connectModule( appam );
junction.sendMessage(PipeAwareModule.APP_TO_MODULE_PIPE,new Message(PipeAwareModule.STDOUT,null,5));
break;


Here's the function that connects the passed module:

:
public function connectModule( module:AppAModule ):void
{
//Create the pipe
var moduleToApp:Pipe = new Pipe();
module.acceptOutputPipe(PipeAwareModule.MODULE_TO_APP_PIPE, moduleToApp);
//Connect the pipe to our app
var appIn:TeeMerge = junction.retrievePipe(PipeAwareModule.MODULE_TO_APP_PIPE) as TeeMerge;
appIn.connectInput(moduleToApp);

//Create the pipe
var appToModule:Pipe = new Pipe();
module.acceptInputPipe(PipeAwareModule.APP_TO_MODULE_PIPE, appToModule);
//Connect the pipe to our module
var appOut:TeeSplit = junction.retrievePipe(PipeAwareModule.APP_TO_MODULE_PIPE) as TeeSplit;
appOut.connect(appToModule);

}


When compiled, this app should send a Message to AppAJunctionMediator, which should then respond to the app with another Message.

It's taken me a week to get to this point and I'm sure whatever mistake I'm making is a simple one.  Thanks in advance -- the code in the link above will compile.




Logged
mikebritton
Full Member
***
Posts: 42


View Profile Email
« Reply #11 on: June 26, 2008, 10:45:59 »

More struggles with Pipes, still no success.  I'm posting here so when I solve the problem myself, I can post the solution.

My ShellJunctionMediator is registering pipes:

:
override public function onRegister():void
{
trace("ShellJunctionMediator::onRegister");

junction.registerPipe( PipeAwareModule.APP_TO_MODULE_PIPE,  Junction.OUTPUT, new TeeSplit() );
junction.registerPipe( PipeAwareModule.MODULE_TO_APP_PIPE,  Junction.INPUT, new TeeMerge() );
junction.addPipeListener( PipeAwareModule.MODULE_TO_APP_PIPE, this, handlePipeMessage );
}

When my module loads, ShellJunctionMediator connects it:

:
public function connectModule( module:AppAModule ):void
{
//Create the pipe
var moduleToApp:Pipe = new Pipe();
module.acceptOutputPipe(PipeAwareModule.MODULE_TO_APP_PIPE, moduleToApp);

//Connect the pipe to our app
var appIn:TeeMerge = junction.retrievePipe(PipeAwareModule.MODULE_TO_APP_PIPE) as TeeMerge;
appIn.connectInput(moduleToApp);

//Create the pipe
var appToModule:Pipe = new Pipe();
module.acceptInputPipe(PipeAwareModule.APP_TO_MODULE_PIPE, appToModule);

//Connect the pipe to our module
var appOut:IPipeFitting = junction.retrievePipe(PipeAwareModule.APP_TO_MODULE_PIPE) as IPipeFitting;
appOut.connect(appToModule);

}

Finally, after all this happens, I try to send a message from Shell to the module when the Shell is clicked:

:
case ApplicationFacade.SHELL_SELECTED:
if (junction.hasOutputPipe(PipeAwareModule.APP_TO_MODULE_PIPE)) {
var myMessage:Message = new Message(PipeAwareModule.STDOUT,new Object(), new Notification(MMEventNames.BASIC_MESSAGE,note.getBody(),"COOL"))
junction.sendMessage(PipeAwareModule.APP_TO_MODULE_PIPE, myMessage);
}
break;


This results in an error:

:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at org.puremvc.as3.multicore.utilities.pipes.plumbing::Pipe/write()[C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\pipes_boilerplate\src\org\puremvc\as3\multicore\utilities\pipes\plumbing\Pipe.as:77]
at org.puremvc.as3.multicore.utilities.pipes.plumbing::TeeSplit/write()[C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\pipes_boilerplate\src\org\puremvc\as3\multicore\utilities\pipes\plumbing\TeeSplit.as:77]
at org.puremvc.as3.multicore.utilities.pipes.plumbing::Junction/sendMessage()[C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\pipes_boilerplate\src\org\puremvc\as3\multicore\utilities\pipes\plumbing\Junction.as:194]
at com.britton.apps.pipesboilerplate.modules.shell.view.mediator::ShellJunctionMediator/handleNotification()[C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\pipes_boilerplate\src\com\britton\apps\pipesboilerplate\modules\shell\view\mediator\ShellJunctionMediator.as:75]

Apparently the Pipe output is null. 

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #12 on: June 26, 2008, 07:57:54 »

Look at the message you are creating and be sure this is correct. Why is PipeAwareModule.STDIN one of the parameters?

Also, I see trace statements. That tells me you're probably not using the debugger. If you use the FB debugger and set a breakpoint after creation of the message, you can inspect it and the whole application. You can drill to the shell junction mediator and inspect the junction to see that its got the right pipes connected the right way.

-=Cliff>
Logged
Pages: [1]
Print