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: Sharing proxy between cores  (Read 8654 times)
sasuke
Full Member
***
Posts: 29


View Profile Email
« on: October 17, 2009, 01:16:14 »

Hi all,

Recently I've been developing a multi-core PureMVC web application in Flex [i.e. more than one core is active at any given time]. When the user logs in the system, I set the user credentials in a User object which is cached by the UserProxy class [which maps to the User VO]. All this action happens in the main or the parent facade, for the sake of completeness, let's call it ShellFacade.

What would be a good design choice for making this cached User VO present in the UserProxy class [which is currently registered in the ShellFacade] available to other cores [e.g. facade XXX]? One way I can think of is to:
  • Retrieve the UserProxy of the ShellFacade in the XXX facade startup command
  • Register the user proxy in the XXX facade using the retrieved proxy
:
class XXXStartupCommand extends SimpleCommand implements ICommand
{
   override public function execute(notification:INotification):void
   {
      var userProxy:IProxy = ShellFacade.getInstance(ShellFacade.NAME).retrieveProxy(UserProxy.NAME);
      facade.registerProxy(userProxy);
      // remaining code
   }
}

This of course creates a dependency of ShellFacade in the facade XXX command which seems a bit problematic since it hinders the reuse of this independent module in other scenarios. Is there any other way of doing this? Any design pattern which I can apply to reduce the coupling which would get introduced here?

I perfectly understand that it wouldn't be a big thing to change the ShellFacade to something else in case I decide to use the facade XXX in some other scenario but I'd like to avoid that. Suggestions welcome.

TIA,
sasuke
« Last Edit: October 17, 2009, 01:17:51 by sasuke » Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #1 on: October 17, 2009, 01:55:32 »

If sharing user VO across cores is important for your application because it contains some data that cost high to retrieve (e.g. from a server), the easiest way to achieve this imho, is to share the same proxy class but not the same proxy instance in your different cores. You can use a local file (SharedObject if you use Flash) to store user info and use the same Proxy class (not the same instance) in all your cores to read the user VO stored in the SharedObject without any tight coupling between cores.

A better but more complex solution is to implement PureMVC Pipes and to punctually ask for a UserVO clone through pipes to the module that have role to retrieve user infos from the server. If the application is large enough the definitive solution is to have a module dedicated to user info management, each module asking or receiving user infos updates.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: October 17, 2009, 02:54:10 »

@Tek, The latter would be my recommendation.
-=Cliff>
Logged
sasuke
Full Member
***
Posts: 29


View Profile Email
« Reply #3 on: October 18, 2009, 03:00:19 »

Hi there.

> You can use a local file (SharedObject if you use Flash) to store user info

This is definitely not a choice in my case since the user can disable the SharedObject implementation by setting the size to 0kb in the Flash Player setting thereby rendering the entire application useless.

> A better but more complex solution is to implement PureMVC Pipes

Unfortunately, the application is almost complete and plugging in a new architectural piece at this moment might not be possible.

> If the application is large enough the definitive solution is to have a module dedicated to user info
> management, each module asking or receiving user infos updates

This sounds interesting; is the term "module" here used in the Pipes context or in the context of a Facade like UserInfoFacade which would be dedicated to managing user information, expiring sessions etc.? On a related note, I hope it isn't an anti-pattern to have a facade which isn't related to a concrete view per-se?

TIA,
sasuke.
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #4 on: October 18, 2009, 07:34:44 »

You're right on the SharedObject deactivation. This was definitively a bad idea, sorry. I want to introduce this because I'm currently working on an application running in two different SWFs, I need and use the SharedObject to store VOs and use the same proxys classes in the two SWFs to access data, I found this elegant. But in the same application, finally it's like using a global context, quite a bad practice.

>This sounds interesting; is the term "module" here used in the Pipes context or in the context of
>a Facade like UserInfoFacade which would be dedicated to managing user information, expiring sessions etc.?

You can use modules without pipes, even if pipes are recommended to let modules communicate http://trac.puremvc.org/Demo_AS3_MultiCore_Flex_Modularity . It's rather easy to integrate Pipes when you already have integrated modules with a clean API for each.

>On a related note, I hope it isn't an anti-pattern to have a facade which isn't related to a concrete view per-se?
 I recently have asked this on the forums, Cliff answered it here : http://forums.puremvc.org/index.php?topic=1445.0

Logged
sasuke
Full Member
***
Posts: 29


View Profile Email
« Reply #5 on: October 23, 2009, 11:35:13 »

Thank you for all the suggestions, the link you posted was really interesting. :)
Logged
Pages: [1]
Print