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: Inter-core communication by implementing sendMessage() method in Facade.as  (Read 13433 times)
openoli
Full Member
***
Posts: 44


View Profile Email
« on: August 15, 2013, 02:23:16 »

Hi,
I'm still struggling with inter-core communication and just wondering if we not could simply add a "sendMessage()" method to the Facade.as.
This method forwards it's message by calling the sendNotication() method for the passed or all registered cores. At the end each core could listen to notifications(messages) that was triggered by other cores.
To avoid conflicts between notification names and message names we coud define a seperate common file for the message constants with it's own "namespace":

MessageConstants.as:
:
public class MessageConstants
{
public static const TEST1:String   = 'msg/Test1';
public static const TEST2:String  = 'msg/Test2';
}

The modified org.puremvc.as3.multicore.patterns.facade.Facade.as:
:
/**
* Send notification (message) to other cores
* @param notificationName the name of the notiification to send
* @param body the body of the notification (optional)
* @param type the type of the notification (optional)
* @param coreId the multitonKey of the receiver core, sends message to all registered cores by default (optional)
*/
public  function sendMessage(messageName:String, body:Object, type:String, coreId:String="*"):void
{
if(coreId=="*"){
for(var multitonKey:String in instanceMap)
{
                        // Send notification to each core
instanceMap[multitonKey].sendNotification(messageName, body, type);
}
}
else{
if(hasCore(coreId))
{
// Send notification to passed core
instanceMap[coreId].sendNotification(messageName, body, type);
}
}
}

Usage:
:
// Send message to all registered cores
facade.sendMessage(MessageConstants.TEST1, "I am a message for all cores");

// Send message to core "Test"
facade.sendMessage(MessageConstants.TEST1, "I am a message for the 'Test' core only", null, Test.NAME);

What do you think about it?

Thanks
Olaf
« Last Edit: August 15, 2013, 01:09:34 by openoli » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: October 14, 2013, 10:19:35 »

The problem is that you can't guarantee that notification constants aren't in conflict across modules. Particularly in a situation where third-party modules are provided. A core's message space is its own. That' why pipes has a message facility that can pass between modules safely.
Logged
openoli
Full Member
***
Posts: 44


View Profile Email
« Reply #2 on: October 29, 2013, 09:57:17 »

Cause we're currently only two PureMVC developers I'll risk it cause it's so easy to use.
But I have always the danger in the eye;-)

Thanks Cliff!
Logged
turtlebite
Newbie
*
Posts: 7


View Profile Email
« Reply #3 on: November 02, 2013, 01:00:11 »

Hi!

I have been using pipes for this also, but one day I had to create inter-communication between our PureMVC app and a module which was built without pureMVC. That's when I started to think about how to achieve this in a clean way, and I finally created a utility called "pigeons". Now I also use it in every situation, even between two pureMVC apps instead of pipes. The cool thing is, it has the same structure as a notification in PureMVC, a name, a body and a type. It's called pigeons, because I like to think about sending message pigeons from one module to another. Have a look and let me know what you think: http://blog.kaegi.net/pigeons-utility-as3-intercommunication-between-shell-and-modules/

And I guess it could be easily ported to other languages as well... :-)

Best,
Christian
Logged
openoli
Full Member
***
Posts: 44


View Profile Email
« Reply #4 on: December 02, 2013, 06:04:34 »

Hey Christian,
I've just seen your post, it sounds good!
I hope I'll get some time to check it out... will give you some feedback then!


Thanks!

Olaf
Logged
Pages: [1]
Print