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 ReliableServer
Message
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); ...
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.