org.mmbase.applications.crontab
Class CronDaemon

java.lang.Object
  extended by org.mmbase.applications.crontab.CronDaemon
All Implemented Interfaces:
Events.Listener, ProposedJobs.Listener, EventListener

public class CronDaemon
extends Object
implements ProposedJobs.Listener, Events.Listener

CronDaemon is a "crontab" clone written in java. The daemon starts a thread that wakes up every minute (it keeps sync by calculating the time to sleep)

Version:
$Id: CronDaemon.java 42083 2010-05-03 12:22:51Z michiel $
Author:
Kees Jongenburger, Michiel Meeuwissen

Method Summary
 void add(CronEntry entry)
          Adds the given CronEntry to this daemon.
protected  void addEntry(CronEntry entry)
          Actually adds, no checks for 'removedEntries' and so on.
 void clear()
          Clears all queues
protected  void consumeJobs()
          Consumes received job proposals
protected  void detectFailedJobs()
           
protected static CronEntry getById(Set<CronEntry> set, String id)
          Finds in given set the CronEntry with the given id.
 CronEntry getCronEntry(String id)
           
 Set<CronEntry> getEntries()
           
protected  long getFirst()
           
static CronDaemon getInstance()
          Singleton, Gets (and instantiates, and starts) the one CronDaemon instance.
 List<ProposedJobs.Event> getQueue()
           
 List<RunningCronEntry> getRunning()
           
 boolean interrupt(String machine, String entry, int id)
           
 boolean isAlive()
           
static void main(String[] argv)
          main only for testing purposes
 void notify(Events.Event event)
           
 void notify(ProposedJobs.Event event)
           
 void remove(CronEntry entry)
          Remove the given CronEntry from this daemon.
protected  void removeEntry(CronEntry entry)
          Actually removes, nor checks for removedEntries' and so on.
protected  void run()
          The main loop of the daemon.
 void start()
          Starts the daemon, which you might want to do if you have stopped if for some reason.
 void stop()
          If you like to temporary stop the daemon, call this.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

notify

public void notify(ProposedJobs.Event event)
Specified by:
notify in interface ProposedJobs.Listener

notify

public void notify(Events.Event event)
Specified by:
notify in interface Events.Listener

interrupt

public boolean interrupt(String machine,
                         String entry,
                         int id)

consumeJobs

protected void consumeJobs()
Consumes received job proposals


getQueue

public List<ProposedJobs.Event> getQueue()

getRunning

public List<RunningCronEntry> getRunning()

detectFailedJobs

protected void detectFailedJobs()

getById

protected static CronEntry getById(Set<CronEntry> set,
                                   String id)
Finds in given set the CronEntry with the given id.

Returns:
a CronEntry if found, null otherwise.

add

public void add(CronEntry entry)
Adds the given CronEntry to this daemon.

Throws:
RuntimeException - If an entry with the same id is present already (unless it is running and scheduled for removal already)

addEntry

protected void addEntry(CronEntry entry)
Actually adds, no checks for 'removedEntries' and so on.


getCronEntry

public CronEntry getCronEntry(String id)

remove

public void remove(CronEntry entry)
Remove the given CronEntry from this daemon. If the entry is currently running, it will be postponed until this job is ready.


removeEntry

protected void removeEntry(CronEntry entry)
Actually removes, nor checks for removedEntries' and so on.


getFirst

protected long getFirst()

start

public void start()
Starts the daemon, which you might want to do if you have stopped if for some reason. The daemon is already started on default.


stop

public void stop()
If you like to temporary stop the daemon, call this.


isAlive

public boolean isAlive()

getInstance

public static CronDaemon getInstance()
Singleton, Gets (and instantiates, and starts) the one CronDaemon instance.


run

protected void run()
The main loop of the daemon.


clear

public void clear()
Clears all queues

Since:
MMBase-1.9.2

getEntries

public Set<CronEntry> getEntries()
Since:
MMBase-1.8

toString

public String toString()
Overrides:
toString in class Object

main

public static void main(String[] argv)
                 throws Exception
main only for testing purposes

Throws:
Exception


MMBase 2.0-SNAPSHOT - null