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: Deployment Config - A PureMVC AS3 / Flex / AIR Utility  (Read 27030 times)
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« on: October 29, 2008, 10:14:30 »

The Deployment Config utility offers a simple solution to the problem of retrieving configuration and distributing it throughout a PureMVC application. Support is provided for multiple deployment environments, such that a single configuration file can hold the unique configuration settings for any number of deployment environments. A single environment is selected by changing the value of a single tag in the XML to point to the desired configuration. Standard and MultiCore versions are included.

The utility has historically been located here: http://trac.puremvc.org/Utility_AS3_Flex_DeploymentConfig
The project has been moved here: https://github.com/PureMVC/puremvc-as3-util-flex-deploymentconfig/wiki

The author is Cliff Hall.
« Last Edit: September 23, 2012, 02:39:30 by puremvc » Logged
jmz
Newbie
*
Posts: 3


View Profile Email
« Reply #1 on: December 23, 2008, 03:50:44 »

Does anyone know if there is an example/demo of the Deployment Config tool being used in a multicore app?

I see the example code in the src shows how to setup your sub-classed ConfigVO and ConfigProxy, but I'm looking for an example of where I would register and retrieve my ConfigProxy in a multicore app so that the information in the config xml is most easily available to both my shell and loaded modules.

Thanks in advance for any advice,

~Josh.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: December 23, 2008, 04:54:01 »

Do this in your StartupCommand:
   
:
var configProxy:MyAppConfigProxy = new MyAppConfigProxy();
facade.registerProxy( configProxy );
configProxy.fetchConfig();

Register a command for ConfigProxy.SUCCESS which continues with the loading of the modules (the locations of which you'll probably define in this configuration file). Then when you load your modules, if you want the configuration to be available to them, you will have to pass a reference to it into each module from the shell, either via a pipe or via an interface call. Note that the custom ConfigVO (i.e. MyAppConfigVO) will need to be defined in a library shared by both the module and the shell.

-=Cliff>
 
Logged
jmz
Newbie
*
Posts: 3


View Profile Email
« Reply #3 on: December 23, 2008, 06:10:08 »

Thanks, I'll give that a try!

ps.  I'm assuming you mean I should call configProxy.retrieveConfig() (rather than configProxy.fetchConfig())? 

Or maybe I have an outdated version?  (I'm using Utility_AS3_MultiCore_Flex_DeploymentConfig_1_0.swc).
Logged
jmz
Newbie
*
Posts: 3


View Profile Email
« Reply #4 on: December 23, 2008, 07:01:10 »

I have this working now for multicore, but I ran into a couple of gotcha's I though I would share if anyone else is attempting to use this:

- If you are using the examples to base your derived classes from, don't forget to modify lines such as:
:
import org.puremvc.as3.utilities.flex.config.interfaces.IConfigVO;to
:
import org.puremvc.as3.multicore.utilities.flex.config.interfaces.IConfigVO;
- I had to modify the code in the MyAppConfigProxy.as to have a contructor that accepts a parameter, and then calls it's parent constructor:

:
public class MyAppConfigProxy extends ConfigProxy
{
public function MyAppConfigProxy( configURL:String ){
super (configURL)
}
override protected function constructVO():IConfigVO
{
return new MyAppConfigVO();
}

}

I did this because the constructor for ConfigProxy requires a parameter, and I was getting and error if I tried to create my child class without passing a parameter when I was creating it.

Finally, in my StartupCommand class, I create my derived configProxy by passing it the url of my config file:

:
var configProxy:AppConfigProxy = new AppConfigProxy("config/config.xml");

Thanks again Cliff for you help!

~Josh.

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: December 24, 2008, 08:04:57 »

Rather than have your StartupCommand be responsible for the knowledge of where the config file is, I would put that in the proxy itself. Instead of the proxy taking a constructor param, simply have it call super with the literal value. This puts the right actor in charge of the information. All the rest of the app needs to know is that it needs to register this proxy and tell it to fetch the config.

-=Cliff>
Logged
mnkyhead
Courseware Beta
Newbie
***
Posts: 4


View Profile Email
« Reply #6 on: January 20, 2009, 07:30:39 »

So if I want to have data in my xml that is available to all environments, I can create a function that just access that info from my VO directly, and don't need to put it in a namespace?
Logged
mnkyhead
Courseware Beta
Newbie
***
Posts: 4


View Profile Email
« Reply #7 on: January 20, 2009, 09:21:38 »

So I am a little confused on the implementation, I have me sub ConfigProxy and my sub ConfigVO, but what is the best way to access the vo?
Do I just create new instances of the VO in my mediators etc., if I want to access the data, or do I retrieve the VO through the proxy? 

Since the name of my sub proxy isn't passed to the super, I can't retrieve it from the facade.  Can I just retrieve the ConfigProxy, and use the configVO call there to access my sub VO?

Logged
Shua
Newbie
*
Posts: 4


View Profile Email
« Reply #8 on: March 11, 2009, 08:29:58 »

I'm looking for the best practice in this situation:

I'm using the Deployment Config not only to configure for multiple environments but also to add modules.  I have a macro command that loads my view and model.  So my initial view is the shell which needs to load modules depending on the config file.  Now maybe I'm missing the boat but since my application mediator is listening for the config success should my macro command load my view first and then the model??? 


Danke,
Josh
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #9 on: March 13, 2009, 08:27:33 »

The order of mofel preparation followed by view preparation is a general guideline, sometimes it's more complicated. If you're loading modules using a mediator, sure you want that mediator and whatever view it tends to be ready unless you're caching them for use at a later stage when the view is ready, in which case you might register the module mediator, prep the model  while the modules load and then prep the view when the model and modules are both ready.

-=Cliff>
Logged
nielt
Newbie
*
Posts: 1


View Profile Email
« Reply #10 on: May 20, 2010, 01:20:17 »

Hi Cliff,

Regarding your suggestion...

"Do this in your StartupCommand:
   
:
var configProxy:MyAppConfigProxy = new MyAppConfigProxy();
facade.registerProxy( configProxy );
configProxy.fetchConfig();

Register a command for ConfigProxy.SUCCESS which continues with the loading of the modules (the locations of which you'll probably define in this configuration file)."

...I was wondering what the best way to handle the fact that the command registered for ConfigProxy.SUCCESS does NOT have a reference to the mx:Application in the notification body (as the StartupCommand DOES).

I need this reference to the mx:Application to register my Mediators.

Currently I am simply keeping a track of it in the Facade...

:
var wFacade:ApplicationFacade = facade as ApplicationFacade;
wFacade.app = note.getBody() as QuestWaver;

var configProxy:WaverConfigProxy = new WaverConfigProxy("config/waver-config.xml");
facade.registerProxy(configProxy);
configProxy.retrieveConfig();

...and then retrieving it in the ViewPrepCommand.

Is there a better (more correct) way to do this?

Thanks,
Niel.

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #11 on: May 20, 2010, 02:36:55 »

Rather than place it on the Facade, go ahead and register an ApplicationMediator which will tend the reference to the app. It can immediately register the other mediators for any other components in the view.

You probably want to do this before requesting the config, and in fact you could have it be the last operation on the ApplicationMediator's onRegister method after registering initial mediators.

-=Cliff>
Logged
gary.paluk
Newbie
*
Posts: 3


View Profile Email
« Reply #12 on: May 24, 2011, 10:12:55 »

When attempting to use this along side the StateMachine I'm not getting a transition into the App.STATE_LOGGED_OUT state. Here's the XML contents of my InjectFSMCommand.

:
<fsm initial={App.STATE_CONFIGURING}>
<state name={App.STATE_CONFIGURING} entering={AppFacade.CONFIGURE}>
<transition action={ConfigProxy.SUCCESS} target={App.STATE_LOGGED_OUT} />
</state>
<state name={App.STATE_LOGGED_OUT} entering={AppFacade.LOGIN}>

</state>
</fsm>



The ConfigureCommand registered in the facade looks like:
:
override public function execute(notification:INotification):void
{
var appConfigProxy: AppConfigProxy = facade.retrieveProxy( ConfigProxy.NAME ) as AppConfigProxy;
appConfigProxy.retrieveConfig();
}



The PrepModelCommand looks like:
:
override public function execute(notification:INotification):void
{
facade.registerProxy( new AppConfigProxy() );
}



My PrepViewCommand is as follows:
:
override public function execute(notification:INotification):void
{
facade.registerMediator( new AppMediator( notification.getBody() as App ) );
}



My StartupCommand is as follows:
:
override protected function initializeMacroCommand():void
{
addSubCommand( PrepModelCommand );
addSubCommand( PrepViewCommand );
addSubCommand( InjectFSMCommand );
}



and LoginCommand is currently just a trace that is not tracing. :|

Anyone who could give me any indication of something wrong within this set up, you will win 1000 internets and my appreciation.


Gary



P.S. Here is the contents of my AppConfigProxy class:
:
public class AppConfigProxy extends ConfigProxy
{
public static const CONFIG_PATH: String = "config/app-config.xml";

public function AppConfigProxy()
{
super( CONFIG_PATH );
}

override protected function constructVO(): IConfigVO
{
return new AppConfigVO( );
}

}
« Last Edit: May 24, 2011, 10:14:36 by gary.paluk » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #13 on: May 25, 2011, 08:24:42 »

Problem is the ConfigProxy superclass is just sending out a ConfigProxy.SUCCESS notification. In order to trigger the StateMachine into a transition, you have to send a StateMachine.ACTION notification.

Have a command translate the note:

InjectFSMCommand
:
<fsm initial={App.STATE_CONFIGURING}>
<state name={App.STATE_CONFIGURING} entering={AppFacade.CONFIGURE}>
<transition action={App.CONFIG_LOADED} target={App.STATE_LOGGED_OUT} />
</state>
<state name={App.STATE_LOGGED_OUT} entering={AppFacade.LOGIN}>

</state>
</fsm>

+

ConfigLoadedCommand:
:
override public function execute(note:INotification):void
{
        // the configVO will be passed on through with the
        // notification sent when the transition to the new state occurs
        var configVO:IConfigVO = IConfigVO( note.getBody() );
sendNotification( StateMachine.ACTION, configVO, App.CONFIG_LOADED );
}

-=Cliff>
Logged
Pages: [1]
Print