Using RSLs with Modules - apache-flex

We are building a fairly complex application that we need to be able to release different parts of at different times. To help us solve this problem we are using RSLs and Modules.
so let me describe the projects (names have been changed to protect the innocent)
core (rsl)
client (application)
groceries (module)
groceriesCore (rsl)
bakery (module)
bakeryCore (rsl)
We have one application client that loads the areas of the application as modules. We have a core RSL that does things like login and holds entitlements and provides an API for the modules to access this sort of state and also to communicate with each other.
When we load client we only want the core rsl to be loaded as that is that is currently required. When the groceries module is loaded we want the groceries rsl to load and likewise when the bakery module is loaded we want the bakeryCore rsl to load.
In reality this isn't what happens. If we set the projects up like that at run time the core rsl loads at application startup but the module RSLs do not load when the module is loaded. If we run an application from the project that houses the groceries module then he rsl loads when the application loads but not when the module does.
We need a way of loading the rsl when the module loads.
At the moment we specify groceriesCore and bakeryCore in the client application so they all load when the client loads. This is obviously not a good idea as when we add another 30 departments we don't want all these departments being downloaded at application startup - we only want them to be downloaded when they are required - when the application loads.
How do I achieve this? (other than a horrible custom rsl loader type thing).

RSLs can only be loaded at application startup. What I've done in the past is to make things like your groceriesCore another module instead of an RSL. Then you just specify it somewhere as a dependency for the groceries module so that when you want to load groceries it will check if the groceriesCore module is loaded and if needed, load it.
Managing the dependencies of modules is not something that Flex manages for you. So you will have to do it manually. Or perhaps the Potomac Framework will help with it's OSGI-ish approach.

Related

Flex RSL Vs Modules

I am in the confusion advantages or uses of RSL and Modules.
It is said that RSLs will be cached in the browser, so that they can be used across multiple applications without loading the same library again.
My question is,
Since the Modules also published as swf only and Willthey also will get cached as like any other application (swf) ?
What is the special logic used in the RSL will get cache?
How does the cache logic differs for RSL than Modules?
thanks,
Mani
There are two kinds of RSL's: signed (by Adobe) and unsigned (like you and I would make)
The signed RSL's contain the Flex framework classes, and are actually cached by the Flash Player itself. You can reduce the size of your application by using these RSL's (the default in Flex 4).
You can compile your own code into unsigned RSL's or Flex Modules. Both of these are cached by the browser, as usual.
Module SWF's can be loaded by an application at anytime, RSL's are loaded up front at application startup.
Theres a definite advantage to using the Flex framework RSL's, but for your own code Modules might have an advantage b/c they don't force the code to be loaded at app startup time.

Best way to organize a Flex application for compile performance?

I'm preparing to reorganize & refactory a Flash Builder application. The goals of the reorg are 1.) keep compile times for the part of the project I'm working on as fast as possible, 2.) keep the unrelated parts separate for code reuse. Goal #1 trumps goal #2 if there's a trade-off.
Currently, the app has assets in one project, core functionality AS3 in another project, and the MXML in a third project that links to the other two.
Would moving resources/code into swc libraries help compile time? What about compiling assets into an swf and embedding that into the main application? Any other techniques?
We had the same problem, application compile time was more than 1 minute.
Here is our solution:
There is a Core Library that contains class Core with static properties like: Core.resourceManager:IResourceManager, Core.stringManager:IStringManager, etc.
Main application project includes Core Library and provides implementation for all Core.someProp. This can be done via some hidden method like Core.setImpelentation().
There are unlimited number of Modules that use Core Library to contribute their display / logic to the application. Important:
Each Module is a separate Flash Builder project
Module link Core Library as external (it's included in Main App)
Module has XML-file that describes it, example it's name and icon in application control bar. It allows not to load all modules at start.
User should be able to choose which modules he would like to use. This will also help you in development.
You can optionally create Lib Library and include in it all classes that are common between modules and can be implemented using Core Library.
The result is incredible - you application becomes low-coupled, open/compile time decreases, APIs become more clear. Profit!
Modules are definitely the way to go here, as Maxim has described. Further to his advice, which is all solid, here's some other tips:
Extract styles out to a separate project, and compile the .css to a SWF. Load the SWF at runtime.
Structure your packages by business function first, MVC role second,
Eg: Rather than com.myapp.model.userconfig.UserOptions, use com.myapp.userconfig.model.UserOptions. Enforce that packages can only reference their siblings, or com.myapp.core.*.
This way, each package is a self contained module, which only references itself, or the core library.
Consider the Hellfire Compiler, which can farm your compilation over several CPU's in parallel
If not already, consider moving to the Flex 4 SDK, which has several compiler performance improvements, especially around compiling multiple SWC's.

Flex: What's the difference between an MXML "Component" and an MXML "Module"?

As the title suggests, what's the difference between a "Component" (New –> MXML Component) and a "Module" (New –> MXML Module)?
Thanks,
David
Modules are compiled into SWFs and loaded at runtime with ModuleLoader, whereas MXML components are compiled into an application. From the Flex docs:
Modules are SWF files that can be
loaded and unloaded by an application.
They cannot be run independently of an
application, but any number of
applications can share the modules.
Modules let you split your application
into several pieces, or modules. The
main application, or shell, can
dynamically load other modules that it
requires, when it needs them. It does
not have to load all modules when it
starts, nor does it have to load any
modules if the user does not interact
with them. When the application no
longer needs a module, it can unload
the module to free up memory and
resources. [...]
Modules are similar to Runtime Shared
Libraries (RSLs) in that they separate
code from an application into
separately loaded SWF files. Modules
are much more flexible than RSLs
because modules can be loaded and
unloaded at run time and compiled
without the application.
Hope that helps!

Is building separate .swc allow a faster loading of the application?

Our application is a bit slow to load at startup, i'm wandering myself if a sepation of the module of the application in several swc will decrease the loading time( grosso modo : a module = a "page" )
SWC is simply a compressed zip-like archive of classes (static library)/
Compiling an application against SWC doesn't change the outputted swf.
There are 2 means by which you can decrease the initial loading:
1.RSL - dynamic library which are loaded separately from the application and can be cached.
Any RSL signed by Adobe can be cached not just by the web browser which is platform-dependent caching, but also by the flash player itself, which means that even if a user clean its browser cached or has no cache at all, once the RSL is downloaded, it's cached.
This is typically useful for runtime loading of the flex framework & the RPC.
The other type of RSL caching like said earlier is browser caching.
Either way, RSL is loaded at startup.
2.The other way is by extracting parts of the application into modules, which will be loaded by demand. For example, if the application has 3 screen, each screen will probably be loaded ["probably", because it's up the developer to decide when] only when the user first enters this screen
It depends on what is making startup slow. Is it slow after the SWF has been cached by the browser? If so then you need to just better structure your code so that not so much is happening on startup. You can defer creation of object by setting the creationPolicy property on components. If the slowness is being caused by the size of the SWFs then using the framework RSLs and partitioning into Modules will help reduce the initial download size.

How to get a Flex project to load a plugin at runtime?

I'm looking to have a couple of plugins in a Flex project I'm working on. I know I can load a SWF using the SWFLoader, but I thought in Flex3 you can now have Runtime Shared Libraries or something. Does anyone have any good documentation on loading a plugin at runtime? Ideally I'd like to be able to load a plugin from a URL, then execute some code from within the plugin (e.g. add a control to the page).
You can use either Modules or RSL.
RSLs have the advantage of getting cached by flash rather than the browser so they stick around longer.
Modules are easier to create and use. I have used modules and had issues with modules failing to load (code needs to handle that case). I haven't tried RSLs yet.
Here is some documentation on creating RSLs http://labs.adobe.com/wiki/index.php/Flex_3:Feature_Introductions:Flex_3_RSLs
Note that, currently, loaded RSLs must be compiled against the very same version of the Flex framework.. if you plan for a "binary" plugin system, probably you want to wait for the Marshall plan feature to be implemented, in the next Flex version.
If you want to try a new and alternative approach, this is a application core framework modelled after java OSGi: http://www.potomacframework.org/
I haven't tried it myself, but it looks really cool!

Resources