Professional Documents
Culture Documents
CONTENTS INCLUDE:
n
About BlazeDS
BlazeDS
n
What Exactly is BlazeDS?
Structural Definition
ABOUT BLAZEDS BlazeDS is a:
• Java web application that leverages the Java Servlets
Adobe BlazeDS is an open source software that facilitates specification.
effective integration of Flex and Java. It enables remote • Web application that runs within a Java Servlet container
procedure calls and message exchanges between the two or a Java application server, for example Apache Tomcat,
platforms thereby helping couple together rich and engaging JBoss AS, IBM Websphere or BEA (now Oracle) Weblogic.
Flash platform based interfaces and robust enterprise servers. • Set of services that can be managed using JMX agents.
Being open source, BlazeDS is freely available and can be • Remoting and messaging program that can be extended
downloaded from by using its Java API.
http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/. • Program that intercepts all communication between a
This Refcard provides a quick overview of BlazeDS. It attempts Flash Player and a Java server.
to illustrate some of the most important features of the • Configurable web application that can be clustered and
software and therefore acts as a starting point for developers used in cases that desire a higher than normal
who are interested in the subject. More details, with exhaustive performance. (The in-built data push mechanism has a few
sets of examples, are available in the book Professional limitations as far as high throughput and high volume
BlazeDS (Wiley/Wrox, 2009). goes but there are ways to get around this shortcoming.)
Behavioral Definition
BlazeDS enables and facilitates:
• Invocation of remote Java methods from a Flex
application.
• Translation of Java objects returned from a server, in
response to the remote method call, to corresponding
AS3 objects.
• Translation of AS3 objects sent by a Flex application to
corresponding Java objects for passing them in as method
call arguments.
• Communication between a Flash Player instance and
a Java server over a TCP/IP-based application-level binary
Getting Started with BlazeDS
protocol.
• Near real-time message passing between a Flex
application and a Java server.
• Management of the communication channels between
Flex and Java.
• Management of connection types between Flex and Java.
• Provision for adapters for communication with server-
side Java artifacts like JMS queues, and persistence layers
like Hibernate and JPA. (Some of these are in-built, and
some can be obtained from open source projects or can
be custom built.)
• Pushing data from the server to the client on the server’s
initiative and not as a response to a request.
BlazeDS based message services leverage two types of built-in objects to their AS3 counterparts so that may make you
adapters, namely: wonder why wiring up JPA and Hibernate entities and their
collections needs any special handling. The reason for this
• JMSAdapters special need arises because of the way BlazeDS serializes data
• ActionScriptAdapters across the wire.
The JMSAdapter connects with JMS server side messaging BlazeDS has a set of endpoints where a Flex application
systems. The ActionScriptAdapter helps route messages channel sends requests up to BlazeDS that resides within
between Flex clients via the server. Therefore JMSAdapter a Servlet container or an application server. Responses
comes handy when Flex clients are wired up to send and from BlazeDS follow the route back up from the endpoint
receive messages to and from enterprise systems that use JMS, to the channel. On endpoints that support translation and
whereas ActionScriptAdapter is useful for building systems serialization between AS3 and Java (or even web services), a
like chat applications to help communicate between two Flex serialization filter is defined to intercept calls to the endpoint.
clients. When an incoming or outgoing message hits the filter,
For effective near real-time messaging use one of the following serialization and deserialization occur. During serialization, the
channels: serializer eagerly fetches all the JPA and Hibernate persistent
objects and sends them across the wire. The JPA and
AMFChannel/Endpoint with Polling Hibernate proxies are replaced with the data that they stand
The client sends a recurring request to the server at a pre- in place of. This breaks the lazy loading semantics, rendering
defined frequency. Polling is very resource and network the idea of proxies useless. Therefore, any Hibernate adapter
intensive. needs to preserve the proxy characteristics while keeping
AMFChannel/Endpoint with Long Polling the standard behavior of the essential serialization and de-
The channel issues polls to the server to fetch data but if no serialization mechanism between Flex and Java intact.
data is available it waits until data arrives for the client or the
configured server wait interval elapses. For high frequency A common design pattern used to solve this problem is what
updates this configuration has the overhead of a poll roundtrip I like to call the ‘‘Clone and Merge Transfer Pattern.”
for every pushed message and therefore messages can be
queued between polls. The Servlet API, prior to its current
version 3, utilizes blocking I/O in which case long polling soon
exhausts connections as multiple concurrent clients utilize the
channel.
Streaming AMFChannel/Endpoint
This channel opens an HTTP connection between the
server and client, over which the server sends an unending
response of messsages. This channel avoids the overhead of
polling and keeps the connection open for the entire scope
of communication between the client and the server. Like
AMFChannel with long polling, the constraints of blocking
Servlet I/O can exhaust connections as multiple concurrent
clients utilize the channel.
A MessageBroker component sits at the heart of BlazeDS. All side message services in Spring BlazeDS are:
messages in BlazeDS are routed through the MessageBroker. • Native built-in BlazeDS AMF messaging
In standard BlazeDS deployments, the MessageBrokerServlet is • JMS messaging using the Spring-spec JMS
declared in WEB-INF/web.xml as follows: components
<servlet>
• Spring BlazeDS messaging integration
<servlet-name>MessageBrokerServlet</servlet-name>
<servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
<init-param> EXTENDING BLAZEDS
<param-name>services.configuration.file</param-name>
<param-value>/WEB-INF/flex/services-config.xml</param-value>
</init-param>
<init-param>
<param-name>flex.write.path</param-name> BlazeDS exposes a public Java API. You can leverage that API
<param-value>/WEB-INF/flex</param-value>
</init-param> to customize the behavior of BlazeDS resources.
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping> The flex.messaging.services.ServiceAdapter abstract class
<servlet-name>MessageBrokerServlet</servlet-name>
<url-pattern>/messagebroker/*</url-pattern> sits at the root of the hierarchy. All built-in adapter classes
</servlet-mapping>
inherit from the ServiceAdapter abstract class. Abstract
classes not only define a contract like interfaces do but also
In Spring MVC, all incoming requests are handled by a Front
define behavior through partial method implementations. The
controller Servlet, called the DispatcherServlet. This means
ServiceAdapter class states the base behavioral characteristics
you must have a way that all requests coming from the Flex
of a BlazeDS adapter.
client and intended to be handled by the BlazeDS instance are
routed by the DispatcherServlet to the MessageBroker. This is You can create custom BlazeDS adapters by extending
exactly what the Spring BlazeDS project implements. either the ServiceAdapter or one of its subclasses like the
JavaAdapter or the MessagingAdapter classes.
In addition, the Spring BlazeDS project also defines an XML
Schema and associated infrastructure so that BlazeDS artifacts
can be configured within Spring configuration files as Spring
MAKING BLAZEDS APPLICATIONS SCALABLE
managed objects.
In web scale applications scalability is an important criteria for
As an example a default BlazeDS message broker configuration
success. BlazeDS instances can be clustered and the following
can then be like so:
techniques can be applied to make applications scale better:
<?xml version=”1.0” encoding=”UTF-8”?>
<beans xmlns=”http://www.springframework.org/schema/beans” Clustering
xmlns:flex=”http://www.springframework.org/schema/flex”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” Clustered instances of BlazeDS share data and messages
xsi:schemaLocation=”
http://www.springframework.org/schema/beans across instances. Therefore, message producers connected
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/flex to a clustered server instance can send messages to message
http://www.springframework.org/schema/flex/spring-flex-1.0.xsd”>
<flex:message-broker/> consumers connected to a different server within the same
</beans>
cluster. Besides sharing state information and routing
More about the possible configurations can be learned online information through the clustered servers, clustering provides
at http://www.springsource.org/spring-flex for channel failover support. Clustered of BlazeDS instances is
powered by JGroups.
With the help of this project it becomes easy to configure
Spring Beans as server side remoting counterparts of Flex Data compression
clients. BlazeDS is a Java Servlets based web application. As data
from a BlazeDS server leaves for the Flex client, it can be
For example a service class configured as a Spring Bean as intercepted using the familiar Java Servlet filter mechanism.
follows: Servlet filters can intercept requests to and responses from
<bean id=”myService” class=”myPackage.MyService” />
a Java Servlet. In order to zip the data transferred from the
server to the client, a filter can be created to manipulate and
Can easily be used as a remoting destination simply by compress the outgoing response.
specifying a configuration as follows:
Data format optimization
<flex:remoting-destination ref=”myService” />
AMF3 facilitates a very efficient way of binary transmission
There is plenty more, including use of annotations, possible of data between the server and the client. In addition, you
for configuring Spring Beans as remoting destinations and you can choose to go with a text-based format that could be well
may want to learn more online from the Spring BlazeDS project structured like XML or delimited like comma-separated or tab-
site mentioned earlier in this paragraph. delimited text. JSON (JavaScript Object Notation) and AMFX,
where AMF is transmitted in XML, are also options.
Besides, remoting the Spring messaging and security benefits
also get extended to Flex applications. In a Spring BlazeDS Robust connection
server, three types of message service components can interact Non-blocking channels allow for greater number of
with the Flex message service. The messaging service in Flex connections to be served provided they are not all active at the
itself is agnostic to the messaging protocol used on the server same time always. Life Cycle Data Services uses NIO channels
side. Therefore, multiple server-side messaging alternatives for connection scalability. You can include the same robustness
easily work with Flex messaging. The three alternative server- in BlazeDS as well.
Service orientation are pooled, they are shared over multiple clients. BlazeDS has
Service oriented architecture (SOA) patterns that apply well acces to all resource pooling strategies that any Java EE web
when creating Flex and BlazeDS applications are: application running in an application server has.
• Concurrent contracts
Workload distribution
• Cross-domain utility layer
Distributing work optimally between a client and its server
• Functional decomposition
is an important challenge when architecting RIA. BlazeDS
• Rules centralization
remoting services optimally combine a Flex client and a Java
• State repository
server and allow a developer to distribute workload across the
Caching wire in ways without necessarily imposing the overheads that
If the accessed data is not changing during the course of its loose coupling like XML based interactions over HTTP and
reuse it always makes sense to cache it. Caching is a time- web services do.
tested way of increasing performance by avoiding data fetches
across the network and using pre-fetched local data instead. CONCLUSION
Resource Pooling
Many of these external systems and libraries, such as With no upfront costs and a great set of features BlazeDS is
messaging infrastructure, database connections and stateless a compelling piece of software for most serious Rich Internet
business services, lend themselves to pooling. When resources Application (RIA) stacks that involve Flex and Java.
Bro
ugh
t to
you
by...
Professional Cheat Sheets You Can Trust
tt erns “Exactly what busy developers need:
n Pa
ld
ona
sig son
McD
simple, short, and to the point.”
De
Ja
By
#8
ired
Insp e
by th
GoF ller con
tinu
ed
ndle
r doe
sn’t
have
to
in tab
Cha d ultip ecific o should cep pat
this if the m up the
man
n M
an ac
z.co
n
sp s ents
be a ject ime. d is see passed
Download Now
Com reter of ob at runt handle plem ks to de to
...
n
uest som tion proces e no m
Itera tor ore req
n A g in metho
d
cep
dm ndlin
e e ar
tho e to ptio th
Exce ion is sm to ha up th tered or
e ca
n
Ob
se Me S renc ral
Refcardz.com
plate RN refe listed in mp
le ce pt ni
echa n pa ssed co un avio
Beh
TTE
n
ex
is en
ick
Virtualization Windows Powershell
am
Tem Exa he .
A s has ack. W tion uest to ject
NP a qu s, a ct- cep Ob
it
n
st q
IG e s e rn b je call e ex e re
vid patt able O le th nd th
DES
! V is
pro s, hand s to ha
UT ard ign us ram .
des diag
Java Performance Tuning Dependency Injection with EJB 3
ct
ABO refc oF) f Re le obje
erns ts o lass exa
mp oke
r
Patt ur (G lemen es c Inv
arz
n F o d rl d h
Des
ig go
f s: E inclu al w
o suc
Th is G a n
l 23 sign Pa
tt e rn e rn
patt , and a
re je ts
t ob mentin
c g AN
D
Expression Web Netbeans IDE JavaEditor
c
a h c M M
ef
in c u
orig kD
e
re.
Ea tion ons
tr ple CO ma
nd
boo Softwa rma to c their im om
Spring Web Flow Getting Started with Eclipse
re R
( low
e x p o n la rg cute is al ch
ati an b rm ts. +exe . Th
bject nship
s su
Cre y c fo je c an o
t th
e
ed
to ob ms, d as ed rela
tio
Get
Suite 100
st que e th itho
n
eals
it
ship Reque y of re de ar
ld be litat pattern ssing w tation articul
e: D tion faci
50795
or
e. Use
n
A hist shou d ce en p
rela ed to mman for pro implem ents its ting.
t S cop runtim s s to type Whe
n
e invo
ker
el y us e co
n
ue al le m pec
jec at cla Pro Th w id th
are utilizing a job q of the
ue ac tu
d im
p
ue is
ex
Ob ged with
n
C ues ueue e que
b e c han
cop
e : D eals me.
pile
ti
rato
r S
P roxy
er mp
le
que
g
s. B
n
y
en to
Job orithm be giv knowle that is terface
of al ed ca to have d obje of the
dge
ct
enq
in
th
Cary, NC 27513
ss S at com Deco serv Exa ut an nes
.com
Abst tory
C C
Fac
B
State
t
pte
r eigh y
Ada Flyw Stra
teg
od
919.678.0300
z
Meth
more than 3.3 million software developers, architects and decision
S S r B
w. d
e rp rete plate
B ridg Inte Tem
S B B
er tor or
ww
C B r B
NSIB
ILIT
Y B
Com
po si te
PO succ
ess
or 9 781934 238905
Sponsorship Opportunities
S
ES
FR
“DZone is a developer’s
CH
AIN
O
dream,” says PC Magazine. >>
terf r
<<in andle
H
ace
st ( )
sales@dzone.com
Copyright © 2009 DZone, Inc. All rights reserved.
Clie
nt
No part of this publication
dle
r2
d lere
que
may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical,
+ha
n
Version 1.0
Han
photocopying, or otherwise, without prior written permission Cof the
oncr
ete publisher.
que
st ( )
s
re
ndle
+ha
ern
1 ki ng
ler by lin .c o
m
and uest one
teH req z
cre () le a w.d
Con uest hand | ww