PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: openoli on August 15, 2013, 02:23:16



Title: Inter-core communication by implementing sendMessage() method in Facade.as
Post by: openoli 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


Title: Re: Inter-core communication by implementing sendMessage() method in Facade.as
Post by: puremvc 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.


Title: Re: Inter-core communication by implementing sendMessage() method in Facade.as
Post by: openoli 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!


Title: Re: Inter-core communication by implementing sendMessage() method in Facade.as
Post by: turtlebite 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


Title: Re: Inter-core communication by implementing sendMessage() method in Facade.as
Post by: openoli 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