Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.presumo.mobileagent
Class Agent  view Agent download Agent.java

java.lang.Object
  extended bycom.presumo.mobileagent.Agent
All Implemented Interfaces:
java.lang.Runnable, java.io.Serializable

public abstract class Agent
extends java.lang.Object
implements java.io.Serializable, java.lang.Runnable

A very rough base class for mobile agents thrown together to support Presumo's test framework.

Currently your Agent implementation must be in the CLASSPATH of the JVM your agent moves to.

It would be relativly trivial to have the Agent run against a ClassLoader running over JMS to remove this restriction. If you are reading this with interest in using MobileAgents over JMS contact the project admins at www.presumo.com and request the feature, or (if you are capable of doing so) volunteer to do it yourself and join the project. ;) DTG


Field Summary
static int AGENT_MOVE
           
static int AGENT_START
           
static int AGENT_STOP
           
static java.lang.String AGENT_TOPIC
          Topic name for which all agent JMS traffic runs across.
protected  javax.jms.TopicSession agentSession
           
private  javax.jms.Topic agentTopic
           
protected  javax.jms.TopicConnection connx
          Means by which the agent communicates witht he JMS layer
private static com.presumo.util.log.Logger logger
           
static java.lang.String MESSAGE_TYPE
          Message property name used to indicate the type of message.
static int QUERY_RESPONSE
           
static java.lang.String RUNNER_NAME
          Message property name used to indicate a Runner identifier.
static java.lang.String RUNNER_PROP
          Message property name for Runner targets a Agent is sent to.
static int RUNNER_QUERY
           
 
Constructor Summary
Agent()
          Default constructor needed only for deserialization.
Agent(javax.jms.TopicConnection connx)
          Preferred Constructor to invoke when subclassing.
 
Method Summary
protected  javax.jms.Message createQueryMessage()
          Encapsulates the creation of a message sent to request all runners to send their names.
protected  javax.jms.TopicSubscriber createQueryResponseReceiver()
          Encapsulates creating a subscriber with the necessary filters to ensure retrieval of all responses to the query.
protected  javax.jms.Message createRunnerMoveMessage(java.lang.String[] runnerTargets)
          Encapsulates the creation of a message to move the Agent instance.
 java.lang.String[] getAvailableRunners(long timeout)
          Get all AgentRunner's available to run Agents.
 void moveTo(java.lang.String runnerName)
          Move the agent to the specified AgentRunner.
 void moveTo(java.lang.String[] runnerNames)
          Broadcast the agent to all the specivied AgentRunner.
 void run()
          This method will be called by whoever wishes to run your class implementing Runnable.
abstract  void runAgent()
           
 void setConnection(javax.jms.TopicConnection connx)
          Used by the AgentRunner to set the Agent's TopicConnection after it is deserialized.
abstract  void startAgent()
          Implement this method if you want your agent to do special processing in response to a start broadcast.
abstract  void stopAgent()
          Implement this method if you want your agent to do something when a stop is broadcast.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AGENT_TOPIC

public static final java.lang.String AGENT_TOPIC
Topic name for which all agent JMS traffic runs across.

See Also:
Constant Field Values

RUNNER_PROP

public static final java.lang.String RUNNER_PROP
Message property name for Runner targets a Agent is sent to.

See Also:
Constant Field Values

RUNNER_NAME

public static final java.lang.String RUNNER_NAME
Message property name used to indicate a Runner identifier.

See Also:
Constant Field Values

MESSAGE_TYPE

public static final java.lang.String MESSAGE_TYPE
Message property name used to indicate the type of message.

See Also:
Constant Field Values

AGENT_MOVE

public static final int AGENT_MOVE
See Also:
Constant Field Values

AGENT_START

public static final int AGENT_START
See Also:
Constant Field Values

AGENT_STOP

public static final int AGENT_STOP
See Also:
Constant Field Values

RUNNER_QUERY

public static final int RUNNER_QUERY
See Also:
Constant Field Values

QUERY_RESPONSE

public static final int QUERY_RESPONSE
See Also:
Constant Field Values

connx

protected transient javax.jms.TopicConnection connx
Means by which the agent communicates witht he JMS layer


agentSession

protected transient javax.jms.TopicSession agentSession

agentTopic

private transient javax.jms.Topic agentTopic

logger

private static com.presumo.util.log.Logger logger
Constructor Detail

Agent

public Agent()
Default constructor needed only for deserialization. When subclassing agent you must make sure agentSession is set.


Agent

public Agent(javax.jms.TopicConnection connx)
Preferred Constructor to invoke when subclassing. If you do not invoke this Constructor you must ensure that agentSession is set.

Method Detail

moveTo

public void moveTo(java.lang.String runnerName)
            throws javax.jms.JMSException
Move the agent to the specified AgentRunner.


moveTo

public void moveTo(java.lang.String[] runnerNames)
            throws javax.jms.JMSException
Broadcast the agent to all the specivied AgentRunner.


getAvailableRunners

public java.lang.String[] getAvailableRunners(long timeout)
                                       throws javax.jms.JMSException
Get all AgentRunner's available to run Agents.


setConnection

public void setConnection(javax.jms.TopicConnection connx)
Used by the AgentRunner to set the Agent's TopicConnection after it is deserialized.


startAgent

public abstract void startAgent()
Implement this method if you want your agent to do special processing in response to a start broadcast. If you want your processing to start as soon as the agent is moved simply perform all work when the run() method is called. Do not do much processing in the thread calling this method. instead a spin lock should be used to wake up thre Thread executing the run method.


stopAgent

public abstract void stopAgent()
Implement this method if you want your agent to do something when a stop is broadcast. Implementations should cause the Thread executing your run() implementation to finish and return from the method gracefully.


runAgent

public abstract void runAgent()

run

public final void run()
Description copied from interface: java.lang.Runnable
This method will be called by whoever wishes to run your class implementing Runnable. Note that there are no restrictions on what you are allowed to do in the run method, except that you cannot throw a checked exception.

Specified by:
run in interface java.lang.Runnable

createRunnerMoveMessage

protected javax.jms.Message createRunnerMoveMessage(java.lang.String[] runnerTargets)
                                             throws javax.jms.JMSException
Encapsulates the creation of a message to move the Agent instance.


createQueryMessage

protected javax.jms.Message createQueryMessage()
                                        throws javax.jms.JMSException
Encapsulates the creation of a message sent to request all runners to send their names.


createQueryResponseReceiver

protected javax.jms.TopicSubscriber createQueryResponseReceiver()
                                                         throws javax.jms.JMSException
Encapsulates creating a subscriber with the necessary filters to ensure retrieval of all responses to the query.