1




       FLEX & JAVA USING
       BLAZEDS



Hien Luu   2009 Silicon Valley Code Camp
About Me
2


      Senior Software Engineer at Netflix
      Many years with developing web-based

       applications w...
Flex & Java Using BlazeDS
3


        Agenda
           BlazeDS   Overview
             What   & Why
           BlazeD...
Flex & Java Using BlazeDS
4




               Quick Survey
BlazeDS Overview
5


        Open source project from Adobe – 12/07
           Smaller   cousin of Adobe LifeCycle Data ...
BlazeDS Overview
6


        Alternatives


                               Servlet Container

                           ...
AMF
7


        AMF (Action Message Format)
           Wire   protocol
             Fast,   small – 10x over XML
      ...
BlazeDS Tour
8


        Download Turnkey version
           Include Tomcat 6.x
           BlazeDS sample applications
...
BlazeDS Architecture
9

                           BlazeDS Services

    Access to enterprise
       functionality
       ...
BlazeDS Architecture
10


                           Flex Client Architecture

            Flex Client                    ...
BlazeDS Architecture
11

                                        BlazeDS Server Architecture

                            ...
BlazeDS Configuration
12




     Filename              Description

     services-config.xml   Top level configuration fi...
BlazeDS Channels & EndPoints
13


         Channel set fallback mechanism

          Channel                Endpoint     ...
BlazeDS Channels Behavior
14




     Channel                           Description
     Non-polling AMF & HTTP channel   ...
Remoting
15


       Invoke methods of Java objects on server side
       HTTP-based request/response data communication...
Remoting
16


         RemoteObject – client side component
            destination– source of Remoting Service destinat...
BlazeDS Architecture
17

                                      BlazeDS Server Architecture

                            Me...
Remoting
18


     <mx:Script>
        private function getProducts() : void {
          ro.getProducts();
        }
     ...
Remoting
19
                                remoting-config.xml
                    <destination id="tutorial-product">
  ...
Remoting
20


     <mx:Script>
        [Bindable]
         private var products:ArrayCollection
         private function ...
Remoting
21


         Destination scope
            request  – server creates an instance of Java class per
           ...
Remoting
22


         Concurrency
            multiple  – existing requests are not canceled
            Single – one ...
Data Serialization
23




                          Servlet Container

             AS   Java
                            ...
Data Serialization
24


         Serializing Between ActionScript & Java
                        AS Type                 ...
Remoting
25


         AS Serialization Rule
            Public bean properties w/ getter/setter methods
            Pu...
Remoting
26




                                       java.util.ArrayList

     ActionScript                             ...
Messaging
27


         Publish-subscribe messaging
            Among  multiple Flex clients
            Support bridgi...
Messaging
28

                                      BlazeDS Server Architecture

                            Message
     ...
Messaging
29
                             messaging-config.xml
                 <destination id=’chat’>
                  ...
Messaging
30


         Message filtering
            Through message header and subtopic information
            Subsc...
Messaging
31



           Filtering through subtopic
              Usesubtopic property of AsyncMessage
              ...
Messaging
32




               Enable destination to support subtopic

     <destination id=“chat” >
         <properties...
Messaging
33




                            Performance related settings

     Property                       Description...
Messaging
34


         Measuring message processing performance
            Message  size
            Sever processing...
Messaging
35


     <channel-definition id="my-streaming-amf”
         class="mx.messaging.channels.StreamingAMFChannel">
...
Messaging
36


             Use MessagePerformanceUtils to access processing
              metrics


     private functio...
Proxy
37

                                 google.com




             Servlet Container
                 BlazeDS         ...
Proxy
38


           HTTPService
              REST  functionality
              All HTTP method
                PUT,...
Proxy
39


         Proxy-config.xml
            Server   side configuration

     <destination id="DefaultHTTP">
      ...
Resources
40


         BlazeDS
              http://opensource.adobe.com/wiki/display/blazeds/Overview
         AMF Be...
Upcoming SlideShare
Loading in...5
×

RIA With Flex & Java Using BlazeDS

16,368

Published on

This session will provide details about how Flex applications can integrate with server side applications written Java using BlazeDS.

Published in: Technology, Education
1 Comment
9 Likes
Statistics
Notes
No Downloads
Views
Total Views
16,368
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
699
Comments
1
Likes
9
Embeds 0
No embeds

No notes for slide

Transcript of "RIA With Flex & Java Using BlazeDS"

  1. 1. 1 FLEX & JAVA USING BLAZEDS Hien Luu 2009 Silicon Valley Code Camp
  2. 2. About Me 2   Senior Software Engineer at Netflix   Many years with developing web-based applications with Java technologies   Instructor at UCSC-Extension school   RIA with Flex & Java   Spring Framework   Design Patterns
  3. 3. Flex & Java Using BlazeDS 3   Agenda   BlazeDS Overview   What & Why   BlazeDS Tour   BlazeDS Architecture   BlazeDS Services   Remoting   Messaging   Proxying   Demo
  4. 4. Flex & Java Using BlazeDS 4 Quick Survey
  5. 5. BlazeDS Overview 5   Open source project from Adobe – 12/07   Smaller cousin of Adobe LifeCycle Data Services Servlet Container BlazeDS Database Your Application
  6. 6. BlazeDS Overview 6   Alternatives Servlet Container Your Java Database application PHP/Python Granite, OpeAMF, Cinnamon,
  7. 7. AMF 7   AMF (Action Message Format)   Wire protocol   Fast, small – 10x over XML   AMF3 specification   Open Source AMF Implementation   AMFPHP   OpenAMF   rubyAMF   PyAMF
  8. 8. BlazeDS Tour 8   Download Turnkey version   Include Tomcat 6.x   BlazeDS sample applications   Flex 3 SDK   Unzip and start Tomcat and HSQL   Come with sample database – product and census data http://localhost:8400/
  9. 9. BlazeDS Architecture 9 BlazeDS Services Access to enterprise functionality RPC Service Let Flex clients communicate with each other Messaging Service asynchronously Proxy service to integrate multiple services with a Proxy Service single application
  10. 10. BlazeDS Architecture 10 Flex Client Architecture Flex Client J2EE Server BlazeDS Component BlazeDS RemoteObject HTTPService WebService HTTP Consumer Producer AMF/AMFX Channel Set M A F H P T T
  11. 11. BlazeDS Architecture 11 BlazeDS Server Architecture Message MessageBrokerServlet Broker Service Destination Adapter •  AMFEndPoint R RemotingService RemotingDestination • HTTPEndPoint O • StreamingAMFEndPoint U JavaAdapter HttpProxyService T HttpProxyDestination E HttpProxy MessageService Adapter M S MessageDestination G ActionScript Adapter Security JMS Check point Adapter
  12. 12. BlazeDS Configuration 12 Filename Description services-config.xml Top level configuration file. Contains security constraints definitions. Logging settings. Basically common configurations across services. remoting-config.xml Remoting service definitions, such as destination. proxy-config.xml Proxy service definitions for working with web services, HTTP. remoting-config.xml Messaging service for publish & subscribe
  13. 13. BlazeDS Channels & EndPoints 13   Channel set fallback mechanism Channel Endpoint Description AMFChannel AMFEndPoint Transport data over HTTP in binary AMF format. Use for Remoting. HTTPChannel HTTPEndPoint Transport data over HTTP in AMFX format. User for Remoting. StreamingAMFChannel StringAMFEndPoint Streams data in real time over HTTP in binary AMF format. User for Messaging. StreamingHTTPChannel StreamingHTTPEndPoint Streams data over HTTP in AMFX foramt.
  14. 14. BlazeDS Channels Behavior 14 Channel Description Non-polling AMF & HTTP channel Good for Remoting Piggybacking AMF & HTTP channel Enable queuing of messages along with responses to any messages from client. Polling AMF & HTTP channel Simple polling mechanism from client side to request messages Long polling AMF & HTTP channel To get pushed messages to client. Server parks the poll request until data arrives for client. Streaming channel Stream data in real-time. Available in HTTP 1.1 only. Make sure servers are capable of handling large concurrent connections
  15. 15. Remoting 15   Invoke methods of Java objects on server side   HTTP-based request/response data communication   Use AMFChannel   Advantages   AMF binary messaging protocol for exchanging data   Serialization/de-serialization are handled automatically   Natively supported by Flash Player   Gateway services make easier to expose server side services Why not use HTTPService or WebService?
  16. 16. Remoting 16   RemoteObject – client side component   destination– source of Remoting Service destination   result – when service call successfully returns   fault – when service call fails   concurrency – how to handle multiple calls   multiple – existing requests are not cancelled   single – one at a time, multiple requests generate fault   last – New request cancels any existing request
  17. 17. BlazeDS Architecture 17 BlazeDS Server Architecture Message MessageBrokerServlet Broker Service Destination Adapter •  AMFEndPoint R RemotingService RemotingDestination O U JavaAdapter T E M S G Security Check point
  18. 18. Remoting 18 <mx:Script> private function getProducts() : void { ro.getProducts(); } private function handleGetProdudctResult(event:ResultEvent) : void { } private function handleUpdateProdudctResult(event:ResultEvent) : void { } private function handleFault(event:FaultEvent) : void { Alert.show(event.fault.faultString); } </mx:Script> <mx:RemoteObject id="ro" destination="tutorial-product" showBusyCursor="true"> <mx:method name="getProducts" fault="handleFault(event)" result="handleGetProductsResult(event)" /> <mx:method name="updateProduct" fault="handleFault(event)" result="handleUpdateProductResult(event)" /> </mx:RemoteObject> <mx:Button label=“Get Products” click=“getProduct()” /> http://localhost:8400/samples/blazeds-debug/Census.html
  19. 19. Remoting 19 remoting-config.xml <destination id="tutorial-product"> <properties> <source>tutorial.ProductDAO</source> </properties> </destination> Java Class Java Class package tutorial; package tutorial; public class ProductDAO { public class Product { public List<Product> getProducts() { private int productId; // DB logic private String name; } private double price; private int qty; public void updateProduct(Product prod){ // DB logic // getters and setters for } // above member variables } }
  20. 20. Remoting 20 <mx:Script> [Bindable] private var products:ArrayCollection private function handleGetProductsResult(event:ResultEvent) : void { products = event.result as ArrayCollection; } private function handleFault(event:FaultEvent) : void { Alert.show(event.toString()); } </mx:Script> <mx:DataGrid dataProvider="{products}" width="100%" height="100%" id="dg" > <mx:columns> <mx:DataGridColumn headerText="Serial Number" dataField="productId" /> <mx:DataGridColumn headerText="Name" dataField="name" /> <mx:DataGridColumn headerText="Price" dataField="price" /> <mx:DataGridColumn headerText="Quantity" dataField="qty" /> </mx:columns> </mx:DataGrid>
  21. 21. Remoting 21   Destination scope   request – server creates an instance of Java class per request (Default)   application – one instance for entire application   session - one instance per session <destination id="tutorial-product"> <properties> <source>tutorial.ProductDAO</source> <scope>request</scope> </properties> </destination>
  22. 22. Remoting 22   Concurrency   multiple – existing requests are not canceled   Single – one at a time   last – latest request cancels any existing request <mx:RemoteObject id="ro" destination="tutorial-product" showBusyCursor="true"> <mx:method name="getProducts" fault="handleFault(event)" result="handleGetProductsResult(event)" concurrency=“multiple”/> </mx:RemoteObject>
  23. 23. Data Serialization 23 Servlet Container AS Java BlazeDS AS Java Your Application
  24. 24. Data Serialization 24   Serializing Between ActionScript & Java AS Type Java Array(dense) java.util.List Array(sparse) java.util.Map Boolean java.lang.Boolean Date java.util.Date int/uint java.lang.Integer Object java.util.Map Typed Object Typed Object [RemoteClass] XML org.w3c.dom.Document • Dense array – all numeric indexes are consecutive (no gap) • Sparse – gap between numeric indexes
  25. 25. Remoting 25   AS Serialization Rule   Public bean properties w/ getter/setter methods   Public variables   Private properties, constants are not serialized   Client side   Use [RemoteClass(alias=“ “)] to map directly to Java object   Custom Serialization package {   Iexternallizable interface [Bindable] [RemoteClass(alias="tutorial.Product")]   [Transient] public class Product { public var productId:int; public var name:String; public var price:Number; public var qty:int; } }
  26. 26. Remoting 26 java.util.ArrayList ActionScript ActionScript Array java.util.TreeSet ArrayCollection java.util.TreeSet public class ProductService { public void addProduct(java.util.Set products) {} public void addProduct(java.util.SortedSet products) {} public void addProduct(java.util.List products) {} }
  27. 27. Messaging 27   Publish-subscribe messaging   Among multiple Flex clients   Support bridging to JMS topics (only)   Server can push message to client on its own. Consumer Message Producer Messaging Consumer Service
  28. 28. Messaging 28 BlazeDS Server Architecture Message MessageBrokerServlet Broker Service Destination Adapter R MessageService MessageDestination •  Producer O • Consumer U ActionScript Adapter T E JMS M Adapter S G Custom Adapter
  29. 29. Messaging 29 messaging-config.xml <destination id=’chat’> <channels> <channel ref=‘sample-amf’> </channels> </destination> <mx:Application> <mx:Script> private function sendMessage(): void { var msg = new AsyncMesage(); msg.body = “Hello there” producer.send(msg); } private function handler(event:MessageEvent) : void { Alert.show(“Got it: “ + event.message.body; } </mx:Script> <mx:Producer id=“producer” destination=“chat”> <mx:Consumer id=“consumer” destination=“chat” message=“handler(event)”> </mx:Application>
  30. 30. Messaging 30   Message filtering   Through message header and subtopic information   Subscriber defines the filter criteria   Send to server during the subscripting step   Message filtering is done on the server <mx:Application> <mx:Script> private function sendMessage(): void { <mx:Application> var msg = new AsyncMesage(); <mx:Script> msg.headers = new Array(); … msg.headers[“user”]= “John”; </mx:script> msg.body = “Hello there”; <mx:Consumer id=“consumer” producer.send(msg); destination=“chat” } message=“handler(event)” </mx:script> selector=“user = ‘John’”> … </mx:Application> </mx:Application>
  31. 31. Messaging 31   Filtering through subtopic   Usesubtopic property of AsyncMessage   Support single-token wildcard in subtopic string <mx:Application> <mx:Script> private function sendMessage(): void { var msg = new AsyncMesage(); msg.body = “Hello there”; producer.subtopic = “chat.gossip”; producer.send(msg); <mx:Application> } <mx:Script> </mx:script> … <mx:Producer id=“producer” </mx:script> destination=“chat”> <mx:Consumer id=“consumer” … destination=“chat” </mx:Application> message=“handler(event)” subtopic=“chat.gossip”> </mx:Application>
  32. 32. Messaging 32 Enable destination to support subtopic <destination id=“chat” > <properties> <server> <allow-subtopics>true</allow-subtopics> <subtopic-separator>.</subtopic-separator> </properties> <channels> <channel ref=‘sample-amf’> </channels> </destination>
  33. 33. Messaging 33 Performance related settings Property Description throttle-inbound Control # of inbound messages per second throttle-outbound Control # of outbound messages per second message-time-to-live How long server should keep a message pending delivery before being discarded as undeliverable Additional settings for security
  34. 34. Messaging 34   Measuring message processing performance   Message size   Sever processing time   Network travel time   Message waiting time   Ensure clients & server clocks are synchronized   Enable at the channel level
  35. 35. Messaging 35 <channel-definition id="my-streaming-amf” class="mx.messaging.channels.StreamingAMFChannel"> <endpoint url="http://{server.name}:{server.port}/{context.root}/ messagebroker/streamingamf” class="flex.messaging.endpoints.StreamingAMFEndpoint"/> <properties> <record-message-times>true</record-message-times> <record-message-sizes>true</record-message-sizes> </properties> </channel-definition>
  36. 36. Messaging 36   Use MessagePerformanceUtils to access processing metrics private function messageHandler(message:IMessage):void { log.text += message.headers["user"] + ": " + message.body.chatMessage + "n"; var perfInfo:MessagePerformanceUtils = new MessagePerformanceUtils(message); Alert.show(perfInfo.prettyPrint()); }
  37. 37. Proxy 37 google.com Servlet Container BlazeDS yahoo.com Your Application amazon.com
  38. 38. Proxy 38   HTTPService   REST functionality   All HTTP method   PUT, DELETE, HEAD, POST, GET   Get response data when status code != 200   URL alias control on server side <mx:HTTPService destination="CNNFeed" useProxy="true" id="topNewService" resultFormat="e4x” result="handleTopNewResult(event)"/> <!– using default proxy destination  <mx:HTTPService useProxy="true" id="searchService" resultFormat="e4x” result="handleSearchResult(event)” />
  39. 39. Proxy 39   Proxy-config.xml   Server side configuration <destination id="DefaultHTTP"> <properties> <dynamic-url>http://*</dynamic-url> </properties> </destination> <destination id="CNNFeed"> <properties> <url>http://rss.cnn.com/rss/cnn_topstories.rss</url> </properties> </destination>
  40. 40. Resources 40   BlazeDS   http://opensource.adobe.com/wiki/display/blazeds/Overview   AMF Benchmark   http://www.jamesward.com/census   Architecting RIAs with Flex Data Management Services   http://www.adobe.com/devnet/flex/articles/architecting_rias.html
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×