Sending the Client’s Heartbeats
To send the client’s heartbeats, you need a class to represent the heartbeat and a producer to perform the sending.
The heartbeat message object will leverage available Flex/Java
serialization—therefore, you’ll need to come up with a pair of almost
identical classes: one in Java and the other one in ActionScript. The
corresponding classes are presented in Examples 5-1 and
5-2. Notice the array received
, which will eventually carry delivery
confirmations of the latest received messages.
Example 5-1. ClientHeartbeatMessage.as
package com.farata.messaging.messages { import mx.messaging.messages.AbstractMessage; [RemoteClass(alias="com.farata.messaging.messages.ClientHeartbeatMessage")] public class ClientHeartbeatMessage extends mx.messaging.messages.AbstractMessage { public var received:Array; //Messages arrived since last heartbeat public function ClientHeartbeatMessage() { super(); //TODO - populate array "received" - later... } } }
Example 5-2. ClientHeartbeatMessage.java
package com.farata.messaging.messages; import flex.messaging.messages.AbstractMessage; public class ClientHeartbeatMessage extends AbstractMessage { public String[] received; // Array of <ClientID>|<MsgNumber> strings }
To periodically send the heartbeat message (Example 5-1) up to the server you need a Flex
Producer
class powered with a Timer
. Example 5-3 illustrates the custom ClientHeartbeatProducer
class with the
startHeartbeat()
and stopHeartbeat()
methods. By default, the heartbeat ...
Get Agile Enterprise Application Development with Flex now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.