Multiple application "instances"

jason.gardner.lv's Avatar

jason.gardner.lv

29 Sep, 2011 05:03 PM

Love RL! I created a modular Air application with a shell and modules, each with there own context and MVCS impl. Works great!

Now I've run into a significant challenge. It seems the new requirement for the application is that it allow multiple instances to be launched. I know that, with Air, this is not possible. However, the common workaround is to try to create a headless main class that can spawn windows as needed. I guess this should work, but I would think the application would need significant re-working to support multiple instances, with most everything being singletons and whatnot. That is, unless I can figure out how to set up the correct application domains to encapsulate each instance.

Has anybody run into a similar scenario or can offer any advice? Thx

  1. Support Staff 1 Posted by Stray on 29 Sep, 2011 07:47 PM

    Stray's Avatar

    Hi Jason,

    as there are no static singletons, there's no reason why you can't just spawn two of your app - assuming they don't require a comms channel between them. The 'singleness' of a singleton is maintained by the injector, not the getInstance() pattern - so provided each app has its own injector, it will also have its own 'singletons'.

    So - it would literally just be a case of doing new MyApp() for each instance.

    If you need communication (but not shared instances) between them then you'd probably be best to take the original long-hand modular approach - you can find that on my github: https://github.com/Stray/robotlegs-utilities-Modular

    This version of modular just facilitates communication between modules by using a shared eventDispatcher. I tend to use a mediator around each module to relay external events to the internal dispatcher and vice versa.

    Note that this won't be the most efficient route at execution - you'll be doing all your reflection and type checking and so on from scratch in each app. Depending on whether performance is important, it might be viable to implement a shared cache for that stuff, and serialise it to shared storage, so that when a new instance of the app is spawned it can pre-load the injector and mediator map caches and so on. Or you can just live with it how it is :)

    But yes - it should be straight forward.

    Stray

  2. 2 Posted by jason.gardner.l... on 29 Sep, 2011 07:54 PM

    jason.gardner.lv's Avatar

    Stray,

    Thanks so much for the reply.

    Yes, in my case there won't be any communication between instances, so I'll just try to create some sort of headless main class for my Air app and create multiple instances of my app "shell" in separate windows. ::fingers crossed::

  3. 3 Posted by Stray on 29 Sep, 2011 08:03 PM

    Stray's Avatar

    Excellent - if you run in to anything peculiar, shout and we'll see what we can do,

    Stray

  4. 4 Posted by jason.gardner.l... on 29 Sep, 2011 08:46 PM

    jason.gardner.lv's Avatar

    Worked like a charm, Stray! I wouldn't have guessed it, but after understanding your explanation of the singleton pattern in RL, I was way overthinking it. "it just works" :)

  5. jason.gardner.lv closed this discussion on 29 Sep, 2011 08:47 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac