flex.messaging.services
Class MessageService

java.lang.Object
  extended by flex.management.ManageableComponent
      extended by flex.messaging.services.AbstractService
          extended by flex.messaging.services.MessageService
All Implemented Interfaces:
Manageable, FlexComponent, FlexConfigurable, Service

public class MessageService
extends AbstractService

The MessageService class is the Service implementation that manages point-to-point and publish-subscribe messaging.


Field Summary
static String LOG_CATEGORY
          Log category for MessageService.
static String TIMING_LOG_CATEGORY
          Log category for MessageService that captures message timing.
 
Fields inherited from class flex.messaging.services.AbstractService
LOG_CATEGORY_STARTUP_DESTINATION
 
Constructor Summary
MessageService()
          Constructs an unmanaged MessageService.
MessageService(boolean enableManagement)
          Constructs an MessageService with the indicated management.
 
Method Summary
 void addDestination(Destination destination)
          Casts the Destination into MessageDestination and calls super.addDestination.
 Destination createDestination(String id)
          Creates a MessageDestination instance, sets its id, sets it manageable if the AbstractService that created it is manageable, and sets its Service to the AbstractService that created it.
 Set getSubscriberIds(Message message, boolean evalSelector)
          Returns a Set of clientIds of the clients subscribed to receive this message.
 Set getSubscriberIds(String destinationId, String subtopicPattern, Map messageHeaders)
          Returns the set of subscribers for the specified destination, subtopic/subtopic pattern and message headers.
 void initRemoteSubscriptions(String destinationId)
          Issue messages to request the remote subscription table from each server in the cluster (except this one).
 void pushMessageToClients(Message message, boolean evalSelector)
          Pushes a message to all clients that are subscribed to the destination targeted by this message.
 void pushMessageToClients(Set subscriberIds, Message message, boolean evalSelector)
          This method is not invoked across a cluster, it is always locally invoked.
 void sendPushMessageFromPeer(Message message, boolean evalSelector)
          This method sends the passed message to clients connected to other server peer nodes in the cluster.
 Object serviceMessage(Message message)
          Processes messages by invoking the requested destination's adapter.
 void serviceMessageFromAdapter(Message message, boolean sendToAllSubscribers)
          This method is called from a messaging adapter to handle the delivery of messages to one or more clients.
 void start()
          Starts the service if its associated MessageBroker is started.
 void subscribeFromPeer(String destinationId, Boolean subscribe, String selector, String subtopic, Object remoteAddress)
          This is called remotely from other cluster members when a new remote subscription is identified.
 
Methods inherited from class flex.messaging.services.AbstractService
addDefaultChannel, describeService, getDefaultAdapter, getDefaultChannels, getDestination, getDestination, getDestinations, getMessageBroker, getRegisteredAdapters, registerAdapter, removeDefaultChannel, removeDestination, serviceCommand, setDefaultAdapter, setDefaultChannels, setId, setMessageBroker, stop, unregisterAdapter
 
Methods inherited from class flex.management.ManageableComponent
getControl, getId, getParent, initialize, isManaged, isStarted, isValid, setControl, setManaged, setParent
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface flex.messaging.services.Service
getId
 
Methods inherited from interface flex.management.Manageable
getControl, isManaged, setControl, setManaged
 
Methods inherited from interface flex.messaging.FlexComponent
isStarted
 
Methods inherited from interface flex.messaging.FlexConfigurable
initialize
 

Field Detail

LOG_CATEGORY

public static final String LOG_CATEGORY
Log category for MessageService.

See Also:
Constant Field Values

TIMING_LOG_CATEGORY

public static final String TIMING_LOG_CATEGORY
Log category for MessageService that captures message timing.

See Also:
Constant Field Values
Constructor Detail

MessageService

public MessageService()
Constructs an unmanaged MessageService.


MessageService

public MessageService(boolean enableManagement)
Constructs an MessageService with the indicated management.

Parameters:
enableManagement - true if the MessageService is manageable; otherwise false.
Method Detail

start

public void start()
Description copied from class: AbstractService
Starts the service if its associated MessageBroker is started. and if the service is not already running. The default implementation of this method starts all of the destinations of the service. If subclasses override, they must call super.start().

Specified by:
start in interface FlexComponent
Overrides:
start in class AbstractService

createDestination

public Destination createDestination(String id)
Creates a MessageDestination instance, sets its id, sets it manageable if the AbstractService that created it is manageable, and sets its Service to the AbstractService that created it.

Specified by:
createDestination in interface Service
Overrides:
createDestination in class AbstractService
Parameters:
id - The id of the MessageDestination.
Returns:
The Destination instanced created.

addDestination

public void addDestination(Destination destination)
Casts the Destination into MessageDestination and calls super.addDestination.

Specified by:
addDestination in interface Service
Overrides:
addDestination in class AbstractService
Parameters:
destination - The Destination instance to be added.

serviceMessage

public Object serviceMessage(Message message)
Description copied from class: AbstractService
Processes messages by invoking the requested destination's adapter. Subclasses should provide their implementation.

Specified by:
serviceMessage in interface Service
Specified by:
serviceMessage in class AbstractService
Parameters:
message - The message sent by the MessageBroker.
Returns:
The result of the service.

serviceMessageFromAdapter

public void serviceMessageFromAdapter(Message message,
                                      boolean sendToAllSubscribers)
This method is called from a messaging adapter to handle the delivery of messages to one or more clients. If you pass in the sendToAllSubscribers parameter as true, the message is routed to all clients who are subscribed to receive messages from this destination. When you use this method, the selector expressions for all subscribing clients are not evaluated. If you want the selector expressions to be evaluated, use a combination of the pushMessageToClients method and the sendPushMessageFromPeer methods.

Parameters:
message - The Message to send.
sendToAllSubscribers - If true, send this message to all clients subscribed to the destination of this message. If false, send the message only to the clientId specified in the message.

sendPushMessageFromPeer

public void sendPushMessageFromPeer(Message message,
                                    boolean evalSelector)
This method sends the passed message to clients connected to other server peer nodes in the cluster. If you are using broadcast cluster-messaging-routing mode, the message is broadcast through the cluster. If you are using the server-to-server mode, the message is sent only to servers from which we have received a matching subscription request.

Parameters:
message - The Message to push to peer server nodes in the cluster.
evalSelector - true to evaluate each remote subscriber's selector before pushing the message to them; false to skip selector evaluation.

pushMessageToClients

public void pushMessageToClients(Message message,
                                 boolean evalSelector)
Pushes a message to all clients that are subscribed to the destination targeted by this message.

Parameters:
message - The Message to push to the destination's subscribers.
evalSelector - true to evaluate each subscriber's selector before pushing the message to them; false to skip selector evaluation.

getSubscriberIds

public Set getSubscriberIds(Message message,
                            boolean evalSelector)
Returns a Set of clientIds of the clients subscribed to receive this message. If the message has a subtopic header, the subtopics are used to gather the subscribers. If there is no subtopic header, subscribers to the destination with no subtopic are used. If a subscription has a selector expression associated with it and evalSelector is true, the subscriber is only returned if the selector expression evaluates to true.

In normal usage, you can use the pushMessageToClients(message, evalSelector) method to both find the subscribers and send the message. You use this method only if you want to do additional processing to the subscribers list - for example, merging it into another list of subscribers or logging the ids of the subscribers who should receive the message. Once this method returns, you can use the pushMessageToClients variant which takes the set of subscriber ids to deliver these messages.

This method only returns subscriptions maintained by the current server instance. It does not return any information for subscribers that might be connected to remote instances. To send the message to remotely connected servers, use the sendPushMessageFromPeer method.

Parameters:
message - The Messsage Typically

getSubscriberIds

public Set getSubscriberIds(String destinationId,
                            String subtopicPattern,
                            Map messageHeaders)
Returns the set of subscribers for the specified destination, subtopic/subtopic pattern and message headers. The message headers can be null. If specified, they are used to match against any selector patterns that were used for subscribers.


pushMessageToClients

public void pushMessageToClients(Set subscriberIds,
                                 Message message,
                                 boolean evalSelector)
This method is not invoked across a cluster, it is always locally invoked. The passed message will be pushed to the subscribers in the passed set, conditionally depending upon the execution of their selector expressions.

Parameters:
subscriberIds - The set of subscribers to push the message to.
message - The Message to push.
evalSelector - true to evaluate each subscriber's selector before pushing the message to them; false to skip selector evaluation.

initRemoteSubscriptions

public void initRemoteSubscriptions(String destinationId)
Issue messages to request the remote subscription table from each server in the cluster (except this one).


subscribeFromPeer

public void subscribeFromPeer(String destinationId,
                              Boolean subscribe,
                              String selector,
                              String subtopic,
                              Object remoteAddress)
This is called remotely from other cluster members when a new remote subscription is identified. We add or remove a remote subscription...



Copyright © 2008 Adobe Systems Inc. All Rights Reserved.

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/blazeds/1/javadoc/flex/messaging/services/MessageService.html