com.ls.lars.communication
Class JMSMessenger

java.lang.Object
  |
  +--com.ls.lars.communication.Messenger
        |
        +--com.ls.lars.communication.RemoteMessenger
              |
              +--com.ls.lars.communication.JMSMessenger
All Implemented Interfaces:
Runnable

public class JMSMessenger
extends com.ls.lars.communication.RemoteMessenger

JMSMessenger is used by Agent to communicate with the LARS platform over a JMS provider. This can be used by applets or other clients, and for platform synchronization. It is obtained by calling the getMessenger method of class ClientMessengerFactory. In order to use this messenger, a JMS provider has to be started up, for example, JBoss server.

Version:
$Revision: 1.15 $
Author:
Last modified by $Author: CReich $

Field Summary
protected  String messengerType
          every remote messenger does in fact know what kind of messenger it is
protected  ArrayList outbox
          outbox stores messages which should be sent to the remote side
 
Constructor Summary
protected JMSMessenger(String agentName, Map parameterList)
          constructs a JMSMessenger object and intializes it with the given parameters.
The given parameterList should contain the following information: 1).
 
Method Summary
 void closeConnection()
          calls closeConnection method with the parameter EVALUATE_CONNECTION_STATUS
 void closeConnection(boolean statusEvaluation)
          Behaviour depends on the connection status:
If connection status is CommunicationTemplate.STATUS_NOT_CONNECTED: returns after writing a warning in the system log file.
protected  void emptyOutbox()
          Waits until outbox is empty.
protected  boolean isOutboxInUse()
          set status of the outbox usage
 void processMessage(Message message)
          Usually calls sendMessage(message)
protected  Message receiveBlockedMessage()
          Waits until a message arrives from the JMS server and returns it.
 void run()
          This method is responsible for connecting this JMSMessenger to the JMS Server.
 void sendMessageToRemoteSide(Message message)
          Sends a message to the LARS platform via JMS provider.
protected  void setMessengerName()
          Sets the name of this messenger.
protected  void setOutboxInUse(boolean status)
          set status of the outbox usage
 void start()
          Starts an own thread for this agent running on the server.
 String toString()
          returns a well formed string from the content of the inbox (The synchronization is guaranteed with help of the inbox object.)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

messengerType

protected String messengerType
every remote messenger does in fact know what kind of messenger it is

outbox

protected ArrayList outbox
outbox stores messages which should be sent to the remote side
Constructor Detail

JMSMessenger

protected JMSMessenger(String agentName,
                       Map parameterList)
                throws ConnectionException
constructs a JMSMessenger object and intializes it with the given parameters.
The given parameterList should contain the following information: 1). JNDI initial context as defined by ICommunication.INITIAL_CONTEXT_FACTORY
2). JMSServer URL Address as defined by ICommunication.PROVIDER_URL
3). Security Principal as defined by ICommunication.SECURITY_PRINCIPAL - should be at least an empty string
4). Security Credentials as defined by ICommunication.SECURITY_CREDENTIALS - should be at least an empty string
5). Queue Name for sending messages to JMS Server, as defined by ICommunication.JMS_SENDING_QUEUE_NAME
6). Queue Name for receiving messages from JMS Server, as defined by ICommunication.JMS_RECEIVING_QUEUE_NAME
7). A boolean value to indicate whether the JMSMessenger is used on server side or client side.
Parameters:
agentName - agent name of the client
parameterList - connection parameters
Throws:
ConnectionException - if the provided parameters are not enough for connecting to a JMS server
Method Detail

start

public void start()
Starts an own thread for this agent running on the server. The new thread receives messages and puts them in the owning agent's inbox().

run

public void run()
This method is responsible for connecting this JMSMessenger to the JMS Server.
Overrides:
run in class com.ls.lars.communication.Messenger

processMessage

public void processMessage(Message message)
Usually calls sendMessage(message)
Parameters:
message - message that has to be transferred

sendMessageToRemoteSide

public void sendMessageToRemoteSide(Message message)
Sends a message to the LARS platform via JMS provider.
This message will be first sent to the JMS provider. It will be forwarded to the LARS platform.
Parameters:
message - Message that has to be transferred

closeConnection

public void closeConnection()
calls closeConnection method with the parameter EVALUATE_CONNECTION_STATUS

closeConnection

public void closeConnection(boolean statusEvaluation)
Behaviour depends on the connection status:
If connection status is CommunicationTemplate.STATUS_NOT_CONNECTED: returns after writing a warning in the system log file.
If connection status is CommunicationTemplate.STATUS_CONNECTED: close the connection to the JMS provider
Parameters:
statusEvaluation - EVALUATE_CONNECTION_STATUS or IGNORE_CONNECTION_STATUS

setMessengerName

protected void setMessengerName()
Sets the name of this messenger.

receiveBlockedMessage

protected Message receiveBlockedMessage()
Waits until a message arrives from the JMS server and returns it. If the connection status is CommunicationTemplate.STATUS_NOT_CONNECTED, a warning is logged and a "connection_closed" message is returned.
Returns:
message The incomming message

emptyOutbox

protected void emptyOutbox()
Waits until outbox is empty.

setOutboxInUse

protected void setOutboxInUse(boolean status)
set status of the outbox usage
Parameters:
status - true, if the outbox shall be used; false else

isOutboxInUse

protected boolean isOutboxInUse()
set status of the outbox usage
Returns:
true, if this messenger uses an outbox; false else

toString

public String toString()
returns a well formed string from the content of the inbox (The synchronization is guaranteed with help of the inbox object.)
Overrides:
toString in class Object
Returns:
well formatted string of the content of the inbox