com.palantir.opensource.sysmon
Class SysmonDaemon

java.lang.Object
  extended by java.lang.Thread
      extended by com.palantir.opensource.sysmon.SysmonDaemon
All Implemented Interfaces:
Runnable

public class SysmonDaemon
extends Thread

SysmonDaemon can be used either as a component of a larger program or as standalone process (by invoking main(String[])).

In standalone mode, it is run as a normal Java class. It will look for a config file to override defaults by either consulting a the System property "sysmon.configPath" or from it's first non-VM command-line argument. Although it's called a daemon, it will not disassociate from the controlling terminal and run in the background - this capability is not provided by default by the Java VM. Pressing Ctrl-C will cause the process to exit.

To use the SysmonDaemon as a component of another program, construct a new instance and pass it a Properties object with any custom configuration - null is fine to pick up defaults. Construction will start a non-daemon background thread that can be shut down by shutdown()

Properties config = new Properties(); // ... // load config file if desired // ... // SysmonDaemon daemon = new SysmonDaemon(config); // background thread is now running // // ... // Do some other stuff // ... // daemon.shutdown();


Nested Class Summary
static class SysmonDaemon.ShutdownTask
          Simple task for parallel shutdown of monitors.
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
static String SYSTEM_PROPERTY_CONFIG_FILE
          System property used to specify the config file path.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SysmonDaemon(Properties config)
          Constructs a new SysmonDaemon object and determines its platform-specific SystemMonitor but does not start any monitoring.
 
Method Summary
static void configureDefaultLogging()
          Sets up log4j logging in the case where no external configuration has been specified.
static SystemMonitor determinePlatformMonitor()
          Since the number of platforms currently supported is small (one, to be exact), this is just a static method that must produce a SystemMonitor object to be run by the daemon.
static void main(String[] args)
          Runs the SysmonDaemon as a process.
 void run()
          Starts platform specific monitoring and then blocks in a non-daemon thread, waiting for a call to shutdown() to unblock it (by releasing a semaphore) and allowing the thread to exit.
 void shutdown()
          Shuts down this SysmonDaemon instance.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SYSTEM_PROPERTY_CONFIG_FILE

public static final String SYSTEM_PROPERTY_CONFIG_FILE
System property used to specify the config file path. Can be overridden by command line argument. Property: "sysmon.configPath"

See Also:
System.getProperties(), Constant Field Values
Constructor Detail

SysmonDaemon

public SysmonDaemon(Properties config)
             throws SysmonException
Constructs a new SysmonDaemon object and determines its platform-specific SystemMonitor but does not start any monitoring.

Throws:
SysmonException - upon error figuring out which class will be used as the SystemMonitor, initializing an instance of that class, or that instance's verification of the execution environment in this VM.
Method Detail

determinePlatformMonitor

public static final SystemMonitor determinePlatformMonitor()
                                                    throws SysmonException
Since the number of platforms currently supported is small (one, to be exact), this is just a static method that must produce a SystemMonitor object to be run by the daemon. A second and third platform could be trivially added to this method — after that, perhaps some sort of classpath-scanning reflective mechanism should be implemented to allow new platforms to be added to the system without changing this class.

Returns:
the object to be run by this daemon to monitor the current platform.
Throws:
SysmonException

run

public void run()
Starts platform specific monitoring and then blocks in a non-daemon thread, waiting for a call to shutdown() to unblock it (by releasing a semaphore) and allowing the thread to exit. This will keep the VM alive even as the platform monitors themselves are only running daemon threads.

Specified by:
run in interface Runnable
Overrides:
run in class Thread
See Also:
Thread.setDaemon(boolean)

shutdown

public void shutdown()
Shuts down this SysmonDaemon instance. Shutdown depends on all platform monitors to only start daemon threads.

See Also:
Thread.setDaemon(boolean)

configureDefaultLogging

public static void configureDefaultLogging()
Sets up log4j logging in the case where no external configuration has been specified. This is only called when this class is invoked via main(String[]). It sets up a single ConsoleAppender, thresholded at Level.WARN, and adds it to the root logger.


main

public static void main(String[] args)
Runs the SysmonDaemon as a process. Config file specified on command line takes precedence over SYSTEM_PROPERTY_CONFIG_FILE.

Parameters:
args - takes single argument: the path to the config file.


Copyright © 2012 Palantir Technologies. All Rights Reserved.