PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: saad on January 26, 2014, 12:50:05



Title: Bidirectional Communication between Modules using Pipes
Post by: saad on January 26, 2014, 12:50:05
I went couple of posts under "Architecture" forum that are talking about intercore communication but I think I need more help.

I've two submodules talking to each other, let's say a login module and a social module (plus others).

For some internal reasons, the login module is separate because of it's complexity and kind of services it's paired with.

If social module is invoked/requested, it needs to first pass the authToken (encrypted username/password) to "Login" module (Login and Social modules are connected to each other via Pipes).

Login module in turn returns true (with user data) or false, and then Social can carry on forward with what it has to do.

I understand that Pipes is one-way communication but I need communication back and forth. There are no web services involved, so it's not an asynchronous call. I'm using PHP port, it checks the database synchronously and returns true (with user data) or false.

What i can think is of is that, send a message with authToken from SocialJunction to LoginJunction and LoginJunction retrieves the Proxy, calls the function, gets it result and sends a message in return, received by SocialJunction and it carries on forward from there? Please advise.

Future Needs: (if multiple types of communication back and forth, use type attribute to distinguish between type of calls, Yes???)

Also if Asynchronous calls, can you pass a function of one submodule and have it executed by the second module as discussed here under Shared Proxies. http://forums.puremvc.org/index.php?topic=2080.0
Is that what async token pattern is or what is it?

Appreciate your help.


Title: Re: Intercore Communication back and forth using Pipes
Post by: saad on January 27, 2014, 04:05:51
Some progress but running into a confusion/problem for this bidirectional communication between two SubModules. I need two submodules to talk each other bidirectionally (no communication to shell necessary). Was able to get it working with an implicit STDSOC (EntitlementModule to SocialModule) but EntitlementModule maybe connected to more modules.

Question: how can I get a module's STDOUT to work as a broadcast to other multiple modules it maybe connected to

P.S. The code is in PHP but you may suggest using AS3.

Shell (StartupCommand)
                     
:
require_once ('modules/social/Social.php');
require_once ('shell/view/mediators/EntitlementMediator.php');
$social = new \modules\social\Social();
$this->facade()->registerMediator(new EntitlementMediator());
$this->facade()->sendNotification(ApplicationFacade::CONNECT_MODULE_TO_ENTITLEMENT, $social);

EntitlementMediator

:
public function handleNotification(\INotification $notification) {
switch($notification->getName()) {
case ApplicationFacade::CONNECT_MODULE_TO_ENTITLEMENT:
$module = $notification->getBody();
$pipe = new \Pipe();
$module->acceptOutputPipe(PipeAwareModule::STDENT, $pipe);
$this->viewComponent->acceptInputPipe(PipeAwareModule::STDIN, $pipe);

$pipe = new \Pipe();
$module->acceptInputPipe(PipeAwareModule::STDIN, $pipe);
$this->viewComponent->acceptOutputPipe(PipeAwareModule::STDSOC, $pipe);//work
//$this->viewComponent->acceptOutputPipe(PipeAwareModule::STDOUT, $pipe);
//how can I get STDOUT to work as a broadcast to all modules it maybe connected to
break;
}
}

EntitlementJunctionMediator

:
public function handleNotification(\INotification $notification) {
switch($notification->getName()) {
case \JunctionMediator::ACCEPT_INPUT_PIPE:
if($notification->getType() == PipeAwareModule::STDIN) {
$pipe = $notification->getBody();
$teeMerge = $this->junction->retrievePipe(PipeAwareModule::STDIN);
$teeMerge->connectInput($pipe);
} else {
parent::handleNotification($notification);
}
break;

default:
parent::handleNotification($notification);
break;
}
}

public function handlePipeMessage(\IPipeMessage $message) {
echo " entitlement ";
$this->junction->sendMessage(PipeAwareModule::STDSOC, new \Message("note name", null, "body"));
}


SocialJunctionMediator

:
public function handleNotification(\INotification $notification) {
switch($notification->getName()) {
case \JunctionMediator::ACCEPT_INPUT_PIPE:
if($notification->getType() == PipeAwareModule::STDIN) {
$pipe = $notification->getBody();
$teeMerge = $this->junction->retrievePipe(PipeAwareModule::STDIN);
$teeMerge->connectInput($pipe);
} else {
parent::handleNotification($notification);
}
break;

default:
parent::handleNotification($notification);
break;
}
}

public function handlePipeMessage(\IPipeMessage $message) {
echo "social";
}



Title: Re: Bidirectional Communication between Modules using Pipes
Post by: puremvc on March 06, 2014, 09:02:02
Question: how can I get a module's STDOUT to work as a broadcast to other multiple modules it maybe connected to?

Use a splitting tee on the module's STDOUT, and a merging tee on the STDIN to the other modules that need to hear the broadcast. It's like plumbing really.