O'Reilly logo

Agile Enterprise Application Development with Flex by Tony Hillerson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required