agentland.util.scheduler
Class SchedulerAgent

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--metaglue.AgentAgent
                          |
                          +--agentland.util.scheduler.SchedulerAgent
All Implemented Interfaces:
Agent, MetagluePrimitives, Remote, Scheduler, Serializable

public class SchedulerAgent
extends AgentAgent
implements Scheduler

Like crontab but better(more opaque).

See Also:
Serialized Form

Inner Class Summary
protected  class SchedulerAgent.Timer
          This class deals with the timing for our scheduler agent
 
Inner classes inherited from class metaglue.AgentAgent
AgentAgent.Attribute
 
Field Summary
protected static long lastID
           
protected  Hashtable remindersByID
           
protected  Vector remindersInOrder
           
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface metaglue.Agent
ALIVE, DIED, NO_METAGLUE, NOT_RUNNING, STARTING
 
Constructor Summary
SchedulerAgent()
           
 
Method Summary
 long addReminder(ReminderRecord reminder)
          Allows you to add a reminder record
protected  void addReminder(ReminderRecord reminder, long id)
           
protected  void callMethod(ReminderRecord reminder)
          This method gets called from the MethodCaller thread -- it calls a method specified in the reminder record.
 Vector getMyReminders(AgentID aid)
          Returns all reminders owned by an agent specified by agent id
protected  ReminderRecord getNextReminder()
          Returns the next unexpired reminder.
 ReminderRecord getReminder(long id)
          Returns the reminder with a given id
 boolean removeReminder(long id)
          Removes a reminder from the list
protected  void setTimer()
          Looks at the next unexpired reminder and sets the timer accordingly.
protected  void storeReminder(ReminderRecord reminder)
           
 String toString()
           
protected  boolean unstoreReminder(long id)
          Removes the reminder and, if necessary, resets the timer
 boolean updateReminder(long id, ReminderRecord reminder)
          Allows you to modify an existing reminder; if the reminder with given id does not exist, we add the new reminder with the given id
protected  void whatsUp()
          This method gets called by the timer thread; it checks if there are any ripe reminders and if so, issues them.
 
Methods inherited from class metaglue.AgentAgent
addMonitor, alive, buildEHAFor, defrost, defrostAll, defrostBoolean, defrostInt, defrostString, fixAttribute, fixAttribute, freeze, freeze, freeze, freezeAll, freezeVar, getAgentID, getAttribute, getCatalog, getCatalogID, getDesignation, getFrozenVariables, getLogLevel, getMetaglueAgent, getMetaglueAgentID, getOccupation, getOldLogs, getProperties, getProxyHandlerClass, getSociety, installAPH, log, log, log, lookupClass, reliesOn, reliesOn, reliesOn, reliesOnSynch, removeAPHFromCatalog, removeFrozen, setFreezeName, setLogLevel, setLogName, shutdown, startAgent, startAgentOn, startAgentOn, startup, status, tiedTo, tiedTo, tiedTo, tiedTo, tieToDesignation, whereAreYou
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface metaglue.Agent
addMonitor, alive, getAgentID, getMetaglueAgentID, getOldLogs, shutdown, startup, whereAreYou
 

Field Detail

lastID

protected static long lastID

remindersByID

protected Hashtable remindersByID

remindersInOrder

protected Vector remindersInOrder
Constructor Detail

SchedulerAgent

public SchedulerAgent()
               throws RemoteException
Method Detail

addReminder

public long addReminder(ReminderRecord reminder)
                 throws RemoteException
Allows you to add a reminder record
Specified by:
addReminder in interface Scheduler
Parameters:
reminder - a ReminderRecord value
Returns:
the id of the reminder, when you do updating or removing later, you must use this id

removeReminder

public boolean removeReminder(long id)
                       throws RemoteException
Removes a reminder from the list
Specified by:
removeReminder in interface Scheduler
Parameters:
id - the id of the reminder to be removed
Returns:
true of everything went ok or false otherwise

updateReminder

public boolean updateReminder(long id,
                              ReminderRecord reminder)
                       throws RemoteException
Allows you to modify an existing reminder; if the reminder with given id does not exist, we add the new reminder with the given id
Specified by:
updateReminder in interface Scheduler
Parameters:
id - the id of the reminder to be modified
reminder - the new reminder object that should go in its place
Returns:
true if everything went ok or false if no reminder with given id could be found

getReminder

public ReminderRecord getReminder(long id)
                           throws RemoteException
Returns the reminder with a given id
Specified by:
getReminder in interface Scheduler
Parameters:
id - id of the reminder to get
Returns:
the reminder or null if no reminder with given id could be found

getMyReminders

public Vector getMyReminders(AgentID aid)
                      throws RemoteException
Returns all reminders owned by an agent specified by agent id
Specified by:
getMyReminders in interface Scheduler
Parameters:
aid - agent id whose reminders you want to see
Returns:
vector of reminders (if anything goes wrong, it returns an empty vector)

addReminder

protected void addReminder(ReminderRecord reminder,
                           long id)

storeReminder

protected void storeReminder(ReminderRecord reminder)

unstoreReminder

protected boolean unstoreReminder(long id)
Removes the reminder and, if necessary, resets the timer
Parameters:
id - id of reminder to remove.
Returns:
true reminder was found and removed, false otherwise.

whatsUp

protected void whatsUp()
This method gets called by the timer thread; it checks if there are any ripe reminders and if so, issues them.

getNextReminder

protected ReminderRecord getNextReminder()
Returns the next unexpired reminder. If it finds any expired reminders in the queue, it silently removes them
Returns:
the next unexpired reminder or null

setTimer

protected void setTimer()
Looks at the next unexpired reminder and sets the timer accordingly. Even if the reminder is already past due, this method is not going to do anything about it. It will just mean that the timer will fire right away....

callMethod

protected void callMethod(ReminderRecord reminder)
This method gets called from the MethodCaller thread -- it calls a method specified in the reminder record. According to the settings in the reminder record, it will either wake the dead agents for the call or not
Parameters:
reminder - the reminder record from which the call info is to be taken

toString

public String toString()
Overrides:
toString in class AgentAgent