com.claritysys.util
Class Daemon

java.lang.Object
  extended by com.claritysys.util.Daemon

public class Daemon
extends java.lang.Object

Provides an abstraction for daemon programs to detect when to shutdown.

It does this by monitoring for the presence of a file, whose path is specified as a configuration parameter. The file can optionally be deleted as the process terminates.

Configure by passing it a Properties object with the following properties defined:

Example:

   Properties properties = new Properties ();
   properties.load (new FileInputStream ("myapp.properties"));
   Daemon daemon = new Daemon (properties);
   while (!daemon.isProcessEnding ()) {
     // Continue running!

     // Nothing to do?
     if (nothingToDo) {
        try {Thread.sleep (5000);} catch (Exception e) {}
     }
   }
 

Version:
$Revision: 2348 $ $Date: 2004-12-01 16:12:21 -0800 (Wed, 01 Dec 2004) $

Field Summary
protected  java.io.File shutdownFile
          Field shutdownFile
protected  boolean shutdownFileAutoDelete
          Field shutdownFileAutoDelete
protected  java.lang.String shutdownFileName
          Our standard batch job control mechanism - shutdown files.
 
Constructor Summary
Daemon(java.util.Properties properties)
          Create a new Daemon from properties.
Daemon(java.lang.String shutdownFileName, boolean autoDelete)
          Create a new Daemon.
 
Method Summary
 boolean isProcessEnding()
          Return true if its time to shut down.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

shutdownFileName

protected java.lang.String shutdownFileName
Our standard batch job control mechanism - shutdown files.


shutdownFileAutoDelete

protected boolean shutdownFileAutoDelete
Field shutdownFileAutoDelete


shutdownFile

protected java.io.File shutdownFile
Field shutdownFile

Constructor Detail

Daemon

public Daemon(java.lang.String shutdownFileName,
              boolean autoDelete)
Create a new Daemon.

Parameters:
shutdownFileName - The path to the shutdown file.
autoDelete - If true, delete the file as we exit.

Daemon

public Daemon(java.util.Properties properties)
Create a new Daemon from properties.

Parameters:
properties - See the class javadoc for a description of the properties that are read.
Method Detail

isProcessEnding

public boolean isProcessEnding()
Return true if its time to shut down.

Returns:
true if the shutdown file was detected and the process should end.


Copyright ? 2002 Clarity Systems Group, LLC. All Rights Reserved.