Learn how to use Flex and AIR with LiveCycle Data Services and ColdFusion. We will demonstrate using LCDS’s powerful Data Management features to push data into our Flex application from both databases and other sources available to ColdFusion in real time. This session will focus on ActionScript and ColdFusion programming, so intermediate experience in both of these is assumed.
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Nick Kwiatkowski - Flex, CF, and LCDS Magic
1. ColdFusion, LCDS and Flex
Magic
Nick Kwiatkowski
Michigan Flex Users Group
& Michigan State University
2. About Me
• Manager of the Michigan Flex Users
Group
• Work at Michigan State University, as a
Telecom Manager
• Active member of the Flex and ColdFusion
communities
• Avid mountain biker, general technology
evanglist
3. So, magic you say?
• What if I told you that after the initial setup,
you only had to use 4 lines of code to get
data from your application server to your
clients?
– Sure, we’ve all seen the demo before, but do
you really know how it works?
» Ok… well, maybe a bit more than 4 lines of code, but
well, 4 lines of code sounds sooo easy, you know?
4. The moving parts
• ColdFusion – This setup will work with
Adobe ColdFusion (sorry, other vendors
don’t work out of the box) versioned 7 and
above. Version 8+ can have LCDS baked
in.***
• LCDS – LiveCycle Data Services is a
middleware application designed to move
and manage large amounts of data.
*** I can’t control what they do with ColdFusion “Next” but one
would assume they won’t remove this
5. The moving parts
• Flex – Any version of the Flex SDK over
2.0.0 will work.
• Data – Any serializable data, including
data from Databases, LDAP, email, FTP,
Mapping software, web services, etc.
6. The Convoluted Mess of Stuff™
Browser Java
Flex or AJAX
application ColdFusion
LiveCycle DS Data
AIR .NET
Application
PHP
Presentation Layer Business Layer Data-Access Layer
7. The Convoluted Mess of Stuff™
Browser
Flex or AJAX
application ColdFusion
LiveCycle DS Data
Presentation Layer Business Layer Data-Access Layer
8. LCDS
• But, isn’t LiveCycle Data Services really,
really expensive?
– Yes, and no. There are three versions of
LCDS you need to worry about:
• BlazeDS – Open-sourced version of LCDS. Does
not include Data Management feature we will be
talking about
• LiveCycle Data Services ES – J2EE application
that Adobe sells that includes all the features of
BlazeDS, plus DM, NIO messaging, etc.
9. LCDS
– LiveCycle Data Services ES Single-CPU
License. (formerly LCDS Express Edition)
• Free version of LCDS, that works on 1-CPU, and
will not cluster. Can be used for dev, testing and
production environments.
• Baked right into the ColdFusion 8 download and
install. (default is to install it!)
10. Data Management
• But, I heard that Flex SDK “Next” will be
offering client-side data management!
Why should I care about this?
– Client-side data management is great for
small bits of data, but not much else.
– Cannot do things like Data Synchronization,
Data Caching, and Conflict Resolution.
11. What LDS brings to the table…
• Data Management
– Have your application server send large
amounts of data to LDS, and let it worry about
passing it to the client. This includes
pagination of data, and data synchronization.
App Server
Flex Client LDS
12. What LDS brings to the table…
• Data Messaging
– Allows Flex clients to communicate with each
other without tying up resources on the App
server (the App server can participate in these
conversations)
Flex Client
LDS App Server
AJAX Client
Flex Client
13. What LDS brings to the table…
• Data Proxying:
– You can proxy your web-service or Remoting
calls through your LDS to help get around
restrictions in firewalls or policies.
Web Service
Flex Client LDS
App Server
15. Coding The Flex Side
• On the Flex side of this setup, there really
isn’t a whole lot to do…
– Create a new Collection (ArrayCollection) to
store your data
– Create a value object so that the data
serializes properly (you will need to instantiate
a copy of this VO, so the compiler includes it)
– Utilize the DataService MXML tag, and call
the fill(collection) function.
17. Why it works
• Data is packaged up
into ‘Value Objects’,
or packages of data.
– This usually consists
of a “row” of data from
a database
• Each VO is tracked
separately as to who
is viewing, editing,
etc.
18. Why it works
• Users then Subscribe
to a set of data.
– LDS will then keep
track of the state of
that data, and send it
from the Application
Server to the Flex
Application.
• LDS will ‘listen’ to any
changes made to the
data in the Flex
Client.
19. Why it works
• If the Collection that
holds the data is
changed in the client,
LDS will take that
change, change the
Value Object in
memory, send the
change to the App
server, and update all
clients in real-time.
20. Why it works
• When an update is
sent to the other
clients, it will check its
local copy, to make
sure that record has
not changed. If it has,
it will issue a
“Conflict” event, and
allow the Client to
choose what to do.
21. Why it works
• On the Client, 95% of
your work is handled
by any of the
Collection classes,
such as the
ArrayCollection
• Handles updating
LDS with Changes,
and notifying other
visual components of
changes.
22. Why it works
• When a DataGrid, or
InputBox broadcast
the Change event, the
ArrayCollection hears
it, and updates its
own data, and passes
the change to other
components that
subscribe to its
change event.
23. The “Secret Sauce”
• One of the more complicated, and “black
box” things about LCDS (and BlazeDS for
that matter) is the configuration files.
• The config files define two important
things:
– The Channels – Defines how data flows from
the client to the server
– The Destination – Defines the
‘namespace’ (think URL) for which the clients
are listening.
24. The “Secret Sauce”
• Your configuration files are located at :
– <ColdFusion Root>wwwrootWEB-INFFlex
• The master configuration file is services-
config.xml
– services-config also holds channel info
– messaging-config.xml holds messaging config
– data-management-config.xml holds DM config
– remoting-config.xml holds Flash Remoting
config
26. Channels? Destinations?
• There are lots of channels to choose from,
each with their pluses and minuses.
– AMF channels typically run over HTTP, so are
often not blocked by firewalls.
• Tend to be slower (polling), or designed for one-
time polls.
• Can be combined with HTTPS for security
– RTMP channels run over port 2048
• Real-time, quick, easy.
• Firewalls have been known to block on occasion
27. Channels? Destinations?
• But don’t worry about choosing only a
single channel! You can setup priorities so
that your communication can degrade
gracefully, but not impact client.
– I typically use RTMP -> AMF Polling
• Each destination can define which
channel(s) it wants to use.
• Each destination is just a name – but must
be unique to the server.
28. ColdFusion Fun
• The final part of this puzzle is the
ColdFusion side. While you technically
can use just about any AMF powered
language (PHP, .NET, Java), why would
you?
• There are two aspects to the ColdFusion
code.
– Perform traditional CRUD requests to your
data source
– Allow un-solisited updates to Flex/LCDS
29. Traditional CRUD
• One of the requirements of having LCDS
manage your ColdFusion Data, is a CFC
that can handle basic CRUD requests.
– fill() -- think of this as a “Get all”
– get() -- this is to get a single item
– sync() -- this performs create, delete, update
– count() -- this needs to return the number of
records (for paging, etc)
30. Unsolicited Updates
• One of the coolest features of LCDS
hooked up with ColdFusion and Flex is the
fact you can push out unsolicited updates
to your clients.
– Non-Flex client update data
– Customer buys something from your store –
update your dashboard
– New email comes in.
31. Unsolicited Updates
• Creating Unsolicited updates are pretty
easy… they involve three steps:
– Create a new Event Gateway of type
‘DataManagement’
– Create some sort of Value Object via a
structure or CFC.
• This structure must serialize the same as your
managed data. Use the VO you created for your
CRUD operations!
– Pass this VO to the Event Gateway. The
update will be pushed to your clients.
33. Bringing it all together
• So, now we know how it all works, what
are some good applications?
– CRUD on a database (duh!)
– Directory Watcher (dashboard)
– Collaborative document management
– E-Mail Client with data push
– Collaborative GIS Application (spontaneous
meetups!)
34. You can reach me at nick@theFlexGroup.org
THANK YOU!
35. Obligatory plugs for my peeps
• Interested in Flex, and Live in Michigan?
– http://www.TheFlexGroup.org
– Meets in Lansing, 2nd Thursdays of the Month
• Interested in ColdFusion?
– http://www.coldFusion.org
– Meets in Lansing, 2nd Tuesdays of the Month
• Interested in UX
– http://www.michiganXD.com
– Meets in Grand Rapids, 2nd Tuesday