9.5. Extending the Messaging Adapter

The ActionScriptAdapter is the simplest of the built-in messaging adapters. It extends the MessagingAdapter abstract class.

Almost all of the functionality in the ActionScriptAdapter class resides in its invoke method. In its invoke method, an ActionScriptAdapter uses a MessageService instance that takes control of the message delivery to all connected clients and server peers. In the invoke method, a call is made to the MessageService's pushMessageToClients method, which sends a message to all connected clients within a local node of a cluster. In addition, the MessageService instance's sendPushMessageFromPeer method is invoked to send messages to the peer servers in the cluster. These servers, in turn, deliver the message to their connected clients.

In this section, let's create another simple messaging adapter like the ActionScriptAdapter. In the custom adapter, I continue to send messages the way the ActionScriptAdapter does. The only modifications I make are:

  • Modify the message body and add the text "Before message body" and "After message body" to the existing message body

  • Add a header named "interceptor" with "CustomActionScriptAdapter" as the value to the message

The source for CustomActionScriptAdapter is shown in Listing 9-3.

Example 9.3. CustomActionScriptAdapter Source
package dsadapters.messaging.adapters.as3; import flex.messaging.messages.AsyncMessage; import flex.messaging.messages.Message; import flex.messaging.services.MessageService; ...

Get Professional BlazeDS: Creating Rich Internet Applications with Flex® and Java® 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.