0
Giorgio Natili
Blaze DS connectivity
   Blog: www.mxml.it
   twitter: http://twitter.com/giorgionatili
During the session

I. Introduction
II. Blaze DS and Live Cycle DS
III. How to invoke Java from Flex
  I.      Setting up ...
It’s RIA time

• The adoption of Rich Internet Applications is increasing in a
  very different range of contexts

   - Bu...
RIA solutions

• The main solution you can find on the market today for the
  front end implementation of a RIA are

   – ...
The snapshot
   Java Programmer




     .NET Programmer

                        Ajax Programmer




     Flash Programmer
And then comes Flex...

• I totally agree with the first reaction of people with Flash, the
  skip intro nightmare is stil...
Blaze DS and Live Cycle DS

• Blaze DS and Live Cycle DS (LCDS) represent today the
  two main choices developers can do w...
AMF communication

• One of the key point of these software is the communication
  over AMF

• Action Message Format (AMF)...
AMF 10 times faster, how?

• Is a compact binary format for data serialization / de-
  serialization and remote method inv...
Features comparison
                                        Features                                      Blaze
DS   LCDS
...
Features comparison
                           Features                            Blaze
DS   LCDS
Offline
Applica;on
Suppor...
And the performance?

• Accordingly to the features you are planning to use the
  performance can change

   - RPC service...
Why this difference?

• The reason why is that Blaze DS supports long-polling and
  streaming over HTTP to push data to th...
Blaze benefits

• Blaze DS is open source and it’s extendable so you can add
  your modules or functionalities

• Supports...
Blaze effect

Java developers and Flash developers became friends and start
                      to work together….
How to invoke Java from Flex

• In order to start with Java and Flex you can download and
  setup Blaze DS on your system ...
It’s so simple

• In your Flex application use MXML in order to invoke a
  remote method you can use the following snippet...
Nothing against simple, but…

I totally agree with you, it seems to be the typical script
approach, the first questions th...
J2EE configuration (server)

• Start Eclipse and select the “Java EE” perspective
• In the bottom panel, select the “Serve...
J2EE configuration (Web Project)

• Create a new “Dynamic Web Project” with the following
  settings:
   – Project name: m...
J2EE configuration (BlazeDS Configuration)

• Overwrite the contents of your “WebContent” directory with
  the BlazeDS dir...
So complex?

                       Are you lost?




  Simply unzip the Blaze DS distribution archive and use it as
     ...
Hello world!




               Demo
A centralized approach

• The development of enterprise application involves actually a
  large number of server side call...
The Service Connector

• The ServiceConnector class is not part of the Flex
  framework, it’s part of a set of utilities I...
Service Connector features

• The ServiceConnector class is a Singleton in order to
  avoid multiple instances of the clas...
Used classes

  –               AMFChannel and SecureAMFChannel; provides the AMF
      support for messaging. You can con...
Service Connector UML diagram
Service Connector dependencies

The dependencies of this outside the flex framework are:

   –   RemoteObjectWrapperEvent
...
The RemoteObjectWrapperEvent

• The RemoteObjectWrapperEvent class is a custom
  Event that uses two public static constan...
The IRemoteMethod interface

The IRemoteMethod is the interface implemented by the remote
method called trough the Service...
The IRemoteMethod interface

• The source and the destination are used in order to
  define the service to call

• The ret...
The RemoteMethod class

The RemoteMethod implements the IRemoteMethod
interface, the use of an interface here is due to po...
The MethodQueue class

• The MethodsQueue class follows the Singleton design
  pattern, when the application calls more th...
The ServerSideCallEvent

• The ServerSideCallEvent is a bubbling event that
  in the Flex architecture (actually in the Fl...
The ServiceConnector in 5 steps (1/5)

• Create the ServiceConnector instance and specify which
  is the object that needs...
The ServiceConnector in 5 steps (2/5)

• Define the listeners for the event that will generate the
  server side calls

  ...
The ServiceConnector in 5 steps (3/5)

Define the listener to anonymous calls, it initialize the
connector, perform the ca...
The ServiceConnector in 5 steps (4/5)

Define the listener to logged calls, it initialize the connector,
perform the call ...
The ServiceConnector in 5 steps (5/5)

• Define the Listener to the general result event, it's able to
  update the UI com...
How to put everything in action

• Use the Model View Presenter for your component
• Make a comparison between Model View ...
The MVP pattern

• The original implementation of the MVP is born in the 1979,
  its name was Thing Model View Editor and ...
The MVP diagram
The MVP actors

•   The Model refers to the data and business functionality of the
    application
•   Selections are comp...
MVP and MVC (1/2)
                  MVC                                          MVP

UI Presentation Pattern focus on    ...
MVP and MVC (2/2)
                   MVC                                      MVP

 The three components would interact   ...
Let’s start with a demo!
Upcoming SlideShare
Loading in...5
×

Giorgio Natilli - Blaze DS Connectivity Framework

1,593

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,593
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
46
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Giorgio Natilli - Blaze DS Connectivity Framework"

  1. 1. Giorgio Natili Blaze DS connectivity Blog: www.mxml.it twitter: http://twitter.com/giorgionatili
  2. 2. During the session I. Introduction II. Blaze DS and Live Cycle DS III. How to invoke Java from Flex I. Setting up the environment II. Create a simple script IV. A centralized approach I. Service Connector (part of the nabiro class set) I. The ActionScript classes involved II. The analysis of the class II. Model View Presenter V. Demo
  3. 3. It’s RIA time • The adoption of Rich Internet Applications is increasing in a very different range of contexts - Business - Education - Entertainment • If your software has an architecture where the business logic is clearly separated from other layers, then you can use one of the available technologies (or mix all the best features of each technology) and develop a RIA
  4. 4. RIA solutions • The main solution you can find on the market today for the front end implementation of a RIA are – Java FX – Silverlight – Ajax – Flash • Accordingly to your choice people can say: - He’s a real programmer - He’s good guy but too much related to MS - He’s a scripter - He’s a graphic designer, he can’t do a software
  5. 5. The snapshot Java Programmer .NET Programmer Ajax Programmer Flash Programmer
  6. 6. And then comes Flex... • I totally agree with the first reaction of people with Flash, the skip intro nightmare is still live in my mind! • But I have to be honest in my experience with the Flex framework you can get great cross platform result and reach a wide range of users because the Flash Player is omni present and a de facto standard in the web development • The use of the Flash Player is not only related to Flex, each Flash application may be a good one or a bad one accordingly to the way you design it
  7. 7. Blaze DS and Live Cycle DS • Blaze DS and Live Cycle DS (LCDS) represent today the two main choices developers can do when they are planning a new RIA connected with Java or Coldfusion • The first one is open source (great!) and the second one is a close source (less great but a very good tool!) product with a greater set of functionalities • There are obviously a lot of difference between the two solutions but the choice depends only on your needs
  8. 8. AMF communication • One of the key point of these software is the communication over AMF • Action Message Format (AMF) is a compact binary format that is used to serialize ActionScript object graphs • Once serialized an AMF encoded object graph may be used to persist and retrieve the public state of an application across sessions or allow two endpoints to communicate through the exchange of strongly typed data
  9. 9. AMF 10 times faster, how? • Is a compact binary format for data serialization / de- serialization and remote method invocation • Object encoding controls how objects are represented in Action Message Format (AMF) • Representation can be transferred over HTTP/HTTPS • As data size increases the performance benefits of using Blaze DS increase exponentially • Objects casting is performed on the server side part
  10. 10. Features comparison Features Blaze
DS LCDS Data
management
Services Client‐Server
synchroniza3on x Conflict
resolu3on x Data
paging x SQL
adapter x Hibernate
adapter x Document
Services Live
Cycle
remo3ng x RIA‐to‐PDF
conversion x Enterprise‐Class
Flex
applica;on
services Data
access/remo3ng x x Proxy
service x x Automated
tes3ng
support x SoFware
clustering x x Web
3er
compiler x Enterprise
Integra;on WSRP
genera3on x Ajax
data
services x x Flex‐Ajax
bridge x x Run3me
configura3on x x Open
adapter
architecture x x JMS
adapter x x Server‐side
component
framework
integra3on x x ColdFusion
integra3on x
  11. 11. Features comparison Features Blaze
DS LCDS Offline
Applica;on
Support Offline
data
cache x Local
message
queuing x Real
‐
Time
Data Publish
and
Subscribe
messaging x x Real‐3me
data
quality
of
service x RTMP
tunneling x
  12. 12. And the performance? • Accordingly to the features you are planning to use the performance can change - RPC services over an AMF Channel -> NO difference - Data pushing -> A LOT of difference LCDS Blaze DS
  13. 13. Why this difference? • The reason why is that Blaze DS supports long-polling and streaming over HTTP to push data to the client but it manages this through the Servlet API which has the restriction right now of mandating blocking IO • LCDS provides support for the RTMPChannel (direct duplex socket connection between the client and server) as well as non-blocking long-polling and streaming support over HTTP that bypasses the Servlet API and its blocking IO limitation • All of these options in LCDS are built on top of the Java NIO APIs
  14. 14. Blaze benefits • Blaze DS is open source and it’s extendable so you can add your modules or functionalities • Supports the main Java servers – Tomcat – Jboss – Glassfish – Others… • Blaze DS is shipped in bundle with Tomcat so it’s easy to start also without a Java background
  15. 15. Blaze effect Java developers and Flash developers became friends and start to work together….
  16. 16. How to invoke Java from Flex • In order to start with Java and Flex you can download and setup Blaze DS on your system from Adobe Labs http:// labs.adobe.com/technologies/blazeds/ • In order to invoke Java methods from Flex application I. Add a mapping to the Java class to services-config.xml II. Map your RemoteObject (provided with Flex SDK) on the client side to the destination configured in services-config.xml III. Invoke the method in your Java class using the RemoteObject instance
  17. 17. It’s so simple • In your Flex application use MXML in order to invoke a remote method you can use the following snippet of code <mx:RemoteObject id=”remoteObj” destination=”testRpc” result=”Alert.show(event.result.toString());” fault=”Alert.show(event.fault.faultString);” /> <mx:Button label=”Remote Service” click=”remoteObj.testRemoteMethod();”/> • The destination is defined in your services-config.xml and the testRemoteMethod() is defined in your java class on the server and you can handle the result and fault event via MXML or via ActionScript for each remote object
  18. 18. Nothing against simple, but… I totally agree with you, it seems to be the typical script approach, the first questions that can came out probably are I. And what happens in a large application? II. How long is the equivalent code in ActionScript? III.Why I have to learn this if I’m not sure of the results? IV. How many killer application really use it? V. Is it an application that use MXML to handle the communication with the business logic really scalable? VI. Even more…
  19. 19. J2EE configuration (server) • Start Eclipse and select the “Java EE” perspective • In the bottom panel, select the “Servers” tab • Right click on the panel and select “New->Server” • Select the server settings and point them to your newly installed tomcat server. The installation directory should be “<base turnkey installation dir>tomcat” (in my case this is “C: tomcat”) • Click Finish
  20. 20. J2EE configuration (Web Project) • Create a new “Dynamic Web Project” with the following settings: – Project name: myBlazeProject – Target Runtime: “Apache Tomcat x.x” (this is the server you created in the last section) – Configuration: Default Configuration for Apache Tomcat x.x • Click “Finish”
  21. 21. J2EE configuration (BlazeDS Configuration) • Overwrite the contents of your “WebContent” directory with the BlazeDS directory structure “<base turnkey installation dir>tomcatwebappsblazeds • Right click on your newly created “myBlazeProject” project and select “Properties” • Select “Java Build Path” from the list in the left hand panel. • Set the “Default output folder” to “myBlazeProject/ WebContent/WEB-INF/classes”, this will cause your web server to automatically update every time you rebuild your project.
  22. 22. So complex? Are you lost? Simply unzip the Blaze DS distribution archive and use it as your server, it’s enough to start….
  23. 23. Hello world! Demo
  24. 24. A centralized approach • The development of enterprise application involves actually a large number of server side calls • You can work with remote objects defined in each component handling the result and the fault event in each component or you can work in a centralized way with only one class that handle for you all the remote operations • There is not a native solution in Flex, you have tor write down your own solution
  25. 25. The Service Connector • The ServiceConnector class is not part of the Flex framework, it’s part of a set of utilities I created for my projects • The packaging structure – Events – Remote – Utils – Main classes
  26. 26. Service Connector features • The ServiceConnector class is a Singleton in order to avoid multiple instances of the class in the same application and provides the public methods a developer needs in order to perform authenticated and anonymous call against java services deployed under Blaze DS • The ServiceConnector class is also able to perform the login and the logout of a user, to handle the queue of multiple calls following a FIFO style and to recover a service using the name of the method you need to call • The ServiceConnector class implements the IEventDispatcher interface and therefore is the responsible of the notification of all the events fired during the server side interaction
  27. 27. Used classes – AMFChannel and SecureAMFChannel; provides the AMF support for messaging. You can configure this Channel to poll the server at an interval to approximate server push – Channel; is the base message channel class that all channels in the messaging system must extend – ChannelSet; is a set of Channels that are used to send messages to a target destination – AbstractOperation; represents an individual method on a service – AbstractService; is the base class for the WebService and RemoteObject classes – AsyncResponder; allows the creator to associate data (a token) and methods that should be called when a request is completed – AsyncToken; provides a place to set additional or token- level data for asynchronous RPC operations
  28. 28. Service Connector UML diagram
  29. 29. Service Connector dependencies The dependencies of this outside the flex framework are: – RemoteObjectWrapperEvent – IRemoteMethod – RemoteMethod – MethodsQueue – MethodsQueueElement – ServerSideCallEvent
  30. 30. The RemoteObjectWrapperEvent • The RemoteObjectWrapperEvent class is a custom Event that uses two public static constants in order to define the FAULT and RESULT type of the event • It’s the one that bring the data recovered out from the ServiceConnector to your application • It’s the one that has the knowledge of the remote method (with an instance of the AbstractService) invoked that is used to notify the appropriate control that data are coming
  31. 31. The IRemoteMethod interface The IRemoteMethod is the interface implemented by the remote method called trough the ServiceConnector class, each method needs to define the following accessor methods (getters not shown for brevity) function set name(value:String):void; function set arguments(value:Array):void; function set source(value:String):void; function set destination(value:String):void; function set returnObject(value:Class):void; function set isList(value:Boolean):void;
  32. 32. The IRemoteMethod interface • The source and the destination are used in order to define the service to call • The returnObject is the class type of the object / objects returned from the method invocation • The isList is used in order to understand if the remote method returns a single value or an Array of values • arguments is self explanatory
  33. 33. The RemoteMethod class The RemoteMethod implements the IRemoteMethod interface, the use of an interface here is due to possible future enhancement of the micro architecture we use for the server side communication
  34. 34. The MethodQueue class • The MethodsQueue class follows the Singleton design pattern, when the application calls more than one method from different components is trough this class that the queue of results is handled and the results are sent to the appropriate component • Each item stored in the MethodQueue class is an instance of the class MethodsQueueElement that defines the method and abstract operation performed
  35. 35. The ServerSideCallEvent • The ServerSideCallEvent is a bubbling event that in the Flex architecture (actually in the Flash Player) is able to reach an upper level component • The ServerSideCallEvent is the one that drives to the ServiceConnector the method to call
  36. 36. The ServiceConnector in 5 steps (1/5) • Create the ServiceConnector instance and specify which is the object that needs to receive the events dispatched from the class sc = ServiceConnector.getConnector(this); • Set the default services for the ServiceConnector instance sc.defaultSource = quot;com.gnstudio.services.Adminquot;; sc.defaultDestination = quot;Adminquot;; • Define the listeners for the events sc.addEventListener(RemoteObjectWrapperEvent.FAULT, onFault) sc.addEventListener(RemoteObjectWrapperEvent.RESULT, onResult)
  37. 37. The ServiceConnector in 5 steps (2/5) • Define the listeners for the event that will generate the server side calls addEventListener(ServerSideCallEvent.ANONYMOUS_CALL, onAnonymousCall); addEventListener(ServerSideCallEvent.LOGGED_CALL, onLoggedCall); • Create the hash map used to handle the queue of the server side calls, the map is the one used also to send the data to a specific component hash = new HashMap();
  38. 38. The ServiceConnector in 5 steps (3/5) Define the listener to anonymous calls, it initialize the connector, perform the call and add the caller to the hash map (@param e ServerSideCallEvent) private function onAnonymousCall(e:ServerSideCallEvent):void{ var obj:AbstractService; try{ obj = sc.makeAnonymousCall(e.fakeObject as IRemoteMethod); }catch(err:Error){ sc.initializeConnector(baseUrl + SERVICES[0], connectorKind); obj = sc.makeAnonymousCall(e.fakeObject as IRemoteMethod); } hash.addItem({service: obj, target: IPresenter(e.target), nameSpace: e.nameSpace}) }
  39. 39. The ServiceConnector in 5 steps (4/5) Define the listener to logged calls, it initialize the connector, perform the call and add the caller to the hash map (@param e ServerSideCallEvent) private function onLoggedCall(e:ServerSideCallEvent):void{ try{ obj = sc.makeLoggedCall(e.fakeObject as RemoteMethod); hash.addItem({service: obj, target: IPresenter(e.target), nameSpace: e.nameSpace}); }catch(err:Error){ Alert.show(quot;You need to be logged on the systemquot;, quot;Attention!quot;); } }
  40. 40. The ServiceConnector in 5 steps (5/5) • Define the Listener to the general result event, it's able to update the UI component that performed the request (@param e RemoteObjectWrapperEvent) private function onResult(e:RemoteObjectWrapperEvent):void{ var tg:IPresenter; if(hash.getItem(quot;servicequot;, e.currentService)){ tg = hash.getItem(quot;servicequot;, e.currentService).target as IPresenter; var ns:Namespace; if(hash.getItem(quot;servicequot;, e.currentService).nameSpace){ ns = hash.getItem(quot;servicequot;, e.currentService).nameSpace; } tg.setDataSet(e.eventData, ns); hash.remove(quot;servicequot;, e.currentService); }}
  41. 41. How to put everything in action • Use the Model View Presenter for your component • Make a comparison between Model View Presenter and Model View Controller • Understand why in an UI context the MVP is the best choice with external data • Make a simple implementation
  42. 42. The MVP pattern • The original implementation of the MVP is born in the 1979, its name was Thing Model View Editor and during these years there were a lot of different implementations between them the Taligent’s one (1996) was for sure the more sophisticated and the more powerful • The Model-View-Presenter pattern is a variation on the Model- View-Controller pattern, and similarly separates the concerns of an application’s data, presentation, and user input into specialized components
  43. 43. The MVP diagram
  44. 44. The MVP actors • The Model refers to the data and business functionality of the application • Selections are components which specify what portion of the data within the Model is to be operated upon • Commands are classes which define the operations which can be performed on the data • The View is the visual representation of the Model and is comprised of the screens and widgets used within an application • Interactors are classes which address how user events are mapped onto operations performed on the Model • The Presenter is a component which orchestrates the overall interaction of the other components within the application
  45. 45. MVP and MVC (1/2) MVC MVP UI Presentation Pattern focus on Based on MVC (UI Presentation Pattern) separation of view with Model Separation of responsibility between three Separation of responsibility between four components: components: 1. View - responsible for rendering UI 1. View - responsible for rendering UI elements elements 2. Controller - responsible for 2. View Interface - responsible for loose responding to view actions coupling between view and model 3. Model - responsible for business 3. Presenter - responsible for view and behavior and state management model interaction 4. Model - responsible for business behavior and state management
  46. 46. MVP and MVC (2/2) MVC MVP The three components would interact Presenter can also interact with View to with each other, Controller would access Model sometime also be responsible to update view (like Front Controller Pattern) Controller is behavior based and Usually one view have one presenter multiple views can share single controller (1-1 mapping), multiple presenters would be associated with a complex view Identifies which view to update Presenter will update its associated view
  47. 47. Let’s start with a demo!
  1. A particular slide catching your eye?

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

×