Tuesday, May 12, 2009

Cloud to RIA: Accessing Google App Engine (Java) Data Through Flex AMF - Part I

[Part I] [Part II] [Part III]

Introduction

Cloud
and RIA (Rich Internet Application) are probably the hottest buzzwords today in the web world. You can look at cloud as a virtual server that provides single-point access to a distributed (often across the globe) collection of hardware/software and coming in three shapes:
  1. IaaS: Infrastructure as a Service. A good example is Amazon EC2, where you basically get a virtual machine (Amazon Machine Image) on which you install what you want.
  2. PaaS: Platform as a Service. This adds infrastructure software to IaaS so you don't start from scratch. Examples are Google App Engine (GAE) and Salesforce Force.com.
  3. SaaS: Software as a Service. Here, you get the full package that you tweak/customize to your needs. Best example of course is Salesforce.com.
Clouds have many benefits, most importantly:
  1. You don't need to plan/invest in hardware/software upfront
  2. Your infrastructure will scale as your business/needs grow
  3. You system will be fault-tolerant and secure
  4. You don't need to maintain/manage the setup
In this example, I'm using GAE (Java) for the cloud. Google had required developers to use Python for GAE till recently, when they announced a Java version. All references to GAE in this write-up refer to GAE (Java). GAE is free to get started; you will need a Gmail account.

An RIA is an advanced web (or desktop) front-end that's more sophisticated than traditional HTML/CSS/JavaScript web apps. The dominant web RIA today is Adobe Flex, although Microsoft Silverlight is gaining rapidly. Sun (Oracle) recently announced JavaFX that's gaining some traction in the Java community. We will use Flex as the RIA in this example; you will need Flex Builder (free trial for 60 days) and Eclipse.

Technology Choices

Once we've decided to hook up a Flex RIA to a GAE cloud, we need to look at some specifics. First, how do you represent the data on GAE? GAE (Java) does not allow saving to files on the server, so our only option is to save on the Google BigTable. In fact, it's a better option anyhow. Luckily, the new GAE has a standards-based Java persistence API (rather than the Google-proprietary API with Python): JDO and JPA. I'm using JPA for this example.

Next, the interchange data format. Popular message formats with Flex are: XML (SOAP or REST), JSON, and the Adobe-proprietary AMF. XML is verbose and although accesss through REST performs reasonably well, more succint representations like JSON are better for larger chunks of data. But the most efficient (and strongly typed) representation is with AMF, which is what we will use for this example. To employ AMF for the data exchange, we use the Flex RemoteObject.

Adobe has made the AMF spec public, and there are multiple free implementations, probably the most important of which are: BlazeDS, WebORB, and GraniteDS. I've tried all the three with GAE. BlazeDS never worked for me, and as of today I'm not aware of any official fixes, though there are blog reports of unofficial workarounds. WebORB kind of worked with their fix in the sense I could move data through POJO interfaces to data, but not the persisted classes themselves. I also had performance issues. GraniteDS worked like a charm, and that's what we'll use in this example. Do keep checking Will it play in App Engine for the latest info.

Preparation

To get started, you need to do two things right away:
  1. Get a GAE account. This is easy and free: just sign up at Google App Engine.
  2. Get a GAE (Java) access. Sign up at GAE (Java) Sign-up.
Once you've done this, let's get going with the real thing... in Part II.

19 comments:

Anonymous said...

An excellent blog entry...looking forward to part II

Puran said...

ok i am on a queue too...

Sekhar Ravinutala said...

Thanks guys, just posted Part II.

Mark Piller said...

What kind of performance problems did you run into with WebORB? As for transfering VOs, I am not aware of any problems there and the examples we posted online clearly demonstrate that functionaloty.

Sekhar Ravinutala said...

The performance issue was that there'd be big delay (several seconds) at the start of each browser session. Felt like each session was getting a new EM factory, as if the scope was session, even though I clearly specified application. I did post on your forums, but didn't hear back. This was with GAE 1.0 though, may be this is not an issue with the new 1.2.1.

And the problem with transferring was specifically with returning entities directly. E.g., I had an auto-generated id and a return em.find(Person.class, id) would fail. If I created a VO with the entity's contents, I could send the VO back without any problem. Possibly an issue with the generated id. Again, this was with 1.0.

Cliff Meyers said...

AMF is not really proprietary. The AMF specification is open and available from this page:

http://opensource.adobe.com/wiki/display/blazeds/Developer+Documentation

AMF serialization has been implemented in Java via BlazeDS which is open source.

Sekhar Ravinutala said...

Yes Cliff, Adobe has made the spec public, and GraniteDS (the one I used) is in fact one of the implementations based on that public spec. WebORB is another popular implementation, as I've noted in the blog.

Ji Lucas said...

Thank you. it is really great blog. I have been searching a good blog how to work with Google App Engine.

Unknown said...

Interesting article! Thx

Anonymous said...

Great article, but why on earth do you compare Adobe Flex to JavaFX or even MS Silverlight?
Both are crap.(tested and prooved)

akshaya said...

This article guides me with accuracy and I can see the altruistic nature in you, where who have been more responsible to deliver the information. Web Designing Course Training in Chennai | Web Designing Course Training in annanagar | Web Designing Course Training in omr | Web Designing Course Training in porur | Web Designing Course Training in tambaram | Web Designing Course Training in velachery

John P. Ketchum said...

Germany's famous media build hit the news "Indigo Blue Lions" Chelsea Premier League club strong. England put the name Mohamed Salah, striker, semi-wing of the Egyptian national team of "Reds" Liverpool is one of the goals of adding an army to Stamford Bridge this summer. ufabet

Marty Sockolov said...

Internet slots (Slot Online) may be the release of a gambling machine. Slot machine As pointed out Used to produce electronic gaming systems referred to as web-based slots, as a result of the improvement era, folks have considered gamble by way of computers. Will achieve slot online games making internet gambling online games Via the internet network process Which players are able to play through the slot plan or maybe will play Slots with the system provider's site Which internet slots gaming systems are actually on hand in the type of taking part in policies. It's similar to taking part in on a slot machine. Each of those realistic pictures and also sounds are likewise thrilling since they go to living room in the casino in the world.บาคาร่า
ufa
ufabet
แทงบอล
แทงบอล
แทงบอล

Michael L Catudal said...

pgslot ซึ่งเกมคาสิโนออนไลน์เกมนี้เป็นเกมที่เรียกว่าเกม สล็อตเอ็กซ์โอ คุณรู้จักเกมส์เอ็กซ์โอหรือไม่ 90% ต้องรู้จักเกมส์เอ็กซ์โออย่างแน่นอนเพราะในตอนนี้เด็กนั้นเราทุกคนมักที่จะเอาก็ได้ขึ้นมา สล็อต เล่นเกมส์เอ็กซ์โอกับเพื่อนเพื่อนแล้วคุณรู้หรือไม่ว่าในปัจจุบันนี้เกมส์เอ็กซ์โอนั้นกลายมาเป็นเกมซะลอสออนไลน์ที่ให้บริการด้วยเว็บคาสิโนออนไลน์คุณสามารถเดิมพันเกมส์เอ็กซ์โอกับเว็บคาสิโนออนไลน์ได้โดยที่จะทำให้คุณนั้นสามารถสร้างกำไรจากการเล่นเกมส์เดิมพันออนไลน์ได้เราแนะนำเกมส์ชนิดนี้ให้คุณได้รู้จักก็เพราะว่าเชื่อว่าทุก

John P. Ketchum said...

Close Protection Services stands tall among other security companies. Our guards think logically top security companies in London
before taking action. Our bodyguards have excellent situational awareness coupled couples with sharp eyes. They constantly scan environments watching out for any potential conflicts or situations that may harm the client. They can detect and stop potential accidents or attackers before they strike. Our bodyguards are aware that being proactive is better than being reactive when it comes to avoiding threats.

Beel SEO EXPORT said...

Any animal can take a gander at the WiFi Password Hacker Online segment in the graph and might want to utilize it free of charge. Hack Wifi Password Online

Cyberz Pc said...

Mega Downloader APK gives client controlled scrambled distributed storage space and talk from one side to another ordinary internet browsers, mutually with dedicated applications for portable methodology. Mega Downloader For Pc

cyber pc said...

Do not allow people to dim your shine because they are blinded. Tell them to put some sunglasses on. https://wishesquotz.com/helpful-life-quotes/

Anonymous said...



Since I have had zero issues when using this application, I think it is your best bet.
https://crackguru.net/ace-utilities-crack-download/