com.caucho.admin
Class PingThread

java.lang.Object
  extended by com.caucho.admin.PingThread
All Implemented Interfaces:
EnvironmentListener, AlarmListener, java.lang.Runnable, java.util.EventListener
Direct Known Subclasses:
PingMailer, PingThread

@Configurable
@Unbound
@Singleton
public class PingThread
extends java.lang.Object
implements java.lang.Runnable, AlarmListener, EnvironmentListener

A thread to restart the Resin server if it fails for some reason.

This pinging only catches some problems because it's running in the same JDK process as Resin itself. If the entire JDK freezes, this thread will freeze as well. Assuming the JDK doesn't freeze, the PingThread will catch errors like deadlocks.


Constructor Summary
PingThread()
           
 
Method Summary
 void addUrl(java.lang.String url)
          Adds a new URL to be tested.
protected  boolean checkPing(Path url, int count)
          Called to check if the connection is alive.
 void environmentBind(EnvironmentClassLoader loader)
          Bind the ping.
 void environmentConfigure(EnvironmentClassLoader loader)
          Configure the ping.
 void environmentStart(EnvironmentClassLoader loader)
          Start the pinger.
 void environmentStop(EnvironmentClassLoader loader)
          Stop the pinger.
 java.lang.String getPingHost()
          Returns the server's ping host
 int getPingPort()
          Returns the server's ping port
 long getRetryTime()
          Gets the retry time between failing pings
 long getSleepTime()
          Gets the sleep time between pings
 long getSocketTimeout()
          Gets the time to wait on a non-responsive socket before giving up.
 int getTryCount()
          Gets the number of times to retry before giving up
 void handleAlarm(Alarm alarm)
          Periodically pings the server to check for anything going wrong.
 void init()
          Initialize the pinger.
protected  void pingFailed(Path url)
          Called if the ping completely fails.
protected  void pingFailedOnce(Path url, int count, ReadStream is)
          Called if the ping fails once.
 void run()
          The ping thread checks to make sure the alarm has been successful.
 void setFreezeTimeout(Period freezeTimeout)
          Sets the response time to detect a frozen jvm
 void setInitialSleepTime(Period sleepTime)
          Sets the sleep time on startup
 void setPingHost(java.lang.String pingHost)
          Sets the server's ping host
 void setPingPort(int pingPort)
          Sets the server's ping port
 void setRetryTime(Period retryTime)
          Sets the retry time between failing pings
 void setSleepTime(Period sleepTime)
          Sets the sleep time between pings
 void setSocketTimeout(Period timeout)
          Sets the number of times to retry before giving up
 void setTryCount(int tryCount)
          Sets the number of times to retry before giving up
 void stop()
          Stop the pinger.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PingThread

public PingThread()
Method Detail

getPingHost

public java.lang.String getPingHost()
Returns the server's ping host


setPingHost

@Configurable
public void setPingHost(java.lang.String pingHost)
Sets the server's ping host


getPingPort

public int getPingPort()
Returns the server's ping port


setPingPort

@Configurable
public void setPingPort(int pingPort)
Sets the server's ping port


addUrl

@Configurable
public void addUrl(java.lang.String url)
Adds a new URL to be tested.


getSleepTime

public long getSleepTime()
Gets the sleep time between pings


setSleepTime

@Configurable
public void setSleepTime(Period sleepTime)
Sets the sleep time between pings


setFreezeTimeout

@Configurable
public void setFreezeTimeout(Period freezeTimeout)
Sets the response time to detect a frozen jvm


setInitialSleepTime

@Configurable
public void setInitialSleepTime(Period sleepTime)
Sets the sleep time on startup


getRetryTime

public long getRetryTime()
Gets the retry time between failing pings


setRetryTime

@Configurable
public void setRetryTime(Period retryTime)
Sets the retry time between failing pings


getTryCount

public int getTryCount()
Gets the number of times to retry before giving up


setTryCount

@Configurable
public void setTryCount(int tryCount)
Sets the number of times to retry before giving up


getSocketTimeout

public long getSocketTimeout()
Gets the time to wait on a non-responsive socket before giving up.


setSocketTimeout

@Configurable
public void setSocketTimeout(Period timeout)
Sets the number of times to retry before giving up


init

@PostConstruct
public void init()
Initialize the pinger.


environmentStart

public void environmentStart(EnvironmentClassLoader loader)
Start the pinger.

Specified by:
environmentStart in interface EnvironmentListener

environmentStop

public void environmentStop(EnvironmentClassLoader loader)
Stop the pinger.

Specified by:
environmentStop in interface EnvironmentListener

environmentConfigure

public void environmentConfigure(EnvironmentClassLoader loader)
Configure the ping.

Specified by:
environmentConfigure in interface EnvironmentListener

environmentBind

public void environmentBind(EnvironmentClassLoader loader)
Bind the ping.

Specified by:
environmentBind in interface EnvironmentListener

handleAlarm

public void handleAlarm(Alarm alarm)
Periodically pings the server to check for anything going wrong.

Specified by:
handleAlarm in interface AlarmListener

run

public void run()
The ping thread checks to make sure the alarm has been successful. PingThread uses this separate thread to minimize the possible freezes. run() can only freeze if the entire JVM is frozen and in that case, there's nothing a Java-based ping can do about the situation.

Specified by:
run in interface java.lang.Runnable

checkPing

protected boolean checkPing(Path url,
                            int count)
                     throws java.lang.Exception
Called to check if the connection is alive. An custom class might override checkPing if it wanted to handle a different status.

Parameters:
url - the url to test
count - the number of times the url has been checked without success.
Returns:
true if the ping succeeds
Throws:
java.lang.Exception

pingFailedOnce

protected void pingFailedOnce(Path url,
                              int count,
                              ReadStream is)
                       throws java.lang.Exception
Called if the ping fails once.

Throws:
java.lang.Exception

pingFailed

protected void pingFailed(Path url)
                   throws java.lang.Exception
Called if the ping completely fails.

Throws:
java.lang.Exception

stop

public void stop()
Stop the pinger.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object