ADK CVS

tryllian.afc.message
Class AbstractMessageDispatcher

java.lang.Object
  extended bytryllian.afc.message.AbstractMessageDispatcher
All Implemented Interfaces:
MessageDispatcher, java.io.Serializable
Direct Known Subclasses:
AFCMessenger

public abstract class AbstractMessageDispatcher
extends java.lang.Object
implements MessageDispatcher, java.io.Serializable

Implementation class used by the agent to dispatch messages to interested listeners (which are usually tasks).
Users of the AFC API will not have to use this class directly.

Since:
2.2
See Also:
Serialized Form

Constructor Summary
AbstractMessageDispatcher()
           
 
Method Summary
 void addCommonMessageHandler(MessageHandler listener)
          Adds a handler that will get notified of all messages received by the agent.
 void addDeliveryReportListener(DeliveryReportListener listener)
          Adds a listener to all delivery reports sent to this agent.
 void addOutgoingMessageListener(OutgoingMessageListener listener)
          Adds a listener to all message that are sent by this agent.
 Conversation createConversation(MessageHandler listener)
          Creates a new Conversation and adds a listener to it.
 java.lang.String createConversationID()
          Creates a unique conversation ID for this agent.
 void dispatch(DeliveryReport report)
          As dispatch for incoming messages, but calling delivery report listeners.
 void dispatch(IncomingMessage message)
          Relays the message to the interested listeners.
 void dispatchMessage(Message areMessage)
          Relays the message to the interested listeners.
 void dispatchReport(Message areMessage)
          Dispatch an incoming message that represents a delivery report.
protected abstract  void doSend(OutgoingMessage message)
          Actually sends the message.
 Conversation getConversationFor(Message message)
          Get the Conversation for this message, if possible.
 java.lang.String getName()
          Returns the name of the agent.
 Conversation getOrCreateConversationFor(Message message)
          Returns the conversation this message is/will be sent in, if initialized; otherwise, create a Conversation, if possible with an ID based on the 'conversation-id' meta field in the message.
protected  void log(java.lang.String message, java.lang.Exception re)
           
 void removeCommonMessageHandler(MessageHandler listener)
          Removes a handler that listens to all messages received by the agent.
 void removeDeliveryReportListener(DeliveryReportListener listener)
          Adds a listener to all delivery reports sent to this agent.
 void removeOutgoingMessageListener(OutgoingMessageListener listener)
          Removes a listener to all message that are sent by this agent.
 void send(OutgoingMessage message)
          Sends a message without using a conversation object.
 void setName(java.lang.String name)
          Sets the name of the agent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface tryllian.afc.message.MessageDispatcher
getMyAddress
 

Constructor Detail

AbstractMessageDispatcher

public AbstractMessageDispatcher()
Method Detail

getName

public java.lang.String getName()
Description copied from interface: MessageDispatcher
Returns the name of the agent. The name is put in the 'nick-name' meta field of all outgoing messages.

Specified by:
getName in interface MessageDispatcher

setName

public void setName(java.lang.String name)
Description copied from interface: MessageDispatcher
Sets the name of the agent. The name is put in the 'nick-name' meta field of all outgoing messages.

Specified by:
setName in interface MessageDispatcher

dispatchMessage

public void dispatchMessage(Message areMessage)
Relays the message to the interested listeners. First, listeners that have subscribed in a certain conversation are called. Then the 'common message handlers' are given the message.


dispatchReport

public void dispatchReport(Message areMessage)
Dispatch an incoming message that represents a delivery report.


dispatch

public void dispatch(IncomingMessage message)
Relays the message to the interested listeners. First, listeners that have subscribed in a certain conversation are called. Then the 'common message handlers' are given the message.


dispatch

public void dispatch(DeliveryReport report)
As dispatch for incoming messages, but calling delivery report listeners.


addCommonMessageHandler

public void addCommonMessageHandler(MessageHandler listener)
Description copied from interface: MessageDispatcher
Adds a handler that will get notified of all messages received by the agent. You would normally subclass ReactiveTask to achieve this.

Specified by:
addCommonMessageHandler in interface MessageDispatcher
Parameters:
listener - object that gets notified of all messages.

removeCommonMessageHandler

public void removeCommonMessageHandler(MessageHandler listener)
Description copied from interface: MessageDispatcher
Removes a handler that listens to all messages received by the agent.

Specified by:
removeCommonMessageHandler in interface MessageDispatcher
Parameters:
listener - object that used to get notified of all messages.

addOutgoingMessageListener

public void addOutgoingMessageListener(OutgoingMessageListener listener)
Description copied from interface: MessageDispatcher
Adds a listener to all message that are sent by this agent. Since these are outgoing messages there is no need to handle them in any way.
Being notified of outgoing messages is typically used for debugging.

Specified by:
addOutgoingMessageListener in interface MessageDispatcher
Parameters:
listener - the OutgoingMessageListener to be added

removeOutgoingMessageListener

public void removeOutgoingMessageListener(OutgoingMessageListener listener)
Description copied from interface: MessageDispatcher
Removes a listener to all message that are sent by this agent.

Specified by:
removeOutgoingMessageListener in interface MessageDispatcher
Parameters:
listener - the OutgoingMessageListener to be removed

addDeliveryReportListener

public void addDeliveryReportListener(DeliveryReportListener listener)
Description copied from interface: MessageDispatcher
Adds a listener to all delivery reports sent to this agent.

Specified by:
addDeliveryReportListener in interface MessageDispatcher
Parameters:
listener - the DeliveryReportListener to be added.

removeDeliveryReportListener

public void removeDeliveryReportListener(DeliveryReportListener listener)
Description copied from interface: MessageDispatcher
Adds a listener to all delivery reports sent to this agent.

Specified by:
removeDeliveryReportListener in interface MessageDispatcher
Parameters:
listener - the DeliveryReportListener to be removed.

createConversation

public Conversation createConversation(MessageHandler listener)
Description copied from interface: MessageDispatcher
Creates a new Conversation and adds a listener to it. A conversation is used to send and receive messages in a certain 'conversational context'.

Specified by:
createConversation in interface MessageDispatcher

send

public void send(OutgoingMessage message)
          throws MessagingException
Description copied from interface: MessageDispatcher
Sends a message without using a conversation object. Note that when the message is sent a conversation ID is still set.

Specified by:
send in interface MessageDispatcher
Parameters:
message - the message to be sent.
Throws:
MessagingException

doSend

protected abstract void doSend(OutgoingMessage message)
                        throws MessagingException
Actually sends the message.

Throws:
MessagingException

createConversationID

public java.lang.String createConversationID()
Creates a unique conversation ID for this agent. By convention, the conversation ID is composed of the agent name followed by a dash and a unique number.

Returns:
the conversation ID

getConversationFor

public Conversation getConversationFor(Message message)
Get the Conversation for this message, if possible.

Returns:
the Conversation corresponding to the message (may be null)

getOrCreateConversationFor

public Conversation getOrCreateConversationFor(Message message)
Description copied from interface: MessageDispatcher
Returns the conversation this message is/will be sent in, if initialized; otherwise, create a Conversation, if possible with an ID based on the 'conversation-id' meta field in the message.

Specified by:
getOrCreateConversationFor in interface MessageDispatcher
Returns:
the Conversation corresponding this message.

log

protected void log(java.lang.String message,
                   java.lang.Exception re)

Copyright 2005, Tryllian Solutions B.V.