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: Bidirectional Communication between Modules using Pipes  (Read 11238 times)
saad
Sr. Member
****
Posts: 65


View Profile Email
« 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.
« Last Edit: January 27, 2014, 04:23:56 by saad » Logged
saad
Sr. Member
****
Posts: 65


View Profile Email
« Reply #1 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";
}

« Last Edit: January 27, 2014, 04:35:59 by saad » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 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.
Logged
Pages: [1]
Print