org.ws4d.java.dispatch
Class MessageInformer

java.lang.Object
  extended by org.ws4d.java.dispatch.MessageInformer

public class MessageInformer
extends java.lang.Object

This class is the place to register listeners for messages crossing the DPWS framework. This is especially useful for clients interested in receiving specific types of messages or for traffic analyzers willing to get notified about each DPWS message sent or received.

When registering, a listener can declare its interest for certain messages by passing a MessageSelector to the method addMessageListener(MessageListener, MessageSelector). The MessageSelector's MessageSelector.matches(Message) method is used to determine whether a given message matches this interest or not. The DPWS framework provides two standard implementations of MessageSelector: AllMessageSelector, which simply marks every message as interesting, and DefaultMessageSelector allowing discrimination based on a message's type and/or its target endpoint address (i.e. the WS-Addressing [destination] property of the message).


Method Summary
 void addMessageListener(MessageListener listener, MessageSelector sel)
          Adds the specified message listener to this message informer.
 void forwardMessage(Message msg, ProtocolData protocolData)
          Forwards a single message to all registered listeners.
static MessageInformer getInstance()
          Returns the singleton instance of this class.
 MessageListener[] getMessageListeners()
          Returns an array containing all currently registered message listeners.
 void removeMessageListener(MessageListener listener)
          Removes the specified message listener, if it was previously registered within this message informer.
 void start()
          Starts the message delivery loop of this message informer instance.
 void stop()
          Stops the message informer, i.e. terminates the message delivery loop.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static MessageInformer getInstance()
Returns the singleton instance of this class.

Returns:
the singleton message informer

start

public void start()
Starts the message delivery loop of this message informer instance. Does nothing, if the message informer is already running.


stop

public void stop()
Stops the message informer, i.e. terminates the message delivery loop.


addMessageListener

public void addMessageListener(MessageListener listener,
                               MessageSelector sel)
Adds the specified message listener to this message informer. The listener will receive notifications about messages running through the DPWS framework that match the specified message selector. If sel is null, the listener will be registered with an AllMessageSelector associated to it and thus will receive notifications about every message.

Parameters:
listener - the listener to register
sel - the selector determining which messages to deliver to the newly registered listener

removeMessageListener

public void removeMessageListener(MessageListener listener)
Removes the specified message listener, if it was previously registered within this message informer.

Parameters:
listener - the listener to remove

getMessageListeners

public MessageListener[] getMessageListeners()
Returns an array containing all currently registered message listeners.

Returns:
an array consisting of all currently registered listeners

forwardMessage

public void forwardMessage(Message msg,
                           ProtocolData protocolData)
Forwards a single message to all registered listeners.

Parameters:
msg - the message to forward
protocolData - transport-specific addressing information attached to the message