com.cometway.ak
Class Agent

java.lang.Object
  extended by com.cometway.props.Props
      extended by com.cometway.ak.Agent
All Implemented Interfaces:
AgentInterface, HasStateMachineModel
Direct Known Subclasses:
AbstractJFrameAgent, AgentKernel, AgentReplicator, CRLFConversionAgent, DeleteFileAgent, DelimitedLineExportAgent, DelimitedLineImportAgent, HTTPDownloaderAgent, JDBCAgent, LogMonitorAgent, MoveFileAgent, PropsListIteratorAgent, ReceiveEmailAgent, RunnableAgent, ScheduledAgent, ServiceAgent, ServiceManager, ShellCommandAgent, StartupAgent, SystemExitAgent, WebServer, XMLPropsListExportAgent, XMLPropsListImportAgent

public abstract class Agent
extends Props
implements AgentInterface

An abstract implementation of the AgentInterface. There is built-in support for routing agent output to the agent's output and error streams, and masking this output through the use of hide_println, hide_debug, and hide_warning props. This implementation of AgentInterface recognizes these properties:


Field Summary
protected  java.lang.String agent_id
          This is where the agent_id is cached for use by the toString method.
protected  AgentControllerInterface agentController
          This is a reference to the AgentController assigned to this agent.
static java.lang.String CREATING_STATE
          The agent is being created; initProps method called.
protected  ReporterInterface debugReporter
          This is a reference to the Reporter assigned to this agent for debug output.
static java.lang.String DESTROYED_STATE
          The agent has been destroyed and can no longer be used.
static java.lang.String DESTROYING_STATE
          The agent is being destroyed; destroy method called.
protected  ReporterInterface errorReporter
          This is a reference to the Reporter assigned to this agent for error output.
static java.lang.String FAILED_STATE
          The agent has failed; DESTROYING_STATE automatically entered.
protected  ReporterInterface printlnReporter
          This is a reference to the Reporter assigned to this agent for println output.
protected  Props props
          Deprecated. use the getProps method if you need a Props reference.
static java.lang.String RUNNING_STATE
          The agent is running and ready to be stoppped.
static java.lang.String STARTING_STATE
          The agent is starting; start method called.
static java.lang.String STOPPED_STATE
          The agent is ready to be started or destroyed.
static java.lang.String STOPPING_STATE
          The agent is stopping; stop method called.
protected  ReporterInterface warningReporter
          This is a reference to the Reporter assigned to this agent for warning output.
 
Constructor Summary
Agent()
           
 
Method Summary
 boolean currentStateEquals(java.lang.String stateName)
          Returns true if the specified state is the current state.
 void debug(java.lang.String message)
          Prints a debug message tagged with this agent's identity to the output stream.
 void destroy()
          Override this method to perform special cleanup before an agent is destroyed.
 void error(java.lang.String message)
          Prints an error message tagged with this agent's identity to the error stream.
 void error(java.lang.String message, java.lang.Exception e)
          Prints an error message tagged with this agent's identity followed by a stack trace of the passed Exception to the error stream.
protected  AgentControllerInterface getAgentController()
          Returns the AgentController for this agent.
static java.lang.String getDateTimeStr()
          Returns the formatted date-time as a String.
 Props getProps()
          Returns the Props assigned to this agent.
 java.lang.Object getServiceImpl(java.lang.String service_name)
          Returns a reference to the requested Service from the ServiceManager; null if the requested service does not exist, or the ServiceManager has not been loaded.
 StateMachineModelInterface getStateMachineModel()
          Called by AgentController to retrieve a reference to this agent's state machine model.
 void initProps()
          Override this method to initialize this agent's properties before it is started.
 void println(java.lang.String message)
          Prints a message tagged with this agent's identity to the output stream.
 void register()
          Registers this instance with the service manager using the service_name property.
 void registerService(java.lang.String service_name, java.lang.Object serviceImpl)
          Registers the specified object with the service manager using the specified property.
 void setAgentController(AgentControllerInterface agentController)
          Assigns an AgentController to this agent.
 void setProps(Props p)
          Called by the agent kernel to assign a Props to this agent.
 void start()
          Override this method to initiate activities for this agent.
 void stop()
          Override this method to handle stop requests from the agent kernel.
 java.lang.String toString()
          Returns the string representation of this agent using the format <agent_id>_<name> taken from this agent's Props the first time this method is called, and cached for future calls.
 void unregister()
          Unregisters this service implementation instance with the service manager using the service_name property.
 void unregisterService(java.lang.String service_name, java.lang.Object serviceImpl)
          Unregisters the service implementation instance with the service manager using the specified property.
 void warning(java.lang.String message)
          Prints a warning message tagged with this agent's identity to the error stream.
 void warning(java.lang.String message, java.lang.Exception e)
          Prints an warning message tagged with this agent's identity followed by a stack trace of the passed Exception to error stream.
 
Methods inherited from class com.cometway.props.Props
addListener, append, copy, copyFrom, copyTo, decrementInteger, dump, enableListeners, enumerateKeys, format, getBoolean, getByteArray, getCharacter, getDate, getDate, getDateString, getDouble, getFloat, getHexString, getInteger, getKeys, getLong, getNextKey, getProperty, getProperty, getPropsContainer, getSize, getString, getString, getTokens, getTokens, getTrimmedString, getVector, hasProperty, incrementInteger, insertProps, loadProps, notifyPropsChanged, notifyPropsChangedIgnore, notifyPropsChangedIgnore, parse, propertyMatchesRegEx, readFromFile, regExPropertyMatches, removeAll, removeListener, removeProperty, resumeNotify, saveProps, set, setBoolean, setCharacter, setDefault, setDouble, setFloat, setInteger, setLong, setProperty, setProperty, setProperty, setPropsContainer, suspendNotify, writeToFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CREATING_STATE

public static final java.lang.String CREATING_STATE
The agent is being created; initProps method called.

See Also:
Constant Field Values

STOPPED_STATE

public static final java.lang.String STOPPED_STATE
The agent is ready to be started or destroyed.

See Also:
Constant Field Values

STARTING_STATE

public static final java.lang.String STARTING_STATE
The agent is starting; start method called.

See Also:
Constant Field Values

RUNNING_STATE

public static final java.lang.String RUNNING_STATE
The agent is running and ready to be stoppped.

See Also:
Constant Field Values

STOPPING_STATE

public static final java.lang.String STOPPING_STATE
The agent is stopping; stop method called.

See Also:
Constant Field Values

FAILED_STATE

public static final java.lang.String FAILED_STATE
The agent has failed; DESTROYING_STATE automatically entered.

See Also:
Constant Field Values

DESTROYING_STATE

public static final java.lang.String DESTROYING_STATE
The agent is being destroyed; destroy method called.

See Also:
Constant Field Values

DESTROYED_STATE

public static final java.lang.String DESTROYED_STATE
The agent has been destroyed and can no longer be used.

See Also:
Constant Field Values

props

protected Props props
Deprecated. use the getProps method if you need a Props reference.
This is a reference to the Agent's Props for backwards compatibility. Under the current architecture the Agent is the Agent's Props making the Props methods to be accessible directly from other agent methods.


agentController

protected AgentControllerInterface agentController
This is a reference to the AgentController assigned to this agent.


agent_id

protected java.lang.String agent_id
This is where the agent_id is cached for use by the toString method.


printlnReporter

protected ReporterInterface printlnReporter
This is a reference to the Reporter assigned to this agent for println output. If this field is null, the println method will be ignored.


debugReporter

protected ReporterInterface debugReporter
This is a reference to the Reporter assigned to this agent for debug output. If this field is null, the debug method will be ignored.


warningReporter

protected ReporterInterface warningReporter
This is a reference to the Reporter assigned to this agent for warning output. If this field is null, the warning methods will be ignored.


errorReporter

protected ReporterInterface errorReporter
This is a reference to the Reporter assigned to this agent for error output. If this field is null, the error methods will be ignored.

Constructor Detail

Agent

public Agent()
Method Detail

setProps

public void setProps(Props p)
Called by the agent kernel to assign a Props to this agent.

Specified by:
setProps in interface AgentInterface

getProps

public final Props getProps()
Returns the Props assigned to this agent.

Specified by:
getProps in interface AgentInterface

initProps

public void initProps()
Override this method to initialize this agent's properties before it is started.

Specified by:
initProps in interface AgentInterface

currentStateEquals

public final boolean currentStateEquals(java.lang.String stateName)
Returns true if the specified state is the current state.


setAgentController

public final void setAgentController(AgentControllerInterface agentController)
Assigns an AgentController to this agent.

Specified by:
setAgentController in interface AgentInterface

getAgentController

protected final AgentControllerInterface getAgentController()
Returns the AgentController for this agent.


getStateMachineModel

public StateMachineModelInterface getStateMachineModel()
Called by AgentController to retrieve a reference to this agent's state machine model.

Specified by:
getStateMachineModel in interface HasStateMachineModel

start

public void start()
Override this method to initiate activities for this agent.

Specified by:
start in interface AgentInterface

stop

public void stop()
Override this method to handle stop requests from the agent kernel.

Specified by:
stop in interface AgentInterface

destroy

public void destroy()
Override this method to perform special cleanup before an agent is destroyed.

Specified by:
destroy in interface AgentInterface

debug

public void debug(java.lang.String message)
Prints a debug message tagged with this agent's identity to the output stream.

Specified by:
debug in interface AgentInterface

warning

public void warning(java.lang.String message)
Prints a warning message tagged with this agent's identity to the error stream. If the Exception is type java.lang.reflect.InvocationTargetException that exception's target exception is also stack traced.

Specified by:
warning in interface AgentInterface

warning

public void warning(java.lang.String message,
                    java.lang.Exception e)
Prints an warning message tagged with this agent's identity followed by a stack trace of the passed Exception to error stream. If the Exception is type java.lang.reflect.InvocationTargetException that exception's target exception is also stack traced.

Specified by:
warning in interface AgentInterface

error

public void error(java.lang.String message)
Prints an error message tagged with this agent's identity to the error stream. If the Exception is type java.lang.reflect.InvocationTargetException that exception's target exception is also stack traced.

Specified by:
error in interface AgentInterface

error

public void error(java.lang.String message,
                  java.lang.Exception e)
Prints an error message tagged with this agent's identity followed by a stack trace of the passed Exception to the error stream. If the Exception is type java.lang.reflect.InvocationTargetException that exception's target exception is also stack traced.

Specified by:
error in interface AgentInterface

println

public void println(java.lang.String message)
Prints a message tagged with this agent's identity to the output stream. Can be disabled by setting hide_println property to "true".

Specified by:
println in interface AgentInterface

getServiceImpl

public java.lang.Object getServiceImpl(java.lang.String service_name)
Returns a reference to the requested Service from the ServiceManager; null if the requested service does not exist, or the ServiceManager has not been loaded.


register

public void register()
Registers this instance with the service manager using the service_name property.


registerService

public void registerService(java.lang.String service_name,
                            java.lang.Object serviceImpl)
Registers the specified object with the service manager using the specified property.


unregister

public void unregister()
Unregisters this service implementation instance with the service manager using the service_name property.


unregisterService

public void unregisterService(java.lang.String service_name,
                              java.lang.Object serviceImpl)
Unregisters the service implementation instance with the service manager using the specified property.


toString

public java.lang.String toString()
Returns the string representation of this agent using the format <agent_id>_<name> taken from this agent's Props the first time this method is called, and cached for future calls. This format follows the standard naming conventions for agent Props files and allows the agent's output to be formatted in a manner consistent with these files.

Specified by:
toString in interface AgentInterface
Overrides:
toString in class Props

getDateTimeStr

public static java.lang.String getDateTimeStr()
Returns the formatted date-time as a String.