PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: cyberpunk on June 24, 2008, 12:11:36

Title: Startup utility with dynamic resources
Post by: cyberpunk on June 24, 2008, 12:11:36
Hi everyone!
I'm new to the forum and to PureMVC.
I've started a couple of days ago to wrap my head around its structure and implementation.
Actually i'm making my tests with the standard edition but i plan to switch to the multicore edition pretty soon, cose my projects are often build in modules and i will like to keep "separated" the various module's implementation.

Now i'm giving a try to the utilities, the StartupManager utility actually, wich is great indeed.
I'm just having some problem adding some resource dynamicalli while using requirements ...

i've a generic "ResourceProxy" to handle the loaded resources in wich the SRNAME is generated by an id that I pass to the constructor along with the resource url ... so, these are my steps:

- in the startup command i load an xml file ("config.xml") in wich are listed the other resources.
- i call the keepResourceListOpen method on the monitor
- when the WAITING_FOR_MORE_RESOURCES notification is received by the mediator i send a notification who trigger LoadAssetsCommand
- LoadAssetsCommand parse the config xml, add the new resources and then call closeResourceList on the monitor

now, everything is ok since i put in some requirements.
let's say that resources B C and D need that resource A is loaded ...
i keep a reference to the StartupResourceProxy istance used for resource A and pass it to the other resources

the StartupManager now loads only resource A and then stops, without any error, message or notification, ignoring the other resources ...

i feel like i'm doing something wrong, but i can't figure out what ... so, thanks to anyone who can help ;)

Title: Re: Startup utility with dynamic resources
Post by: philipSe on June 24, 2008, 06:23:10
First, let me know that you are stating the dependencies and adding resources in the expected way.  For example, here are some lines from the source of the StartupAsOrdered demo.

        var rInv :StartupResourceProxy = new StartupResourceProxy( InvoiceProxy.SRNAME, invPx );
        facade.registerProxy( rInv );
        rInv.requires = [ rDAcc, rSO ];
        monitor.addResource( rInv );

These lines occur within commented code in the LoadResourcesCommand class.  They are meant to illustrate the api when the resource list is open.  Notice that the requires method sets the dependencies on rInv before rInv is added to the monitor.  This is because addResource() will cause immediate activity by the monitor and the dependencies must be known beforehand.

Anyway, maybe you have the above point covered.  The next point to cover is that after the load of your A resource, you must send the loaded notification so that the monitor knows to proceed with the other loads.  And of course, your B/C/D proxies must implement IStartupProxy by having a load() method.

Let me know your status regarding the above points.
BTW. This discussion should perhaps be under the StartupManager topic i.e. Forums /Port to as3 /Standard version

Title: Re: Startup utility with dynamic resources
Post by: cyberpunk on June 24, 2008, 07:00:18
first of all, excuse me for posting in the wrong board  :-[ hope someone can move it to the right one

most of the code i'm using it's taken from the StartupAsOrdered demo, so i think (hope) i'm addind resources and dependencies in the correct way and yes, my ResourceProxy do implements the IStartupProxy interface but i have only one generic proxy for every resource.

i think my error it's that i'm not sending a loaded notification, but i'm not so sure, mostly because if i don't use any requirements everythings gets loaded (but maybe that's the way it's intended to work)

i've posted my source here http://cyberpunk.l33t.it/puremvc/srcview/ for a better understanding of the problem
it's a bit silly but it's just a test to see how things works ^_^

Title: Re: Startup utility with dynamic resources
Post by: philipSe on June 24, 2008, 10:03:49
The loaded notification is essential when there are dependencies, otherwise dependent resources will not get loaded, since the monitor will not invoke the dependent loads until it knows the independent one has loaded.

When there are no dependencies, the monitor will invoke all the loads but it won't know they've completed if loaded notifications are not sent, so the monitor will not send its completed notification.

To be precise, it is the application proxies that implement IStartupProxy, not the StartupResourceProxies, but I'm sure you know that.

I hope your problem is solved by dealing with the loaded notifications.

Now, I have glanced at your code, note 'glanced' so forgive if I misread.  My comments are as follows
- ensure that you have looked at the api docs for the startup manager, so that you understand what it expects from client applications
- each instance of application resource proxy (your ResourceProxy class) must have a unique proxy name; this is critical in the context of loaded notifications so that the manager can distinguish which resource has been loaded; I think your constant NAME variable is being used 
- setting defaultRetryPolicy on the monitor in the LoadAssetsCommand, having already done it in the StartupCommand seems unnecessary and may even be wrong.

Let me know your progress.  Good luck.