Guaranteed Delivery of Server Messages

A server can send various types of messages. When a client receives them, we want the client to be able to send back the heartbeat object with delivery confirmations for only some of them, similar to a special treatment that letters with delivery confirmation get in the post office.

Our special messages will be represented by the class ReliableServerMessage; only these types of messages will be acknowledged. Java and ActionScript versions of such a class are shown in Examples 5-7 and 5-8.

Example 5-7. ReliableServerMessage.java

package com.farata.messaging.messages;

import flex.messaging.messages.AsyncMessage;
import flex.messaging.util.UUIDUtils;

public class ReliableServerMessage extends AsyncMessage {

   public ReliableServerMessage(Object body) {
      super();
      this.body = body;
      setMessageId(UUIDUtils.createUUID(false));
      timestamp = System.currentTimeMillis();
   }
}

Example 5-8. ReliableServerMessage.as

package com.farata.messaging.messages {
   import mx.messaging.messages.AsyncMessage;

   [RemoteClass(alias="com.farata.messaging.messages.ReliableServerMessage")]
   public class ReliableServerMessage extends AsyncMessage{
   }
}

The easiest way to identify the server-side outgoing message is by assigning some unique sequence number to its header. Just as a reminder, each AsyncMessage object has a message body and a message header and you are allowed to attach any key/value pairs to its header:

message = new ReliableServerMessage("Server message #" + number); message.setHeader("seqNo", ...

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.