ciagent
Class CIAgent

java.lang.Object
  |
  +--ciagent.CIAgent
Direct Known Subclasses:
AirfareAgent, BuyerAgent, FacilitatorAgent, FileAgent, FilterAgent, NewsReaderAgent, SchedulerAgent, SellerAgent, URLReaderAgent, UserNotificationAgent

public abstract class CIAgent
extends java.lang.Object
implements CIAgentEventListener, java.io.Serializable

The CIAgent class defines the common programming interface and behavior for intelligent agents.

The lifecycle of a CIAgent is as follows:

  1. construct an agent bean (state = UNINITIATED)
  2. set the bean properties
  3. call initialize() method (state changes to INITIATED)
  4. call startAgentProcessing() method (state changes to ACTIVE) use agent in applications
  5. call stopAgentProcessing() method (state changed to UNKNOWN)

Call process() to perform synchronous agent processing of data. Use processTimerPop() to perform asynchronous agent processing. Call processCIAgentEvent() to perform synchronous event processing Call postCIAgentEvent() to perform asynchronous event processing

See Also:
Serialized Form

Field Summary
protected  AgentPlatform agentPlatform
           
protected  java.util.Vector children
           
static int DEFAULT_ASYNCTIME
           
static int DEFAULT_SLEEPTIME
           
protected  java.lang.String name
           
protected  CIAgent parent
           
protected  int traceLevel
           
 
Constructor Summary
CIAgent()
          Creates a CIAgent instance.
CIAgent(java.lang.String name)
          Creates a CIAgent with specified name.
 
Method Summary
 void addAgent(CIAgent child)
          Adds a CIAgent to this agent and sets its parent member to point to this agent.
 void addCIAgentEventListener(CIAgentEventListener listener)
          Adds a listener for CIAgent events.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds a listener for PropertyChange events.
 CIAgent getAgent(java.lang.String name)
          Retrieves an agent running on the same agent platform
 AgentPlatform getAgentPlatform()
          Retrieves the agent platform.
 java.util.Vector getAgents()
          Retrieves the other agents running on the same agent platform
 int getAsyncTime()
          Retrieves the time (in milliseconds) for asynchronous event processing.
 java.util.Vector getChildren()
          Retrieves a list of CIAgent objects contained by this agent.
 java.lang.Class getCustomizerClass()
          Uses introspection on this bean to get the customizer class (if any).
 java.lang.String getDisplayName()
          Uses introspection on this bean to get the display name (defaults to the class name).
 java.lang.String getName()
          Retrieves the name of this agent.
 CIAgent getParent()
          Retrieves the parent CIAgent object.
 int getSleepTime()
          Retrieves the agent sleep time (in milliseconds).
 CIAgentState getState()
          Retrieves the current state of this agent (UNINITIATED, INITIATED, ACTIVE, SUSPENDED, UNKNOWN).
abstract  java.lang.String getTaskDescription()
          Retrieves a formatted string for display of this agent's current task.
 int getTraceLevel()
          Retrieves the trace level.
abstract  void initialize()
          Initializes this agent for processing.
protected  void notifyCIAgentEventListeners(CIAgentEvent e)
          Delivers the CIAgent event to all registered listeners.
 void postCIAgentEvent(CIAgentEvent event)
          Posts an event to this agent's event queue.
abstract  void process()
          Provides the synchronous processing done by this agent.
 void processAsynchronousEvents()
          Processes all events on the asynchronous event queue periodically, depending on the asynchronous event time for this agent.
 void processCIAgentEvent(CIAgentEvent event)
          Performs synchronous event processing for this agent.
abstract  void processTimerPop()
          Provides the asynchronous, autonomous behavior of this agent that occurs periodically, depending on the sleep time for this agent.
 void removeAgent(CIAgent child)
          Removes a CIAgent from this agent.
 void removeCIAgentEventListener(CIAgentEventListener listener)
          Removes a listener for CIAgent events.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes a listener for PropeortyChange events.
 void reset()
          Resets this agent so that it is in a known state.
 void resumeAgentProcessing()
          Resumes agent processing of the timer and asynchronous events and sets the agent state to ACTIVE.
 void setAgentPlatform(AgentPlatform agentPlatform)
          Sets the agent platform for this agent.
 void setAsyncTime(int asyncTime)
          Sets the time (in milliseconds) for asynchronous event processing.
 void setName(java.lang.String newName)
          Sets the name of this agent.
 void setParent(CIAgent parent)
          Sets the parent CIAgent for this agent.
 void setSleepTime(int sleepTime)
          Sets the agent sleep time (in milliseconds) for autonomous processing.
protected  void setState(int newState)
          Sets the current state of this agent (UNINITIATED, INITIATED, ACTIVE, SUSPENDED, UNKNOWN).
 void setTraceLevel(int traceLevel)
          Sets the trace level.
 void startAgentProcessing()
          Starts the agent timer and asynchronous event processing and sets the agent state to ACTIVE.
 void stopAgentProcessing()
          Stops the agent timer and asynchronous event processing and sets the agent state to UNKNOWN.
 void suspendAgentProcessing()
          Temporarily stops the agent timer so that the autonomous behavior is suspended and sets the agent state to SUSPENDED.
 void trace(java.lang.String msg)
          Sends a trace event to all registered listeners.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SLEEPTIME

public static final int DEFAULT_SLEEPTIME

DEFAULT_ASYNCTIME

public static final int DEFAULT_ASYNCTIME

name

protected java.lang.String name

traceLevel

protected int traceLevel

agentPlatform

protected AgentPlatform agentPlatform

children

protected java.util.Vector children

parent

protected CIAgent parent
Constructor Detail

CIAgent

public CIAgent()
Creates a CIAgent instance.

CIAgent

public CIAgent(java.lang.String name)
Creates a CIAgent with specified name.
Parameters:
name - the String name given to this agent
Method Detail

setName

public void setName(java.lang.String newName)
Sets the name of this agent.
Parameters:
newName - the String that contains the new name of this agent

getName

public java.lang.String getName()
Retrieves the name of this agent.
Returns:
the String that contains the name of this agent

setState

protected void setState(int newState)
Sets the current state of this agent (UNINITIATED, INITIATED, ACTIVE, SUSPENDED, UNKNOWN).
Parameters:
state - the new state of this agent
newState - the int object

getState

public CIAgentState getState()
Retrieves the current state of this agent (UNINITIATED, INITIATED, ACTIVE, SUSPENDED, UNKNOWN).
Returns:
the state of this agent

setSleepTime

public void setSleepTime(int sleepTime)
Sets the agent sleep time (in milliseconds) for autonomous processing. Note that this has no effect on a running agent.
Parameters:
sleepTime - the sleep time (in milliseconds) for this agent

getSleepTime

public int getSleepTime()
Retrieves the agent sleep time (in milliseconds).
Returns:
the sleep time (in milliseconds) for this agent

setAsyncTime

public void setAsyncTime(int asyncTime)
Sets the time (in milliseconds) for asynchronous event processing. Note that this has no effect on a running agent.
Parameters:
asyncTime - the time (in milliseconds) for asynchronous event processing

getAsyncTime

public int getAsyncTime()
Retrieves the time (in milliseconds) for asynchronous event processing.
Returns:
the time (in milliseconds) for asynchronous event processing

setTraceLevel

public void setTraceLevel(int traceLevel)
Sets the trace level.
Parameters:
traceLevel - the integer that represents the trace level

getTraceLevel

public int getTraceLevel()
Retrieves the trace level.
Returns:
the trace level of this agent

setAgentPlatform

public void setAgentPlatform(AgentPlatform agentPlatform)
Sets the agent platform for this agent.
Parameters:
agentPlatform - the AgentPlatform object for this agent

getAgentPlatform

public AgentPlatform getAgentPlatform()
Retrieves the agent platform.
Returns:
the agent platform of this agent

getAgents

public java.util.Vector getAgents()
Retrieves the other agents running on the same agent platform
Returns:
a vector of agents running on this platform, null if no platform

getAgent

public CIAgent getAgent(java.lang.String name)
Retrieves an agent running on the same agent platform
Returns:
a CIAgnet running on this platform, null if no match

getTaskDescription

public abstract java.lang.String getTaskDescription()
Retrieves a formatted string for display of this agent's current task.
Returns:
the String that represents the current task

getChildren

public java.util.Vector getChildren()
Retrieves a list of CIAgent objects contained by this agent.
Returns:
a Vector of CIAgent objects contained by this agent

setParent

public void setParent(CIAgent parent)
Sets the parent CIAgent for this agent.
Parameters:
parent - the CIAgent object that is the parent of this agent

getParent

public CIAgent getParent()
Retrieves the parent CIAgent object.
Returns:
a CIAgent object or null if no parent is defined

getCustomizerClass

public java.lang.Class getCustomizerClass()
Uses introspection on this bean to get the customizer class (if any).
Returns:
the customizer class for this agent bean

getDisplayName

public java.lang.String getDisplayName()
Uses introspection on this bean to get the display name (defaults to the class name).
Returns:
the display name for this agent bean

reset

public void reset()
Resets this agent so that it is in a known state.

initialize

public abstract void initialize()
Initializes this agent for processing.

startAgentProcessing

public void startAgentProcessing()
Starts the agent timer and asynchronous event processing and sets the agent state to ACTIVE.

stopAgentProcessing

public void stopAgentProcessing()
Stops the agent timer and asynchronous event processing and sets the agent state to UNKNOWN.

suspendAgentProcessing

public void suspendAgentProcessing()
Temporarily stops the agent timer so that the autonomous behavior is suspended and sets the agent state to SUSPENDED.

resumeAgentProcessing

public void resumeAgentProcessing()
Resumes agent processing of the timer and asynchronous events and sets the agent state to ACTIVE.

process

public abstract void process()
Provides the synchronous processing done by this agent.

processTimerPop

public abstract void processTimerPop()
Provides the asynchronous, autonomous behavior of this agent that occurs periodically, depending on the sleep time for this agent.

processAsynchronousEvents

public void processAsynchronousEvents()
Processes all events on the asynchronous event queue periodically, depending on the asynchronous event time for this agent.

processCIAgentEvent

public void processCIAgentEvent(CIAgentEvent event)
Performs synchronous event processing for this agent.
Specified by:
processCIAgentEvent in interface CIAgentEventListener
Parameters:
event - the CIAgentEvent object

postCIAgentEvent

public void postCIAgentEvent(CIAgentEvent event)
Posts an event to this agent's event queue.
Specified by:
postCIAgentEvent in interface CIAgentEventListener
Parameters:
event - the CIAgentEvent to be posted

addCIAgentEventListener

public void addCIAgentEventListener(CIAgentEventListener listener)
Adds a listener for CIAgent events.
Parameters:
listener - the CIAgentEventListener to be added

removeCIAgentEventListener

public void removeCIAgentEventListener(CIAgentEventListener listener)
Removes a listener for CIAgent events.
Parameters:
listener - the CIAgentEventListener to be removed

notifyCIAgentEventListeners

protected void notifyCIAgentEventListeners(CIAgentEvent e)
Delivers the CIAgent event to all registered listeners.
Parameters:
e - the CIAgentEvent to be sent to all listeners

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a listener for PropertyChange events.
Parameters:
listener - the PropertyChangeListener to be added

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a listener for PropeortyChange events.
Parameters:
listener - the PropertyChangeListener to be removed

trace

public void trace(java.lang.String msg)
Sends a trace event to all registered listeners.
Parameters:
msg - the String that is the message portion of the trace event

addAgent

public void addAgent(CIAgent child)
Adds a CIAgent to this agent and sets its parent member to point to this agent.
Parameters:
child - the CIAgent object to be added to this object as a child

removeAgent

public void removeAgent(CIAgent child)
Removes a CIAgent from this agent.
Parameters:
child - the CIAgent object to be removed from this agent