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

Resending Messages with QoSAdapter

We have completed the first half of the exercise, in which the heartbeats travel with delivery confirmations via the AcknowledgingRTMPChannel. The other half of the solution is:

  • To accumulate the delivery confirmations coming from the client with each heartbeat. This will be done in the QoSAdapter.java adapter.

  • Upon certain timeout, resend unconfirmed messages to the client. This task requires an additional Java resender thread, started in QoSAdapter.java.

To figure out on the server which messages were confirmed, we need to keep all unconfirmed messages in a safe place—the unconfirmedMessageMap in the QoSAdapter:

 static {
  unconfirmedMessageMap =
      new ConcurrentHashMap<String, ReliableServerMessage>();
}

The data type of this Java map is ConcurrentHashMap, which is a HashMap that supports concurrent data updates; this is essential in situations in which confirmations can arrive from multiple clients but will all be stored in the same map.

Accordingly, in Example 5-11, the invoke() method puts every ReliableServerMessage into the map via a registerForDeliveryConfirmation() call.

We also want to emulate the loss of messages on the server by marking about 20 percent (the function Math.random() takes care of it) with the header property tm for “test mode.”

Example 5-11. Method invoke() of QoSAdapter.java

public Object invoke(Message message){ isDebug = logger.isDebugEnabled(); if ( message instanceof ReliableServerMessage ) { registerForDeliveryConfirmation((ReliableServerMessage)message); ...

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