com.cometway.ak
Class ScheduledAgent

java.lang.Object
  extended by com.cometway.props.Props
      extended by com.cometway.ak.Agent
          extended by com.cometway.ak.ScheduledAgent
All Implemented Interfaces:
AgentInterface, HasStateMachineModel, ISchedulable
Direct Known Subclasses:
EmailReporter, FileReaper, ObjectManagerArchiver, ObjectManagerArchiver, ReceivePOP3EmailAgent, SessionReaper

public class ScheduledAgent
extends Agent
implements ISchedulable

Implementation of a scheduled agent. Subclass this agent and override the wakeup method that is called as specified by the schedule property. Creates and uses a Schedule as specified by the schedule property.


Field Summary
protected  ISchedule schedule
           
 
Fields inherited from class com.cometway.ak.Agent
agent_id, agentController, CREATING_STATE, debugReporter, DESTROYED_STATE, DESTROYING_STATE, errorReporter, FAILED_STATE, printlnReporter, props, RUNNING_STATE, STARTING_STATE, STOPPED_STATE, STOPPING_STATE, warningReporter
 
Constructor Summary
ScheduledAgent()
           
 
Method Summary
 boolean addScheduleChangeListener(IScheduleChangeListener l)
          Listeners are not implemented.
 ISchedule getSchedule()
          Returns a reference to the schedule instance.
 void initProps()
          Override this method to provide default properties for subclasses.
 boolean removeScheduleChangeListener(IScheduleChangeListener l)
          Listeners are not implemented.
protected  boolean schedule()
          Creates a Schedule as specified by the schedule property and schedules this agent.
 void start()
          Creates a Schedule as specified by the schedule property and schedules this agent.
 void stop()
          Unschedules this agent.
protected  boolean unschedule()
          Unschedules this agent.
 void wakeup()
          Override this method to handle schedule wakeup notifications.
 
Methods inherited from class com.cometway.ak.Agent
currentStateEquals, debug, destroy, error, error, getAgentController, getDateTimeStr, getProps, getServiceImpl, getStateMachineModel, println, register, registerService, setAgentController, setProps, toString, unregister, unregisterService, warning, warning
 
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

schedule

protected ISchedule schedule
Constructor Detail

ScheduledAgent

public ScheduledAgent()
Method Detail

initProps

public void initProps()
Override this method to provide default properties for subclasses. ScheduledAgent recognizes the following properties: schedule (scheduled string or none) agent_classname and agent_name (used by default wakeup implementation to instantiate and start a new agent based on this agent's properties).

Specified by:
initProps in interface AgentInterface
Overrides:
initProps in class Agent

start

public void start()
Creates a Schedule as specified by the schedule property and schedules this agent.

Specified by:
start in interface AgentInterface
Overrides:
start in class Agent

stop

public void stop()
Unschedules this agent.

Specified by:
stop in interface AgentInterface
Overrides:
stop in class Agent

schedule

protected boolean schedule()
Creates a Schedule as specified by the schedule property and schedules this agent. Call this method instead of super.start for clarification when overriding start method.


unschedule

protected boolean unschedule()
Unschedules this agent. Call this method instead of super.stop for clarification when overriding stop method.


addScheduleChangeListener

public boolean addScheduleChangeListener(IScheduleChangeListener l)
Listeners are not implemented. Always returns false.

Specified by:
addScheduleChangeListener in interface ISchedulable
Parameters:
l - a reference to an IScheduleChangeListener.
Returns:
true if the listener already exists.

getSchedule

public ISchedule getSchedule()
Returns a reference to the schedule instance.

Specified by:
getSchedule in interface ISchedulable
Returns:
a reference to an ISchedule.

removeScheduleChangeListener

public boolean removeScheduleChangeListener(IScheduleChangeListener l)
Listeners are not implemented. Always returns false.

Specified by:
removeScheduleChangeListener in interface ISchedulable
Parameters:
l - a reference to an IScheduleChangeListener.
Returns:
true if the listener was removed; false otherwise.

wakeup

public void wakeup()
Override this method to handle schedule wakeup notifications. By default this agent will create and start a new agent based on the properties of this agent and: 1) agent_classname, the java class name of the agent instance to be created, 2) agent_name, the name property assigned to the new agent instance, 3) agent_id, the unique id property assigned to the new agent instance. The wakeup driven agents are only started (not stopped) and if they have a problem during execution (exception thrown) this agent would be unscheduled automatically.

Specified by:
wakeup in interface ISchedulable