Welcome!

Adobe Flex Authors: Matthew Lobas, PR.com Newswire, Shelly Palmer, Kevin Benedict

Related Topics: Adobe Flex

Adobe Flex: Article

Working with Large Applications

Static versus dynamic linking: development perspective Part 1

In this excerpt from our book, Rich Internet Applications, we'll cover how to set up large applications intended for Web or, more broadly speaking, distributed deployment. As an example let's consider an enterprise application that consists of hundreds of screens, reports, forms, and dashboards. Accordingly, about a dozen engineers specializing in GUIs, frameworks, data layers, and business domains are working on this application in parallel.

Every application "run" in Flex Builder as well as the invocation of the application's MXML file processed by the Web-tier Flex compiler requires an application build. Needless to say, this takes time. The bigger the application, the more time it takes.

Developers need a fast process of building and deploying their applications.

The application also has to be partitioned for team development both vertically (application screens) and horizontally (UI, skins, reusable components, and back-end code). Imagine working on two "portlets," one of them showing a DataGrid and the other a TreeView. You have a choice: either package a 1MB module with both portlets or download separate ones (500K each) on demand. The latter way has the additional benefit of isolating the work between the team members.

Finally, the model should allow the extensibility of the product, meaning the integration of patches and portlet-style add-ons as well as external Flex subsystems shouldn't impact the main build.

We'll try to accommodate these requirements emphasizing the productivity of team development and deployment flexibility. But first let's review the deployment scenarios from the business point-of-view in detail.

Deployment Scenarios
Throughout this excerpt we'll use the term patches, which are the fixes and additions made to an application between releases. Add-ons are the parts of the application that are typically added over time. Similar to patches add-ons blend seamlessly into the hosting application, both visually and programmatically.

In some cases the application build may not even "know" about specific add-ons since they're different for each user type. For example, an enterprise application can reveal more screens or more functionality within these screens to internal users. In this case we talk about portlet-style add-ons.

Plug-ins are independent applications that don't share the look-and-feel of the main application. No intensive interaction between the main application and plug-ins is expected.

Application Domains 101
As much as we don't like to duplicate the work done by the Adobe Flex documentation team, we have to cover the subject of Application Domains since it's essential to this chapter. So, here are the facts.

All code loaded from an SWF file lands in one or another application domain. Conversely, instances of the flash.system.ApplicationDomain class stores the tables of the ActionScript 3.0 definitions and class definitions in particular.

A system domain contains all the application domains and there's a current domain where the main application runs. There's also a parent domain for each domain except the system one. System domains, quite naturally, happen to be the parent of the main application's domain.

The definition of the loaded classes as long as they remain loaded can't be overriden down the parental chain. Attempts to reload a class that's already been loaded by its parent will fail. If you're coming from the Java side, you may have seen a similar mechanism called Java ClassLoader.

We also have to mention the security domains of the Flash Player, since partitioning the classes (visibility) via application domains is within the confines of the security domains. The choice of a security domain is relevant for use cases when we need to load an SWF file coming from a different server, which is outside the scope of this chapter.

So, an application domain is the mechanism that (a) supports multiple definitions of the same class where children can access parent definitions seamlessly or (b) lets child definitions be tentatively merged with parent ones so that accessing the other party's definitions is seamless for both the child and the parent.

This mechanism is enacted by flash.display.Loader and mx.controls.SWFLoader controls.

The first choice is represented by the syntax new ApplicationDomain(Appli cationDomain.currentDomain) while the second one is ApplicationDomain.currentDomain.

A specific sub-case of (a) is the use of a system domain as a parent: new ApplicationDomain(null), which results in the ultimate separation of the (class) definitions, eliminating any overshadowing.

Either way, the required application domain is getting assigned the applicationDomain property of a Flash.system.LoaderContext instance, which, in turn is used as an argument to construct a flash.system.Loader, or acts as a property of an mx.controls.SWFLoader.

There are nuiances in accessing child definitions from the parent as well as in loading/accessing possibly overshadowing the class definitions.

When you bring existing Flex subsystems (perhaps even written in a different version of Flex) under a common application umbrella, it makes sense to resort to a separate application domain. At the same time, if you need to dynamically load DataGrid definitions, it makes sense to load them in the same application domain where the main application is running.

Runtime Shared Libraries 101
Flex documentation defines Runtime Shared Libraries (RSL) as "a library of components." We would like to start with the clarification that RSL is not a file but a pattern of using an SWF file from within another SWF file.

Specifically, SWFs marked as RSLs are automatically pre-loaded during the application's bootstrap as opposed to being explicitly loaded by the code you write. To be exact, definitions contained in the SWF are loaded into the applicationDomain of the hosting application.

Now how does the application's bootstrap know which SWF files are to be pre-loaded?

Here is an answer. Let's assume that:
a)  You made the file FlexLibrary.SWC (using the compc compiler explicitly or from within the Flex Builder's Library Project);
b)  You've created the file FlexApplication.mxml, which refers to components from FlexLibrary.SWC;
c)  While compiling FlexApplication.mxml you instructed the mxmlc compiler that FlexLibrary.SWC contains an image of an SWF to be pre-loaded during the bootstrap (this will be explained later in this chapter).

Then, the corresponding ActionScript file generated by the mxmlc compiler will have the code fragment shown below. You'll find this and other files in the generated folder of your application project once you set the compiler's option to keep-generated-actionscript=true:

public class _FlexApplication_mx_managers_SystemManager extends mx.managers.SystemManager
implements IFlexModuleFactory {
    public function _FlexApplication_mx_managers_SystemManager() {
super();
    }
      override public function info():Object {
      return {
        "currentDomain": ApplicationDomain.currentDomain,
        "layout" : "absolute",
        "mainClassName" : "FlexApplication",
        "mixins" : ["_FlexApplication_FlexInit", ......]
        ,
        "rsls" : [{url: "FlexLibrary.swf", size: -1}]
    };
}
}
}

As a reminder, the SystemManager is a parent of all the displayable objects within the application, such as the main window (an instance of mx.core.Application), pop-ups, cursors, etc. SystemManager also creates the mx.preloaders.Preloader that loads SWF files.

Please note that FlexLibrary.swf is not an RSL. As we said above, RSL is a usage pattern rather than a file. What makes FlexLibrary.swf part of this pattern is the intent to pre-load it during the application startup communicated by us to the mxmlc compiler.

    "currentDomain": ApplicationDomain.currentDomain,

This illustrates that the RSL approach results in class definitions from the library are loaded into the same domain where the definition of the application classes belong. That's why, in particular, we find the RSL technique especially useful for delivering various patches, which should be loaded prior to any other class definitions.

SWFs and SWCs: What's Under the Hood How do our SWC files relate to SWFs? Like every Flex SWC, FlexLibrary.SWC contains the library.swf and catalog.xml files. The latter describes the hierarchy of dependencies found in library.swf, which can potentially become FlexLibrary.swf (depending on the selected link type described below).

When we compile FlexApplication.mxml containing references to FlexLibrary.SWC in the library search path, there are three link types to choose from:

  • External - The catalog.xml in the FlexLibrary.swc will be used to resolve references; however the code contained in library.swf won't be included in the body of the FlexApplication.swf. The External link type assumes that by the time FlexApplication needs to create instances of classes from the library.swf part the definitions for these classes will somehow get loaded in the relevant applicationDomain.
  • RSL - The catalog.xml in the FlexLibrary.swc will be used to resolve references; code contained in library.swf won't be included in the body of the FlexApplication.swf. So far sounds like External, right? Here's the difference: all definitions originally contained in the library.swf part will be upfront-loaded into the main applicationDomain during application startup.
  • Merge-in - Classes that are explicitly referenced by the code (and their dependencies) explicitly get included in the FlexApplication.swf. This is a default option for statically linked applications and guarantees that the definitions of all referenced classes as well as the classes they depend on are loaded into the main applicationDomain outright.
A Merge-in scenario is often called static linking, while External and RSL are cases of dynamic linking.

Suppose we went with dynamic linking via RSL. As illustrated in the previous code fragment, this means pre-loading the FlexLibrary.swf. Here's the question: where do we get this FlexLibrary.swf from? Under one scenario we can let Flex Builder extract and rename the library.swf from the FlexLibrary.swc. In Flex Builder (project Properties >Flex Build Path> Library Path) this option is called Auto extract swf. Alternatively, we could have declined auto-extracting and unzipped the SWF from the SWC ourselves. As we'll show later, there's yet another way of explicitly controlling the upfront build of FlexLibrary.swf.

We'll illustrate these cases in the next section.

Making the FlexLibrary.swc
Let's make an SWC in Flex Builder by creating a new Flex Library Project. The only component we're going to add to this SWC is the CustomPanel from the following code which enumerates the instances of itself and imprints the number of the instance as part of its title, using the variable instanceNumber that we've declared bindable:

<?xml version="1.0" encoding="utf-8"?>
<!-- CustomPanel.mxml -->
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" title="'Custom' Panel
#{instanceNumber}" width="300" height="150" creationComplete="instanceNumber=++count;" >
    <mx:Script>
      public static var count:int;
      [Bindable]
      private var instanceNumber:int;
    </mx:Script>
</mx:Panel>

To ensure that our CustomPanel is accounted for (in both library.swf and catalog.xml) we have to verify that it's included in the Flex Library Build Path. Please be aware that every time you add or rename files in your Library Project the corresponding checkbox in Flex Builder gets cleared.

After we click OK, Flex Builder will invoke the compc compiler to create the FlexLibrary.swc in the output bin folder.


More Stories By Victor Rasputnis

Dr. Victor Rasputnis is a Managing Principal of Farata Systems. He's responsible for providing architectural design, implementation management and mentoring to companies migrating to XML Internet technologies. He holds a PhD in computer science from the Moscow Institute of Robotics. You can reach him at [email protected]

More Stories By Yakov Fain

Yakov Fain is a Java Champion and a co-founder of the IT consultancy Farata Systems and the product company SuranceBay. He wrote a thousand blogs (http://yakovfain.com) and several books about software development. Yakov authored and co-authored such books as "Angular 2 Development with TypeScript", "Java 24-Hour Trainer", and "Enterprise Web Development". His Twitter tag is @yfain

More Stories By Anatole Tartakovsky

Anatole Tartakovsky is a Managing Principal of Farata Systems. He's responsible for creation of frameworks and reusable components. Anatole authored number of books and articles on AJAX, XML, Internet and client-server technologies. He holds an MS in mathematics. You can reach him at [email protected]

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices t...
"Evatronix provides design services to companies that need to integrate the IoT technology in their products but they don't necessarily have the expertise, knowledge and design team to do so," explained Adam Morawiec, VP of Business Development at Evatronix, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
DevOps at Cloud Expo – being held June 5-7, 2018, at the Javits Center in New York, NY – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real results. Among the proven benefits,...
@DevOpsSummit at Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, is co-located with 22nd Cloud Expo | 1st DXWorld Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait...
Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
SYS-CON Events announced today that T-Mobile exhibited at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on qua...
SYS-CON Events announced today that Cedexis will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Cedexis is the leader in data-driven enterprise global traffic management. Whether optimizing traffic through datacenters, clouds, CDNs, or any combination, Cedexis solutions drive quality and cost-effectiveness. For more information, please visit https://www.cedexis.com.
SYS-CON Events announced today that Google Cloud has been named “Keynote Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Companies come to Google Cloud to transform their businesses. Google Cloud’s comprehensive portfolio – from infrastructure to apps to devices – helps enterprises innovate faster, scale smarter, stay secure, and do more with data than ever before.
SYS-CON Events announced today that Vivint to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. As a leading smart home technology provider, Vivint offers home security, energy management, home automation, local cloud storage, and high-speed Internet solutions to more than one million customers throughout the United States and Canada. The end result is a smart home solution that sav...
SYS-CON Events announced today that Opsani will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Opsani is the leading provider of deployment automation systems for running and scaling traditional enterprise applications on container infrastructure.