au.com.lastweekend.jen.util
Class AbstractWatchdog

java.lang.Object
  extended by au.com.lastweekend.jen.util.LoopRunnable
      extended by au.com.lastweekend.jen.util.AbstractWatchdog
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
ProcessWatchdog

public abstract class AbstractWatchdog
extends LoopRunnable

Abstract class to continuously start a process

Version:
$Id$
Author:
Grant Gardner grant@lastweekend.com.au

Constructor Summary
AbstractWatchdog(java.lang.ProcessBuilder builder)
           
 
Method Summary
 java.lang.ProcessBuilder getBuilder()
           
protected abstract  void handleStandardError(java.io.InputStream stderr)
          Do something with stderr.
protected abstract  void handleStandardInput(java.io.OutputStream stdin)
          Do something with the stdin
protected abstract  void handleStandardOutput(java.io.InputStream stdout)
          Do something with stdout
protected  void loop()
          This method will run repeatedly until the stop method is called or the method throws an exception.
protected  void processDestroy()
          Called when the process is destroyed forcibly during the stop sequence.
protected  void processExit(int result)
          Called when the process terminates of its own accord (or some external kill)
protected  void processStart()
          Called each time the process is started
protected abstract  void startException(java.io.IOException e)
          Handle the IO exception thrown from builder.start()
protected  void waitInterrupted(java.lang.InterruptedException e)
          Handle the interrupt exception during the stop process.
 
Methods inherited from class au.com.lastweekend.jen.util.LoopRunnable
run, start, stop, stopAtShutdown, stopped
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractWatchdog

public AbstractWatchdog(java.lang.ProcessBuilder builder)
Method Detail

processExit

protected void processExit(int result)
Called when the process terminates of its own accord (or some external kill)

Parameters:
result -

processDestroy

protected void processDestroy()
Called when the process is destroyed forcibly during the stop sequence.


processStart

protected void processStart()
Called each time the process is started


waitInterrupted

protected void waitInterrupted(java.lang.InterruptedException e)
Handle the interrupt exception during the stop process.

Parameters:
e -

handleStandardInput

protected abstract void handleStandardInput(java.io.OutputStream stdin)
Do something with the stdin

Parameters:
stdin -

handleStandardOutput

protected abstract void handleStandardOutput(java.io.InputStream stdout)
Do something with stdout

Parameters:
stdout -

handleStandardError

protected abstract void handleStandardError(java.io.InputStream stderr)
Do something with stderr. Will not be called if builder.redirectErrorStream()

Parameters:
stderr -

startException

protected abstract void startException(java.io.IOException e)
Handle the IO exception thrown from builder.start()

Parameters:
e -

loop

protected final void loop()
Description copied from class: LoopRunnable
This method will run repeatedly until the stop method is called or the method throws an exception. The stop process works by interrupting the thread. If you want to escape your loop early check Thread.currentThread().isInterrupted() Wrapping some part of the loop in synchronized(this) {...} will block the stopping thread.

Specified by:
loop in class LoopRunnable

getBuilder

public java.lang.ProcessBuilder getBuilder()


Copyright © 2008. All Rights Reserved.