info.rolandkrueger.roklib.system
Class VMStatSwappingDetectionThread

java.lang.Object
  extended by java.lang.Thread
      extended by info.rolandkrueger.roklib.system.MemorySwappingDetectionThread
          extended by info.rolandkrueger.roklib.system.VMStatSwappingDetectionThread
All Implemented Interfaces:
Runnable

public class VMStatSwappingDetectionThread
extends MemorySwappingDetectionThread

This class is a concrete implementation of the abstract class MemorySwappingDetectionThread where the program vmstat is used for detecting memory swapping. When the thread is started, vmstat is invoked with an update delay of a configurable number of seconds. The thread will then evaluate the output of vmstat upon each update. If the swap in/out column of vmstat's output differs from 0 the object registered as MemorySwappingEventListener will be notified of that event.

Note: Detecting memory paging with an external, platform-dependent tool such as vmstat is of course detrimental to the application's portability. This strategy was chosen, though, since it offered an easy to implement method for swapping detection. Unfortunately, the Java language as yet doesn't offer any general machanisms to detect these memory paging situations in a portable way. If there are any better ways to cope with that in the future, an appropriate method can be implemented as a subclass of MemorySwappingDetectionThread.

Author:
Roland Krueger

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
private static String CMD_STRING
           
private  String mLine
           
private  Matcher mMatcher
           
private  BufferedReader mProcessReader
           
private  int mSamplingRate
           
private  String mVMStatBinaryLocation
           
private  Process mVMStatProcess
           
protected static Logger sLogger
           
private static Pattern SWAP_PATTERN
          Regular expression that extracts the swap in and swap out columns of the vmstat output.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
VMStatSwappingDetectionThread(MemorySwappingEventListener listener, String vmstatBinaryLocation, int samplingRate)
          Constructor.
 
Method Summary
protected  boolean isSwapEventDetected()
          Returns true if a memory paging event was detected
 boolean startProcess()
          Starts the vmstat command in an own process.
protected  void stopThreadImpl()
          Implementations of this method define the actions that have to be taken prior to stopping this thread.
 
Methods inherited from class info.rolandkrueger.roklib.system.MemorySwappingDetectionThread
notifyListenerOfSwappingEvent, run, stopThread
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sLogger

protected static Logger sLogger

CMD_STRING

private static final String CMD_STRING
See Also:
Constant Field Values

SWAP_PATTERN

private static final Pattern SWAP_PATTERN
Regular expression that extracts the swap in and swap out columns of the vmstat output.


mVMStatBinaryLocation

private String mVMStatBinaryLocation

mSamplingRate

private int mSamplingRate

mVMStatProcess

private Process mVMStatProcess

mProcessReader

private BufferedReader mProcessReader

mLine

private String mLine

mMatcher

private Matcher mMatcher
Constructor Detail

VMStatSwappingDetectionThread

public VMStatSwappingDetectionThread(MemorySwappingEventListener listener,
                                     String vmstatBinaryLocation,
                                     int samplingRate)
Constructor.

Parameters:
listener - object that implements the MemorySwappingEventListener interface
vmstatBinaryLocation - the location of the vmstat command. This is usually /usr/bin/vmstat.
samplingRate - the update delay for vmstat
Method Detail

startProcess

public boolean startProcess()
Starts the vmstat command in an own process.

Returns:
true if the process was successfully started

isSwapEventDetected

protected boolean isSwapEventDetected()
Description copied from class: MemorySwappingDetectionThread
Returns true if a memory paging event was detected

Specified by:
isSwapEventDetected in class MemorySwappingDetectionThread
Returns:
true if a memory paging event was detected

stopThreadImpl

protected void stopThreadImpl()
Description copied from class: MemorySwappingDetectionThread
Implementations of this method define the actions that have to be taken prior to stopping this thread.

Specified by:
stopThreadImpl in class MemorySwappingDetectionThread


Copyright © 2007-2011. All Rights Reserved.