Class 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. Communication takes place either over a Pipe, or Socket. In either case, the Wrapper code will initializate its end of the communication and then launch Java in a separate process. In the case of a socket, the Wrapper will 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". In the case of a pipe, the Wrapper will set up a pair of named ports and then pass in a property named "wrapper.backend=pipe". The Wrapper and JVM will communicate via the pipes. 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". When the backend connection is a socket, it does not have any timeout set by default. For testing purposes it is possible to set a timeout in seconds using the following system property when launching the JVM. This will only be noticeable if it is shorter than the ping interval, and debug output is enabled: -Dwrapper.backend.so_timeout=300 This class is implemented as a singleton class. Generate JNI Headers with the following command in the build/classes directory: javah -jni -classpath ./ org.tanukisoftware.wrapper.WrapperManager
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      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 addWrapperEventListener​(org.tanukisoftware.wrapper.event.WrapperEventListener listener, long mask)
      Adds a WrapperEventListener which will receive WrapperEvents.
      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 void appearOrphan()
      Deprecated.
      Removed as of 3.5.8
      static void appearSlow​(int slowSeconds)
      (Testing Method) Causes the WrapperManager to go into a state which makes the JVM appear to be sluggish when viewed from the native Wrapper code.
      static WrapperProcess exec​(java.lang.String command)
      A more powerful replacement to the java.lang.Runtime.exec method.
      static WrapperProcess exec​(java.lang.String[] cmdArray)
      A more powerful replacement to the java.lang.Runtime.exec method.
      static WrapperProcess exec​(java.lang.String[] cmdArray, WrapperProcessConfig config)
      A more powerful replacement to the java.lang.Runtime.exec method.
      static WrapperProcess exec​(java.lang.String command, WrapperProcessConfig config)
      A more powerful replacement to the java.lang.Runtime.exec method.
      protected void finalize()  
      static void fireUserEvent​(int eventNr)
      Fires a user event user_n specified in the conf file
      static java.lang.String getArch()
      Returns the Architecture that the Wrapper has resolved.
      static java.lang.String getBuildTime()
      Obtain the build time of Wrapper.
      static WrapperUser getInteractiveUser​(boolean groups)
      Returns a WrapperUser object which describes the interactive user whose desktop is being interacted with.
      static int getJavaPID()
      Returns the PID of the Java process.
      static int getJVMId()
      Returns the Id of the current JVM.
      static java.lang.String getOS()
      Returns the OS that the Wrapper has resolved.
      static java.util.Properties getProperties()
      Returns a Properties object containing expanded the contents of the configuration file used to launch the Wrapper.
      static WrapperResources getRes()
      Returns the WrapperResources object which is used to manage all resources for the Java Service Wrapper.
      static WrapperUser getUser​(boolean groups)
      Returns a WrapperUser object which describes the user under which the Wrapper is currently running.
      static java.lang.String getVersion()
      Obtain the current version of Wrapper.
      static java.io.File getWrapperLogFile()
      Returns the Log file currently being used by the Wrapper.
      static int getWrapperPID()
      Returns the PID of the Wrapper process.
      static boolean hasShutdownHookBeenTriggered()
      Returns true if the ShutdownHook for the JVM has already been triggered.
      static boolean isAIX()
      Returns true if the current JVM is AIX.
      static boolean isControlledByNativeWrapper()
      Returns true if the JVM was launched by the Wrapper application.
      static boolean isDebugEnabled()
      Returns true if the wrapper.debug property, or any of the logging channels are set to DEBUG in the wrapper configuration file.
      static boolean isIgnoreUserLogoffs()
      Returns true if the JVM should ignore user logoff events.
      static boolean isLaunchedAsService()
      Returns true if the Wrapper was launched as an NT service on Windows or as a daemon process on UNIX platforms.
      static boolean isMacOSX()
      Returns true if the current JVM is Mac OSX.
      static boolean isNativeLibraryOk()
      Returns true if the native library has been loaded successfully, false otherwise.
      static boolean isProfessionalEdition()
      Returns true if the current Wrapper edition has support for Professional Edition features.
      static boolean isShuttingDown()
      Returns true if the JVM is in the process of shutting down.
      static boolean isStandardEdition()
      Returns true if the current Wrapper edition has support for Standard Edition features.
      static boolean isWindows()
      Returns true if the current JVM is Windows.
      static WrapperWin32Service[] listServices()
      Returns an array of all registered services.
      static WrapperResources loadWrapperResources​(java.lang.String domain, java.lang.String folder)
      Loads a WrapperResources based on the current locale of the JVM.
      static void log​(int logLevel, java.lang.String message)
      Requests that the Wrapper log a message at the specified log level.
      static int nativeGetDpiScale()  
      static void releaseShutdownLock()
      Called by a thread which has previously called requestShutdownLock().
      static void removeWrapperEventListener​(org.tanukisoftware.wrapper.event.WrapperEventListener listener)
      Removes a WrapperEventListener so it will not longer receive WrapperEvents.
      static void requestShutdownLock()
      Increase the number of locks which will prevent the Wrapper from letting the JVM process exit on shutdown.
      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.
      static void restartAndReturn()
      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()
      The main comm runner thread.
      static WrapperWin32Service sendServiceControlCode​(java.lang.String serviceName, int controlCode)
      Sends a service control code to the specified service.
      static void setConsoleTitle​(java.lang.String title)
      Sets the title of the console in which the Wrapper is running.
      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.
      static void stopAndReturn​(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.
      static void stopImmediate​(int exitCode)
      Tells the native wrapper that the JVM wants to shut down and then promptly halts.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • WRAPPER_CTRL_C_EVENT

        public static final int WRAPPER_CTRL_C_EVENT
        Received when the user presses CTRL-C in the console on Windows or UNIX platforms.
        See Also:
        Constant Field Values
      • WRAPPER_CTRL_CLOSE_EVENT

        public static final int WRAPPER_CTRL_CLOSE_EVENT
        Received when the user clicks on the close button of a Console on Windows.
        See Also:
        Constant Field Values
      • WRAPPER_CTRL_LOGOFF_EVENT

        public static final int WRAPPER_CTRL_LOGOFF_EVENT
        Received when the user logs off of a Windows system.
        See Also:
        Constant Field Values
      • WRAPPER_CTRL_SHUTDOWN_EVENT

        public static final int WRAPPER_CTRL_SHUTDOWN_EVENT
        Received when a Windows system is shutting down.
        See Also:
        Constant Field Values
      • WRAPPER_CTRL_TERM_EVENT

        public static final int WRAPPER_CTRL_TERM_EVENT
        Received when a SIG TERM is received on a UNIX system.
        See Also:
        Constant Field Values
      • WRAPPER_CTRL_HUP_EVENT

        public static final int WRAPPER_CTRL_HUP_EVENT
        Received when a SIG HUP is received on a UNIX system.
        See Also:
        Constant Field Values
      • WRAPPER_CTRL_USR1_EVENT

        public static final int WRAPPER_CTRL_USR1_EVENT
        Received when a SIG USR1 is received on a UNIX system.
        See Also:
        Constant Field Values
      • WRAPPER_CTRL_USR2_EVENT

        public static final int WRAPPER_CTRL_USR2_EVENT
        Received when a SIG USR2 is received on a UNIX system.
        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
      • WRAPPER_LOG_LEVEL_ADVICE

        public static final int WRAPPER_LOG_LEVEL_ADVICE
        Log message at advice log level.
        See Also:
        Constant Field Values
      • WRAPPER_LOG_LEVEL_NOTICE

        public static final int WRAPPER_LOG_LEVEL_NOTICE
        Log message at notice log level.
        See Also:
        Constant Field Values
      • SERVICE_CONTROL_CODE_START

        public static final int SERVICE_CONTROL_CODE_START
        Service Control code which can be sent to start a service.
        See Also:
        Constant Field Values
      • SERVICE_CONTROL_CODE_STOP

        public static final int SERVICE_CONTROL_CODE_STOP
        Service Control code which can be sent or received to stop a service.
        See Also:
        Constant Field Values
      • SERVICE_CONTROL_CODE_PAUSE

        public static final int SERVICE_CONTROL_CODE_PAUSE
        Service Control code which can be sent to pause a service.
        See Also:
        Constant Field Values
      • SERVICE_CONTROL_CODE_CONTINUE

        public static final int SERVICE_CONTROL_CODE_CONTINUE
        Service Control code which can be sent to resume a paused service.
        See Also:
        Constant Field Values
      • SERVICE_CONTROL_CODE_INTERROGATE

        public static final int SERVICE_CONTROL_CODE_INTERROGATE
        Service Control code which can be sent to or received interrogate the status of a service.
        See Also:
        Constant Field Values
      • SERVICE_CONTROL_CODE_SHUTDOWN

        public static final int SERVICE_CONTROL_CODE_SHUTDOWN
        Service Control code which can be received when the system is shutting down.
        See Also:
        Constant Field Values
      • SERVICE_CONTROL_CODE_POWEREVENT_QUERYSUSPEND

        public static final int SERVICE_CONTROL_CODE_POWEREVENT_QUERYSUSPEND
        Service Control code which is received when the system being suspended.
        See Also:
        Constant Field Values
      • SERVICE_CONTROL_CODE_POWEREVENT_QUERYSUSPENDFAILED

        public static final int SERVICE_CONTROL_CODE_POWEREVENT_QUERYSUSPENDFAILED
        Service Control code which is received when permission to suspend the computer was denied by a process. Support for this event was removed from the Windows OS starting with Vista.
        See Also:
        Constant Field Values
      • SERVICE_CONTROL_CODE_POWEREVENT_SUSPEND

        public static final int SERVICE_CONTROL_CODE_POWEREVENT_SUSPEND
        Service Control code which is received when the computer is about to enter a suspended state.
        See Also:
        Constant Field Values
      • SERVICE_CONTROL_CODE_POWEREVENT_RESUMECRITICAL

        public static final int SERVICE_CONTROL_CODE_POWEREVENT_RESUMECRITICAL
        Service Control code which is received when the system has resumed operation. This event can indicate that some or all applications did not receive a SERVICE_CONTROL_CODE_POWEREVENT_SUSPEND event. Support for this event was removed from the Windows OS starting with Vista. See SERVICE_CONTROL_CODE_POWEREVENT_RESUMEAUTOMATIC.
        See Also:
        Constant Field Values
      • SERVICE_CONTROL_CODE_POWEREVENT_RESUMESUSPEND

        public static final int SERVICE_CONTROL_CODE_POWEREVENT_RESUMESUSPEND
        Service Control code which is received when the system has resumed operation after being suspended.
        See Also:
        Constant Field Values
      • SERVICE_CONTROL_CODE_POWEREVENT_BATTERYLOW

        public static final int SERVICE_CONTROL_CODE_POWEREVENT_BATTERYLOW
        Service Control code which is received when the battery power is low. Support for this event was removed from the Windows OS starting with Vista. See SERVICE_CONTROL_CODE_POWEREVENT_POWERSTATUSCHANGE.
        See Also:
        Constant Field Values
      • SERVICE_CONTROL_CODE_POWEREVENT_POWERSTATUSCHANGE

        public static final int SERVICE_CONTROL_CODE_POWEREVENT_POWERSTATUSCHANGE
        Service Control code which is received when there is a change in the power status of the computer, such as a switch from battery power to A/C. The system also broadcasts this event when remaining battery power slips below the threshold specified by the user or if the battery power changes by a specified percentage.
        See Also:
        Constant Field Values
      • SERVICE_CONTROL_CODE_POWEREVENT_OEMEVENT

        public static final int SERVICE_CONTROL_CODE_POWEREVENT_OEMEVENT
        Service Control code which is received when the APM BIOS has signaled an APM OEM event. Support for this event was removed from the Windows OS starting with Vista.
        See Also:
        Constant Field Values
      • SERVICE_CONTROL_CODE_POWEREVENT_RESUMEAUTOMATIC

        public static final int SERVICE_CONTROL_CODE_POWEREVENT_RESUMEAUTOMATIC
        Service Control code which is received when the computer has woken up automatically to handle an event.
        See Also:
        Constant Field Values
    • Method Detail

      • getRes

        public static WrapperResources getRes()
        Returns the WrapperResources object which is used to manage all resources for the Java Service Wrapper.
        Returns:
        the Wrapper's resouces.
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • nativeGetDpiScale

        public static int nativeGetDpiScale()
      • loadWrapperResources

        public static WrapperResources loadWrapperResources​(java.lang.String domain,
                                                            java.lang.String folder)
        Loads a WrapperResources based on the current locale of the JVM.
        Parameters:
        domain - Domain of the resource.
        folder - Location of the resource.
        Returns:
        The requested resource.
      • getVersion

        public static java.lang.String getVersion()
        Obtain the current version of Wrapper.
        Returns:
        The version of the Wrapper.
      • getBuildTime

        public static java.lang.String getBuildTime()
        Obtain the build time of Wrapper.
        Returns:
        The time that the Wrapper was built.
      • 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.
        Returns:
        The Id of the current JVM.
      • exec

        public static WrapperProcess exec​(java.lang.String command)
                                   throws java.lang.SecurityException,
                                          java.io.IOException,
                                          java.lang.NullPointerException,
                                          java.lang.IllegalArgumentException,
                                          WrapperJNIError,
                                          WrapperLicenseError,
                                          java.lang.UnsatisfiedLinkError
        A more powerful replacement to the java.lang.Runtime.exec method.

        When the JVM exits or is terminated for any reason, the Wrapper will clean up any child processes launched with this method automatically before shutting down or launching a new JVM.

        This method is the same as calling

        WrapperManager.exec(command, new WrapperProcessConfig());

        The returned WrapperProcess object can be used to control the child process, supply input, or process output.

        Professional Edition feature.

        Parameters:
        command - A specified system command in one String.
        Returns:
        A new WrapperProcess object for managing the subprocess.
        Throws:
        java.io.IOException - Will be thrown if an I/O error occurs
        java.lang.NullPointerException - If command is null.
        java.lang.IllegalArgumentException - If command is empty
        java.lang.SecurityException - If a SecurityManager is present and its checkExec method doesn't allow creation of a subprocess.
        WrapperJNIError - If the native library has not been loaded or is in the process of shutting down.
        WrapperLicenseError - If the function is called other than in the Professional Edition or if the native library has not been loaded.
        java.lang.UnsatisfiedLinkError - If the posix_spawn function couldn't be found
        Since:
        Wrapper 3.4.0
        See Also:
        isProfessionalEdition(), exec(String command, WrapperProcessConfig config), WrapperProcessConfig
      • exec

        public static WrapperProcess exec​(java.lang.String command,
                                          WrapperProcessConfig config)
                                   throws java.lang.SecurityException,
                                          java.io.IOException,
                                          java.lang.NullPointerException,
                                          java.lang.IllegalArgumentException,
                                          WrapperJNIError,
                                          WrapperLicenseError,
                                          java.lang.UnsatisfiedLinkError
        A more powerful replacement to the java.lang.Runtime.exec method.

        By configuring the WrapperProcessConfig object, it is possible to control whether or not the child process will be automatically cleaned up when the JVM exits or is terminated. It is also possible to control how the child process is launched to work around memory issues on some platforms.

        For example, on Solaris when the JVM is very large, doing a fork will duplicate the entire JVM's memory space and cause an out of memory error or JVM crash, to avoid such memory problems the child process can be launched using posix spawn as follows:

        WrapperManager.exec( command, new WrapperProcessConfig().setStartType( WrapperProcessConfig.POSIX_SPAWN ) );

        Please review the WrapperProcessConfig class for a full list of options.

        The returned WrapperProcess object can be used to control the child process, supply input, or process output.

        Professional Edition feature.

        Parameters:
        command - A specified system command in one String.
        config - A WrapperProcessConfig object representing the Start/Run Configurations of the subprocess
        Returns:
        A new WrapperProcess object for managing the subprocess.
        Throws:
        java.io.IOException - Will be thrown if an I/O error occurs
        java.lang.NullPointerException - If command is null.
        java.lang.IllegalArgumentException - If command is empty or the configuration is invalid
        java.lang.SecurityException - If a SecurityManager is present and its checkExec method doesn't allow creation of a subprocess.
        WrapperJNIError - If the native library has not been loaded or is in the process of shutting down.
        WrapperLicenseError - If the function is called other than in the Professional Edition or if the native library has not been loaded.
        java.lang.UnsatisfiedLinkError - If the posix_spawn function couldn't be found
        Since:
        Wrapper 3.4.0
        See Also:
        isProfessionalEdition(), WrapperProcessConfig
      • exec

        public static WrapperProcess exec​(java.lang.String[] cmdArray)
                                   throws java.lang.SecurityException,
                                          java.io.IOException,
                                          java.lang.NullPointerException,
                                          java.lang.IndexOutOfBoundsException,
                                          java.lang.IllegalArgumentException,
                                          WrapperJNIError,
                                          java.lang.UnsatisfiedLinkError,
                                          WrapperLicenseError
        A more powerful replacement to the java.lang.Runtime.exec method.

        When the JVM exits or is terminated for any reason, the Wrapper will clean up any child processes launched with this method automatically before shutting down or launching a new JVM.

        This method is the same as calling

        WrapperManager.exec(cmdArray, new WrapperProcessConfig());

        The returned WrapperProcess object can be used to control the child process, supply input, or process output.

        Professional Edition feature.

        Parameters:
        cmdArray - A specified system command in array format for each parameter a single element.
        Returns:
        A new WrapperProcess object for managing the subprocess
        Throws:
        java.io.IOException - Will be thrown at any error realated with Memory allocation, or if the command does not exist.
        java.lang.NullPointerException - If cmdarray is null, or one of the elements of cmdarray is null.
        java.lang.IndexOutOfBoundsException - If cmdarray is an empty array (has length 0)
        java.lang.SecurityException - If a SecurityManager is present and its checkExec method doesn't allow creation of a subprocess.
        java.lang.IllegalArgumentException - If there are any problems with the WrapperProcessConfig object.
        WrapperJNIError - If the native library has not been loaded or is in the process of shutting down.
        WrapperLicenseError - If the function is called other than in the Professional Edition or if the native library has not been loaded.
        java.lang.UnsatisfiedLinkError - If the posix_spawn function couldn't be found
        Since:
        Wrapper 3.4.0
        See Also:
        isProfessionalEdition()
      • exec

        public static WrapperProcess exec​(java.lang.String[] cmdArray,
                                          WrapperProcessConfig config)
                                   throws java.lang.SecurityException,
                                          java.io.IOException,
                                          java.lang.NullPointerException,
                                          java.lang.IndexOutOfBoundsException,
                                          java.lang.IllegalArgumentException,
                                          WrapperJNIError,
                                          WrapperLicenseError,
                                          java.lang.UnsatisfiedLinkError
        A more powerful replacement to the java.lang.Runtime.exec method.

        By configuring the WrapperProcessConfig object, it is possible to control whether or not the child process will be automatically cleaned up when the JVM exits or is terminated. It is also possible to control how the child process is launched to work around memory issues on some platforms.

        For example, on Solaris when the JVM is very large, doing a fork will duplicate the entire JVM's memory space and cause an out of memory error or JVM crash, to avoid such memory problems the child process can be launched using posix spawn as follows:

        WrapperManager.exec( cmdArray, new WrapperProcessConfig().setStartType( WrapperProcessConfig.POSIX_SPAWN ) );

        Please review the WrapperProcessConfig class for a full list of options.

        The returned WrapperProcess object can be used to control the child process, supply input, or process output.

        Professional Edition feature.

        Parameters:
        cmdArray - A specified system command in array format, for each parameter a single element.
        config - A WrapperProcessConfig object representing the Start/Run Configurations of the subprocess
        Returns:
        A new WrapperProcess object for managing the subprocess.
        Throws:
        java.io.IOException - Will be thrown if an I/O error occurs
        java.lang.NullPointerException - If cmdarray is null, or one of the elements of cmdarray is null.
        java.lang.IndexOutOfBoundsException - If cmdarray is an empty array (has length 0)
        java.lang.SecurityException - If a SecurityManager is present and its checkExec method doesn't allow creation of a subprocess.
        java.lang.IllegalArgumentException - If there are any problems with the WrapperProcessConfig object.
        WrapperJNIError - If the native library has not been loaded or is in the process of shutting down.
        WrapperLicenseError - If the function is called other than in the Professional Edition or if the native library has not been loaded.
        java.lang.UnsatisfiedLinkError - If the posix_spawn function couldn't be found
        Since:
        Wrapper 3.4.0
        See Also:
        isProfessionalEdition()
      • isNativeLibraryOk

        public static boolean isNativeLibraryOk()
        Returns true if the native library has been loaded successfully, false otherwise. This value can switch to false on shutdown when the native library can no longer be reliably referenced.
        Returns:
        True if the native library is loaded and available.
      • getOS

        public static java.lang.String getOS()
        Returns the OS that the Wrapper has resolved. This will be the same as the WRAPPER_OS environment variable. Used when resolving the platform specific native library name.
        Returns:
        The resolved Wrapper OS name.
        Since:
        Wrapper 3.5.31
      • getArch

        public static java.lang.String getArch()
        Returns the Architecture that the Wrapper has resolved. This will be the same as the WRAPPER_ARCH environment variable. Used when resolving the platform specific native library name.
        Returns:
        The resolved Wrapper Architecture name.
        Since:
        Wrapper 3.5.31
      • isWindows

        public static boolean isWindows()
        Returns true if the current JVM is Windows.
        Returns:
        True if this is Windows.
        Since:
        Wrapper 3.5.1
      • isMacOSX

        public static boolean isMacOSX()
        Returns true if the current JVM is Mac OSX.
        Returns:
        True if this is Mac OSX.
        Since:
        Wrapper 3.5.1
      • isAIX

        public static boolean isAIX()
        Returns true if the current JVM is AIX.
        Returns:
        True if this is AIX.
        Since:
        Wrapper 3.5.27
      • isProfessionalEdition

        public static boolean isProfessionalEdition()
        Returns true if the current Wrapper edition has support for Professional Edition features. False will also be returned if the native library has not been initialized correctly.
        Returns:
        True if professional features are supported.
      • isStandardEdition

        public static boolean isStandardEdition()
        Returns true if the current Wrapper edition has support for Standard Edition features. False will also be returned if the native library has not been initialized correctly.
        Returns:
        True if standard features are supported.
      • fireUserEvent

        public static void fireUserEvent​(int eventNr)
        Fires a user event user_n specified in the conf file
        Parameters:
        eventNr - The user-event number to fire. Must be in the range of 1-32767.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("fireUserEvent") permission.
        WrapperLicenseError - If the function is called other than in the Professional Edition or if the native library has not been loaded.
      • setConsoleTitle

        public static void setConsoleTitle​(java.lang.String title)
        Sets the title of the console in which the Wrapper is running. This is currently only supported on Windows platforms.

        As an alternative, it is also possible to set the console title from within the wrapper.conf file using the wrapper.console.title property.

        Parameters:
        title - The new title. The specified string will be encoded to a byte array using the default encoding for the current platform.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("setConsoleTitle") permission.
        See Also:
        WrapperPermission
      • getUser

        public static WrapperUser getUser​(boolean groups)
        Returns a WrapperUser object which describes the user under which the Wrapper is currently running. Additional platform specific information can be obtained by casting the object to a platform specific subclass. WrapperWin32User, for example.
        Parameters:
        groups - True if the user's groups should be returned as well. Requesting the groups that a user belongs to increases the CPU load required to complete the call.
        Returns:
        An object describing the current user.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("getUser") permission.
        See Also:
        WrapperPermission
      • getInteractiveUser

        public static WrapperUser getInteractiveUser​(boolean groups)
        Returns a WrapperUser object which describes the interactive user whose desktop is being interacted with. When a service running on a Windows platform has its interactive flag set, this method will return the user who is currently logged in. Additional platform specific information can be obtained by casting the object to a platform specific subclass. WrapperWin32User, for example.

        If a user is not currently logged on then this method will return null. User code can repeatedly call this method to detect when a user has logged in. To detect when a user has logged out, there are two options. 1) The user code can continue to call this method until it returns null. 2) Or if the WrapperListener method is being implemented, the WrapperListener.controlEvent method will receive a WRAPPER_CTRL_LOGOFF_EVENT event when the user logs out.

        On XP systems, it is possible to switch to another account rather than actually logging out. In such a case, the interactive user will be the first user that logged in. This will also be the only user with which the service will interact. If other users are logged in when the interactive user logs out, the service will not automatically switch to another logged in user. Rather, the next user to log in will become the new user which the service will interact with.

        This method will always return NULL on versions of NT prior to Windows 2000. This can not be helped as some required functions were not added to the windows API until NT version 5.0, also known as Windows 2000.

        Parameters:
        groups - True if the user's groups should be returned as well. Requesting the groups that a user belongs to increases the CPU load required to complete the call.
        Returns:
        The current interactive user, or null.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("getInteractiveUser") permission.
        See Also:
        WrapperPermission
      • getProperties

        public static java.util.Properties getProperties()
        Returns a Properties object containing expanded the contents of the configuration file used to launch the Wrapper. All properties are included so it is possible to define properties not used by the Wrapper in the configuration file and have then be available in this Properties object.
        Returns:
        The contents of the Wrapper configuration file.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("getProperties") permission.
        See Also:
        WrapperPermission
      • getWrapperPID

        public static int getWrapperPID()
        Returns the PID of the Wrapper process. A PID of 0 will be returned if the JVM was launched standalone. This value can also be obtained using the 'wrapper.pid' system property.
        Returns:
        The PID of the Wrpper process.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("getWrapperPID") permission.
        See Also:
        WrapperPermission
      • getJavaPID

        public static int getJavaPID()
        Returns the PID of the Java process. A PID of 0 will be returned if the native library has not been initialized. This value can also be obtained using the 'wrapper.java.pid' system property.
        Returns:
        The PID of the Java process.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("getJavaPID") permission.
        See Also:
        WrapperPermission
      • 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.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("requestThreadDump") permission.
        See Also:
        WrapperPermission
      • 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.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("test.appearHung") permission.
        See Also:
        WrapperPermission
      • appearSlow

        public static void appearSlow​(int slowSeconds)
        (Testing Method) Causes the WrapperManager to go into a state which makes the JVM appear to be sluggish when viewed from the native Wrapper code. Each packet received from the Wrapper is delayed by the specified number of seconds. If several packets are received in succession then this delay will be cumulative. The delay reported by the Wrapper may appear to be quite a bit different if multiple packets are being delayed in series. Some packets, like pings, which are sent multiple times may also be reported as being processed faster than this delay because the previous response is what is actually being received. Does not have any effect when the JVM is not being controlled from the native Wrapper. Useful for testing the Wrapper functions.
        Parameters:
        slowSeconds - The number of seconds to delay reponding to any incoming commands from the wrapper.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("test.appearSlow") permission.
        See Also:
        WrapperPermission
      • appearOrphan

        public static void appearOrphan()
        Deprecated.
        Removed as of 3.5.8
      • 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 which does not exist in newer JVMs. Use of the accessViolationNative() method is preferred.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("test.accessViolation") permission.
        See Also:
        WrapperPermission
      • 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.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("test.accessViolationNative") permission.
        See Also:
        WrapperPermission
      • 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.
        Returns:
        True if the current JVM was launched by the Wrapper.
      • isLaunchedAsService

        public static boolean isLaunchedAsService()
        Returns true if the Wrapper was launched as an NT service on Windows or as a daemon process on UNIX platforms. False if launched as a console. This can be useful if you wish to display a user interface when in Console mode. On UNIX platforms, this is not as useful because an X display may not be visible even if launched in a console.
        Returns:
        True if the Wrapper is running as an NT service or daemon process.
      • isIgnoreUserLogoffs

        public static boolean isIgnoreUserLogoffs()
        Returns true if the JVM should ignore user logoff events. Mainly used within WrapperListener.controlEvent() method implemenations.
        Returns:
        True if user logoff events should be ignroed.
      • isDebugEnabled

        public static boolean isDebugEnabled()
        Returns true if the wrapper.debug property, or any of the logging channels are set to DEBUG in the wrapper configuration file. Useful for deciding whether or not to output certain information to the console.
        Returns:
        True if the Wrapper is logging any Debug level output.
      • 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.

        This method must be called on startup and then can only be called once so there is no reason for any security permission checks on this call.

        Parameters:
        listener - The WrapperListener instance which represents the application being started.
        args - The argument list passed to the JVM when it was launched.
      • isShuttingDown

        public static boolean isShuttingDown()
        Returns true if the JVM is in the process of shutting down. This can be useful to avoid starting long running processes when it is known that the JVM will be shutting down shortly.
        Returns:
        true if the JVM is shutting down.
      • requestShutdownLock

        public static void requestShutdownLock()
                                        throws WrapperShuttingDownException
        Increase the number of locks which will prevent the Wrapper from letting the JVM process exit on shutdown. This is primarily useful around calls to native JNI functions in daemon threads where it has been shown that premature JVM exits can cause the JVM process to crash on shutdown.

        Normal non-daemon threads should not require these locks as the very fact that the non-daemon thread is still running will prevent the JVM from shutting down.

        It is possible to make multiple calls within a single thread. Each call should always be paired with a call to releaseShutdownLock().

        Throws:
        WrapperShuttingDownException - If called after the Wrapper has already begun the shutdown of the JVM.
      • releaseShutdownLock

        public static void releaseShutdownLock()
                                        throws java.lang.IllegalStateException
        Called by a thread which has previously called requestShutdownLock().
        Throws:
        java.lang.IllegalStateException - If called without first calling requestShutdownLock() from the same thread.
      • restart

        public static void restart()
                            throws java.lang.SecurityException
        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.

        This method will not return.

        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("restart") permission.
        See Also:
        WrapperPermission
      • restartAndReturn

        public static void restartAndReturn()
                                     throws java.lang.SecurityException
        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.

        This method requests that the JVM be restarted but then returns. This allows components to initiate a JVM exit and then continue, allowing a normal shutdown initiated by the JVM via shutdown hooks. In applications which are designed to be shutdown when the user presses CTRL-C, this may result in a cleaner shutdown.

        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("restart") permission.
        See Also:
        WrapperPermission
      • 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.

        This method will not return.

        Parameters:
        exitCode - The exit code that the Wrapper will return when it exits.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("stop") permission.
        See Also:
        WrapperPermission
      • stopAndReturn

        public static void stopAndReturn​(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.

        This method requests that the JVM be shutdown but then returns. This allows components to initiate a JVM exit and then continue, allowing a normal shutdown initiated by the JVM via shutdown hooks. In applications which are designed to be shutdown when the user presses CTRL-C, this may result in a cleaner shutdown.

        Parameters:
        exitCode - The exit code that the Wrapper will return when it exits.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("stop" ) permission.
        See Also:
        WrapperPermission
      • stopImmediate

        public static void stopImmediate​(int exitCode)
        Tells the native wrapper that the JVM wants to shut down and then promptly halts. Be careful when using this method as an application will not be given a chance to shutdown cleanly.
        Parameters:
        exitCode - The exit code that the Wrapper will return when it exits.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("stopImmediate") permission.
        See Also:
        WrapperPermission
      • signalStarting

        public static void signalStarting​(int waitHint)
        Signal the native wrapper that the startup is progressing but that more time is needed. The current startup timeout will be extended if necessary so it will be at least 'waitHint' milliseconds in the future.

        This call will have no effect if the current startup timeout is already more than 'waitHint' milliseconds in the future.

        Parameters:
        waitHint - Time in milliseconds to allow for the startup to complete.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("signalStarting") permission.
        See Also:
        WrapperPermission
      • signalStopping

        public static void signalStopping​(int waitHint)
        Signal the native wrapper that the shutdown is progressing but that more time is needed. The current shutdown timeout will be extended if necessary so it will be at least 'waitHint' milliseconds in the future.

        This call will have no effect if the current shutdown timeout is already more than 'waitHint' milliseconds in the future.

        Parameters:
        waitHint - Time in milliseconds to allow for the shutdown to complete.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("signalStopping") permission.
        See Also:
        WrapperPermission
      • 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.
        Parameters:
        exitCode - The exit code.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("signalStopped") permission.
        See Also:
        WrapperPermission
      • hasShutdownHookBeenTriggered

        public static boolean hasShutdownHookBeenTriggered()
        Returns true if the ShutdownHook for the JVM has already been triggered. Some code needs to know whether or not the system is shutting down.
        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.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("log") permission.
        See Also:
        WrapperPermission
      • listServices

        public static WrapperWin32Service[] listServices()
                                                  throws java.lang.SecurityException
        Returns an array of all registered services. This method is only supported on Windows platforms which support services. Calling this method on other platforms will result in null being returned.
        Returns:
        An array of services.
        Throws:
        java.lang.SecurityException - If a SecurityManager has not been set in the JVM or if the calling code has not been granted the WrapperPermission "listServices" permission. A SecurityManager is required for this operation because this method makes it possible to learn a great deal about the state of the system.
        See Also:
        WrapperPermission
      • sendServiceControlCode

        public static WrapperWin32Service sendServiceControlCode​(java.lang.String serviceName,
                                                                 int controlCode)
                                                          throws WrapperServiceException,
                                                                 java.lang.SecurityException
        Sends a service control code to the specified service. The state of the service should be tested on return. If the service was not currently running then the control code will not be sent.

        The control code sent can be one of the system control codes: WrapperManager.SERVICE_CONTROL_CODE_START, WrapperManager.SERVICE_CONTROL_CODE_STOP, WrapperManager.SERVICE_CONTROL_CODE_PAUSE, WrapperManager.SERVICE_CONTROL_CODE_CONTINUE, or WrapperManager.SERVICE_CONTROL_CODE_INTERROGATE. In addition, user defined codes in the range 128-255 can also be sent.

        Parameters:
        serviceName - Name of the Windows service which will receive the control code.
        controlCode - The actual control code to be sent. User defined control codes should be in the range 128-255.
        Returns:
        A WrapperWin32Service containing the last known status of the service after sending the control code. This will be null if the currently platform is not a version of Windows which supports services.
        Throws:
        WrapperServiceException - If there are any problems accessing the specified service.
        java.lang.SecurityException - If a SecurityManager has not been set in the JVM or if the calling code has not been granted the WrapperServicePermission permission for the specified service and control code. A SecurityManager is required for this operation because this method makes it possible to control any service on the system, which is of course rather dangerous.
        See Also:
        WrapperServicePermission
      • addWrapperEventListener

        public static void addWrapperEventListener​(org.tanukisoftware.wrapper.event.WrapperEventListener listener,
                                                   long mask)
        Adds a WrapperEventListener which will receive WrapperEvents. The specific events can be controlled using the mask parameter. This API was chosen to allow for additional events in the future. To avoid future compatibility problems, WrapperEventListeners should always test the class of an event before making use of it. This will avoid problems caused by new event classes added in future versions of the Wrapper. This method should only be called once for a given WrapperEventListener. Build up a single mask to receive events of multiple types.
        Parameters:
        listener - WrapperEventListener to be start receiving events.
        mask - A mask specifying the event types that the listener is interrested in receiving. See the WrapperEventListener class for a full list of flags. A mask is created by combining multiple flags using the binary '|' OR operator.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the appropriate WrapperEventPermission(...) permission.
        See Also:
        WrapperEventPermission
      • removeWrapperEventListener

        public static void removeWrapperEventListener​(org.tanukisoftware.wrapper.event.WrapperEventListener listener)
        Removes a WrapperEventListener so it will not longer receive WrapperEvents.
        Parameters:
        listener - WrapperEventListener to be stop receiving events.
        Throws:
        java.lang.SecurityException - If a SecurityManager is present and the calling thread does not have the WrapperPermission("removeWrapperEventListener") permission.
        See Also:
        WrapperPermission
      • getWrapperLogFile

        public static java.io.File getWrapperLogFile()
        Returns the Log file currently being used by the Wrapper. If log file rolling is enabled in the Wrapper then this file may change over time.
        Returns:
        The Wrapper log file.
        Throws:
        java.lang.IllegalStateException - If this method is called before the Wrapper instructs this class to start the user application.
      • run

        public void run()
        The main comm runner thread. This will only be called when the Wrapper is controlling the JVM.
        Specified by:
        run in interface java.lang.Runnable