com.silveregg.wrapper
Class WrapperManager

java.lang.Object
  |
  +--com.silveregg.wrapper.WrapperManager
All Implemented Interfaces:
java.lang.Runnable

public final class WrapperManager
extends java.lang.Object
implements java.lang.Runnable

Handles all communication with the native portion of the Wrapper code. The native wrapper code will launch Java in a separate process and set up a server socket which the Java code is expected to open a socket to on startup. When the server socket is created, a port will be chosen depending on what is available to the system. This port will then be passed to the Java process as property named "wrapper.port". For security reasons, the native code will only allow connections from localhost and will expect to receive the key specified in a property named "wrapper.key". This class is implemented as a singleton class. Generate JNI Headers with the following command in the build/classes directory: javah -jni -classpath ./ com.silveregg.wrapper.WrapperManager


Field Summary
static int WRAPPER_CTRL_C_EVENT
           
static int WRAPPER_CTRL_CLOSE_EVENT
           
static int WRAPPER_CTRL_LOGOFF_EVENT
           
static int WRAPPER_CTRL_SHUTDOWN_EVENT
           
static int WRAPPER_LOG_LEVEL_DEBUG
          Log message at debug log level.
static int WRAPPER_LOG_LEVEL_ERROR
          Log message at error log level.
static int WRAPPER_LOG_LEVEL_FATAL
          Log message at fatal log level.
static int WRAPPER_LOG_LEVEL_INFO
          Log message at info log level.
static int WRAPPER_LOG_LEVEL_STATUS
          Log message at status log level.
static int WRAPPER_LOG_LEVEL_WARN
          Log message at warn log level.
 
Method Summary
static void accessViolation()
          (Testing Method) Cause an access violation within the Java code.
static void accessViolationNative()
          (Testing Method) Cause an access violation within native JNI code.
static void appearHung()
          (Testing Method) Causes the WrapperManager to go into a state which makes the JVM appear to be hung when viewed from the native Wrapper code.
static java.lang.String getBuildTime()
          Obtain the build time of Wrapper.
static int getJVMId()
          Returns the Id of the current JVM.
protected static int getNonDaemonThreadCount()
          Returns a count of all non-daemon threads in the JVM, starting with the top thread group.
static java.lang.String getVersion()
          Obtain the current version of Wrapper.
static boolean hasShutdownHookBeenTriggered()
          Returns true if the ShutdownHook for the JVM has already been triggered.
static boolean isControlledByNativeWrapper()
          Returns true if the JVM was launched by the Wrapper application.
static boolean isDebugEnabled()
          Returns true if the wrapper.debug property is set the wrapper config file.
static boolean isLaunchedAsService()
          Returns true if the Wrapper was launched as a service (Windows only).
static void log(int logLevel, java.lang.String message)
          Requests that the Wrapper log a message at the specified log level.
static void requestThreadDump()
          Requests that the current JVM process request a thread dump.
static void restart()
          Tells the native wrapper that the JVM wants to restart, then informs all listeners that the JVM is about to shutdown before killing the JVM.
 void run()
           
static void signalStarting(int waitHint)
          Signal the native wrapper that the startup is progressing but that more time is needed.
static void signalStopped(int exitCode)
          This method should not normally be called by user code as it is called from within the stop and restart methods.
static void signalStopping(int waitHint)
          Signal the native wrapper that the shutdown is progressing but that more time is needed.
static void start(WrapperListener listener, java.lang.String[] args)
          Start the Java side of the Wrapper code running.
static void stop(int exitCode)
          Tells the native wrapper that the JVM wants to shut down, then informs all listeners that the JVM is about to shutdown before killing the JVM.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WRAPPER_CTRL_C_EVENT

public static final int WRAPPER_CTRL_C_EVENT
See Also:
Constant Field Values

WRAPPER_CTRL_CLOSE_EVENT

public static final int WRAPPER_CTRL_CLOSE_EVENT
See Also:
Constant Field Values

WRAPPER_CTRL_LOGOFF_EVENT

public static final int WRAPPER_CTRL_LOGOFF_EVENT
See Also:
Constant Field Values

WRAPPER_CTRL_SHUTDOWN_EVENT

public static final int WRAPPER_CTRL_SHUTDOWN_EVENT
See Also:
Constant Field Values

WRAPPER_LOG_LEVEL_DEBUG

public static final int WRAPPER_LOG_LEVEL_DEBUG
Log message at debug log level.

See Also:
Constant Field Values

WRAPPER_LOG_LEVEL_INFO

public static final int WRAPPER_LOG_LEVEL_INFO
Log message at info log level.

See Also:
Constant Field Values

WRAPPER_LOG_LEVEL_STATUS

public static final int WRAPPER_LOG_LEVEL_STATUS
Log message at status log level.

See Also:
Constant Field Values

WRAPPER_LOG_LEVEL_WARN

public static final int WRAPPER_LOG_LEVEL_WARN
Log message at warn log level.

See Also:
Constant Field Values

WRAPPER_LOG_LEVEL_ERROR

public static final int WRAPPER_LOG_LEVEL_ERROR
Log message at error log level.

See Also:
Constant Field Values

WRAPPER_LOG_LEVEL_FATAL

public static final int WRAPPER_LOG_LEVEL_FATAL
Log message at fatal log level.

See Also:
Constant Field Values
Method Detail

getVersion

public static java.lang.String getVersion()
Obtain the current version of Wrapper.


getBuildTime

public static java.lang.String getBuildTime()
Obtain the build time of Wrapper.


getJVMId

public static int getJVMId()
Returns the Id of the current JVM. JVM Ids increment from 1 each time the wrapper restarts a new one.


requestThreadDump

public static void requestThreadDump()
Requests that the current JVM process request a thread dump. This is the same as pressing CTRL-BREAK (under Windows) or CTRL-\ (under Unix) in the the console in which Java is running. This method does nothing if the native library is not loaded.


appearHung

public static void appearHung()
(Testing Method) Causes the WrapperManager to go into a state which makes the JVM appear to be hung when viewed from the native Wrapper code. Does not have any effect when the JVM is not being controlled from the native Wrapper. Useful for testing the Wrapper functions.


accessViolation

public static void accessViolation()
(Testing Method) Cause an access violation within the Java code. Useful for testing the Wrapper functions. This currently only crashes Sun JVMs and takes advantage of Bug #4369043


accessViolationNative

public static void accessViolationNative()
(Testing Method) Cause an access violation within native JNI code. Useful for testing the Wrapper functions. This currently causes the access violation by attempting to write to a null pointer.


isControlledByNativeWrapper

public static boolean isControlledByNativeWrapper()
Returns true if the JVM was launched by the Wrapper application. False if the JVM was launched manually without the Wrapper controlling it.


isLaunchedAsService

public static boolean isLaunchedAsService()
Returns true if the Wrapper was launched as a service (Windows only). False if launched as a console. This can be useful if you wish to display a user interface when in Console mode. On unix systems, the Wrapper is always launched as a console application, so this method will always return false.


isDebugEnabled

public static boolean isDebugEnabled()
Returns true if the wrapper.debug property is set the wrapper config file.


start

public static void start(WrapperListener listener,
                         java.lang.String[] args)
Start the Java side of the Wrapper code running. This will make it possible for the native side of the Wrapper to detect that the Java Wrapper is up and running.


restart

public static void restart()
Tells the native wrapper that the JVM wants to restart, then informs all listeners that the JVM is about to shutdown before killing the JVM.


stop

public static void stop(int exitCode)
Tells the native wrapper that the JVM wants to shut down, then informs all listeners that the JVM is about to shutdown before killing the JVM.


signalStarting

public static void signalStarting(int waitHint)
Signal the native wrapper that the startup is progressing but that more time is needed.


signalStopping

public static void signalStopping(int waitHint)
Signal the native wrapper that the shutdown is progressing but that more time is needed.


signalStopped

public static void signalStopped(int exitCode)
This method should not normally be called by user code as it is called from within the stop and restart methods. However certain applications which stop the JVM may need to call this method to let the wrapper code know that the shutdown was intentional.


hasShutdownHookBeenTriggered

public static boolean hasShutdownHookBeenTriggered()
Returns true if the ShutdownHook for the JVM has already been triggered.


log

public static void log(int logLevel,
                       java.lang.String message)
Requests that the Wrapper log a message at the specified log level. If the JVM is not being managed by the Wrapper then calls to this method will be ignored. This method has been optimized to ignore messages at a log level which will not be logged given the current log levels of the Wrapper.

Log messages will currently by trimmed by the Wrapper at 4k (4096 bytes).

Because of differences in the way console output is collected and messages logged via this method, it is expected that interspersed console and log messages will not be in the correct order in the resulting log file.

This method was added to allow simple logging to the wrapper.log file. This is not meant to be a full featured log file and should not be used as such. Please look into a logging package for most application logging.

Parameters:
logLevel - The level to log the message at can be one of WRAPPER_LOG_LEVEL_DEBUG, WRAPPER_LOG_LEVEL_INFO, WRAPPER_LOG_LEVEL_STATUS, WRAPPER_LOG_LEVEL_WARN, WRAPPER_LOG_LEVEL_ERROR, or WRAPPER_LOG_LEVEL_FATAL.
message - The message to be logged.

getNonDaemonThreadCount

protected static int getNonDaemonThreadCount()
Returns a count of all non-daemon threads in the JVM, starting with the top thread group.

Returns:
Number of non-daemon threads.

run

public void run()
Specified by:
run in interface java.lang.Runnable


Copyright 2000, 2001 SilverEgg Technology Corp. All Rights Reserved.