nick kwiatkowski - flex, cf, and lcds magic

35
ColdFusion, LCDS and Flex Magic Nick Kwiatkowski Michigan Flex Users Group & Michigan State University

Upload: 360conferences

Post on 20-May-2015

697 views

Category:

Technology


1 download

DESCRIPTION

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.

TRANSCRIPT

Page 1: Nick Kwiatkowski - Flex, CF, and LCDS Magic

ColdFusion, LCDS and Flex Magic

Nick KwiatkowskiMichigan Flex Users Group& Michigan State University

Page 2: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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

Page 3: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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?

Page 4: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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

Page 5: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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.

Page 6: Nick Kwiatkowski - Flex, CF, and LCDS Magic

The Convoluted Mess of Stuff™

Brow

ser

Flex or AJAXapplication

AIRApplication

LiveCycle DS

Java

ColdFusion

.NET

Data

Presentation Layer Business Layer Data-Access Layer

PHP

Page 7: Nick Kwiatkowski - Flex, CF, and LCDS Magic

The Convoluted Mess of Stuff™

Brow

ser

Flex or AJAXapplication

LiveCycle DS

ColdFusion

Data

Presentation Layer Business Layer Data-Access Layer

Page 8: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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.

Page 9: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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!)

Page 10: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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.

Page 11: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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.

Flex Client LDSApp Server

Page 12: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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

AJAX Client

Flex Client

LDS App Server

Page 13: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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.

Flex Client LDS

Web Service

App Server

Page 14: Nick Kwiatkowski - Flex, CF, and LCDS Magic

DATA MANAGEMENT EXAMPLE

Page 15: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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.

Page 16: Nick Kwiatkowski - Flex, CF, and LCDS Magic

CODING A FLEX APP

Page 17: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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.

Page 18: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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.

Page 19: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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.

Page 20: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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.

Page 21: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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.

Page 22: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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.

Page 23: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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.

Page 24: Nick Kwiatkowski - Flex, CF, and LCDS Magic

The “Secret Sauce”

• Your configuration files are located at :– <ColdFusion Root>\wwwroot\WEB-INF\Flex\

• 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

Page 25: Nick Kwiatkowski - Flex, CF, and LCDS Magic

DIVING INTO THE CONFIGURATION FILES

Page 26: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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

Page 27: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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.

Page 28: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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

Page 29: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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)

Page 30: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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.

Page 31: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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.

Page 32: Nick Kwiatkowski - Flex, CF, and LCDS Magic

CODING THE COLDFUSION CODE

Page 33: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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!)

Page 35: Nick Kwiatkowski - Flex, CF, and LCDS Magic

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