Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Welcome, Guest. Please login or register.
August 16, 2017, 02:36:50 PM
Home Help Search Login Register
News: Please DM @puremvc on Twitter to gain forum access. Spambots are why we can't have nice things.
Pages: [1]
Print
Author Topic: Inter-core communication by implementing sendMessage() method in Facade.as  (Read 6332 times)
openoli
Full Member
***
Posts: 44


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

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:
Code:
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:
Code:
/**
* 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:
Code:
// 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 PM by openoli » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2870



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

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
« Reply #2 on: October 29, 2013, 09:57:17 AM »

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
« Reply #3 on: November 02, 2013, 01:00:11 PM »

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
« Reply #4 on: December 02, 2013, 06:04:34 AM »

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
Jump to: