org.opengts.util
Class OSTools

java.lang.Object
  extended by org.opengts.util.OSTools

public class OSTools
extends java.lang.Object


Field Summary
static int OS_BSD
           
static int OS_BSD_FREEBSD
           
static int OS_LINUX
           
static int OS_LINUX_CENTOS
           
static int OS_LINUX_DEBIAN
           
static int OS_LINUX_FEDORA
           
static int OS_LINUX_UBUNTU
           
static int OS_MACOS
           
static int OS_MACOS_X
           
static int OS_SUBTYPE_MASK
           
static int OS_TYPE_MASK
           
static int OS_UNIX
           
static int OS_UNIX_AIX
           
static int OS_UNIX_DIGITAL
           
static int OS_UNIX_HPUX
           
static int OS_UNIX_IRIX
           
static int OS_UNIX_SOLARIS
           
static int OS_UNIX_SUNOS
           
static int OS_UNKNOWN
           
static int OS_WINDOWS
           
static int OS_WINDOWS_2000
           
static int OS_WINDOWS_2003
           
static int OS_WINDOWS_7
           
static int OS_WINDOWS_9X
           
static int OS_WINDOWS_CE
           
static int OS_WINDOWS_CYGWIN
           
static int OS_WINDOWS_NT
           
static int OS_WINDOWS_VISTA
           
static int OS_WINDOWS_XP
           
static java.lang.String PROPERTY_JAVA_HOME
           
static java.lang.String PROPERTY_JAVA_SPECIFICATION_VERSION
           
static java.lang.String PROPERTY_JAVA_VENDOR
           
 
Constructor Summary
OSTools()
           
 
Method Summary
static void checkMemoryUsage(boolean reset)
          Analyzes/Prints the current memory usage.
(This method only analyzes/prints memory usage if the current usage is less than the previous usage, implying that a garbage collection has recently occured)
Useful for determining IF there are memory leaks, and how much it is leaking, but useless for determining WHERE the leak is occurring.
static java.lang.String[] createJavaCommand(java.lang.String[] classpath, java.lang.String className, java.lang.String[] args)
          Returns a Java command set up to be executed by Runtime.getRuntime().exec(...)
static java.lang.Class getCallerClass(int frame)
          Gets the class of the caller at the specified frame index
static java.lang.String getHostIP()
          Gets the current host IP address
static java.lang.String getHostName()
          Gets the current host name
static long[] getMemoryUsage(long[] L)
          Get the current memory usage (in number of bytes)
static java.lang.String getMemoryUsageStringMb()
          Get the current memory usage String
static int getOSType()
          Returns the known OS type as an integer bitmask
static java.lang.String getOSTypeName(int type, boolean inclSubtype)
          Returns the String representation of the specified OS type
static int getProcessID()
          Gets the Process-ID of this JVM invocation.
IMPORTANT: This implementation relies on a "convention", rather that a documented method of obtaining the process-id of this JVM within the OS.
static boolean hasGetCallerClass()
          Returns true if 'sun.reflect.Reflection' is present in the runtime libraries.
(will return true when running with the Sun Microsystems version of Java)
static boolean instanceOf(java.lang.Object obj, java.lang.String className)
          Returns true if the specified object is an instance of (or equal to) the specified class name.
static boolean isBrokenToFront()
          Returns true if this implementation has a broken 'toFront' Swing implementation.
(may only be applicable on Java v1.4.2)
static boolean isLinux()
          Returns true if the OS is Unix/Linux
static boolean isMacOS()
          Returns true if the OS is Apple Mac OS
static boolean isMacOSX()
          Returns true if the OS is Apple Mac OS X
static boolean isOSType(int type)
          Returns true if the OS is the specified type
static boolean isOSType(int type, int subType)
          Returns true if the OS is the specified type
static boolean isSunJava()
          Returns true if executed from a Sun Microsystems JVM.
static boolean isUnknown()
          Returns true if the OS is unknown
static boolean isWindows()
          Returns true if the OS is a flavor of Windows
static boolean isWindows9X()
          Returns true if the OS is Windows 95/98
static boolean isWindowsXP()
          Returns true if the OS is Windows XP
static void main(java.lang.String[] argv)
          Main entry point for testing/debugging
static void printCallerClasses()
          Prints the class of the caller (debug purposes only)
static void printMemoryUsage()
          Prints the current memory usage to the log file
static void printMemoryUsageMXBean()
          Prints the current memory usage to the log file
static boolean sleepMS(long ms)
          Sleeps for the specified number of milliseconds
static boolean sleepSec(long sec)
          Sleeps for the specified number of seconds
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OS_TYPE_MASK

public static final int OS_TYPE_MASK
See Also:
Constant Field Values

OS_SUBTYPE_MASK

public static final int OS_SUBTYPE_MASK
See Also:
Constant Field Values

OS_UNKNOWN

public static final int OS_UNKNOWN
See Also:
Constant Field Values

OS_LINUX

public static final int OS_LINUX
See Also:
Constant Field Values

OS_LINUX_FEDORA

public static final int OS_LINUX_FEDORA
See Also:
Constant Field Values

OS_LINUX_CENTOS

public static final int OS_LINUX_CENTOS
See Also:
Constant Field Values

OS_LINUX_UBUNTU

public static final int OS_LINUX_UBUNTU
See Also:
Constant Field Values

OS_LINUX_DEBIAN

public static final int OS_LINUX_DEBIAN
See Also:
Constant Field Values

OS_UNIX

public static final int OS_UNIX
See Also:
Constant Field Values

OS_UNIX_SOLARIS

public static final int OS_UNIX_SOLARIS
See Also:
Constant Field Values

OS_UNIX_SUNOS

public static final int OS_UNIX_SUNOS
See Also:
Constant Field Values

OS_UNIX_AIX

public static final int OS_UNIX_AIX
See Also:
Constant Field Values

OS_UNIX_DIGITAL

public static final int OS_UNIX_DIGITAL
See Also:
Constant Field Values

OS_UNIX_HPUX

public static final int OS_UNIX_HPUX
See Also:
Constant Field Values

OS_UNIX_IRIX

public static final int OS_UNIX_IRIX
See Also:
Constant Field Values

OS_BSD

public static final int OS_BSD
See Also:
Constant Field Values

OS_BSD_FREEBSD

public static final int OS_BSD_FREEBSD
See Also:
Constant Field Values

OS_MACOS

public static final int OS_MACOS
See Also:
Constant Field Values

OS_MACOS_X

public static final int OS_MACOS_X
See Also:
Constant Field Values

OS_WINDOWS

public static final int OS_WINDOWS
See Also:
Constant Field Values

OS_WINDOWS_9X

public static final int OS_WINDOWS_9X
See Also:
Constant Field Values

OS_WINDOWS_XP

public static final int OS_WINDOWS_XP
See Also:
Constant Field Values

OS_WINDOWS_VISTA

public static final int OS_WINDOWS_VISTA
See Also:
Constant Field Values

OS_WINDOWS_7

public static final int OS_WINDOWS_7
See Also:
Constant Field Values

OS_WINDOWS_CE

public static final int OS_WINDOWS_CE
See Also:
Constant Field Values

OS_WINDOWS_NT

public static final int OS_WINDOWS_NT
See Also:
Constant Field Values

OS_WINDOWS_2000

public static final int OS_WINDOWS_2000
See Also:
Constant Field Values

OS_WINDOWS_2003

public static final int OS_WINDOWS_2003
See Also:
Constant Field Values

OS_WINDOWS_CYGWIN

public static final int OS_WINDOWS_CYGWIN
See Also:
Constant Field Values

PROPERTY_JAVA_HOME

public static final java.lang.String PROPERTY_JAVA_HOME
See Also:
Constant Field Values

PROPERTY_JAVA_VENDOR

public static final java.lang.String PROPERTY_JAVA_VENDOR
See Also:
Constant Field Values

PROPERTY_JAVA_SPECIFICATION_VERSION

public static final java.lang.String PROPERTY_JAVA_SPECIFICATION_VERSION
See Also:
Constant Field Values
Constructor Detail

OSTools

public OSTools()
Method Detail

getOSType

public static int getOSType()
Returns the known OS type as an integer bitmask

Returns:
The OS type

getOSTypeName

public static java.lang.String getOSTypeName(int type,
                                             boolean inclSubtype)
Returns the String representation of the specified OS type

Parameters:
type - The OS type
Returns:
The OS type name

isOSType

public static boolean isOSType(int type)
Returns true if the OS is the specified type

Returns:
True if the OS is the specified type

isOSType

public static boolean isOSType(int type,
                               int subType)
Returns true if the OS is the specified type

Returns:
True if the OS is the specified type

isUnknown

public static boolean isUnknown()
Returns true if the OS is unknown

Returns:
True if the OS is unknown

isWindows

public static boolean isWindows()
Returns true if the OS is a flavor of Windows

Returns:
True if the OS is a flavor of Windows

isWindowsXP

public static boolean isWindowsXP()
Returns true if the OS is Windows XP

Returns:
True if the OS is Windows XP

isWindows9X

public static boolean isWindows9X()
Returns true if the OS is Windows 95/98

Returns:
True if the OS is Windows 95/98

isLinux

public static boolean isLinux()
Returns true if the OS is Unix/Linux

Returns:
True if the OS is Unix/Linux

isMacOS

public static boolean isMacOS()
Returns true if the OS is Apple Mac OS

Returns:
True if the OS is Apple Mac OS

isMacOSX

public static boolean isMacOSX()
Returns true if the OS is Apple Mac OS X

Returns:
True if the OS is Apple Mac OS X

getHostName

public static java.lang.String getHostName()
Gets the current host name

Returns:
The current hostname

getHostIP

public static java.lang.String getHostIP()
Gets the current host IP address

Returns:
The current IP address

getMemoryUsage

public static long[] getMemoryUsage(long[] L)
Get the current memory usage (in number of bytes)

Parameters:
L - The long array where the memory values will be placed. If 'null', is specified, or if the array has fewer than 3 elements, a new long array will be returned. then the array must be
Returns:
The current memory usage as an array of 3 long values indicating { MaxMemory, TotalMemory, FreeMemory } (in that order).

getMemoryUsageStringMb

public static java.lang.String getMemoryUsageStringMb()
Get the current memory usage String


printMemoryUsage

public static void printMemoryUsage()
Prints the current memory usage to the log file


printMemoryUsageMXBean

public static void printMemoryUsageMXBean()
Prints the current memory usage to the log file


checkMemoryUsage

public static void checkMemoryUsage(boolean reset)
Analyzes/Prints the current memory usage.
(This method only analyzes/prints memory usage if the current usage is less than the previous usage, implying that a garbage collection has recently occured)
Useful for determining IF there are memory leaks, and how much it is leaking, but useless for determining WHERE the leak is occurring.

Parameters:
reset - True to reset the memory growth-rate checks.

isBrokenToFront

public static boolean isBrokenToFront()
Returns true if this implementation has a broken 'toFront' Swing implementation.
(may only be applicable on Java v1.4.2)

Returns:
True if this implementation has a broken 'toFront' Swing implementation.

isSunJava

public static boolean isSunJava()
Returns true if executed from a Sun Microsystems JVM.

Returns:
True is executed from a Sun Microsystems JVM.

getCallerClass

public static java.lang.Class getCallerClass(int frame)
Gets the class of the caller at the specified frame index

Parameters:
frame - The frame index
Returns:
The calling class

hasGetCallerClass

public static boolean hasGetCallerClass()
Returns true if 'sun.reflect.Reflection' is present in the runtime libraries.
(will return true when running with the Sun Microsystems version of Java)

Returns:
True if 'getCallerClass' is available.

printCallerClasses

public static void printCallerClasses()
Prints the class of the caller (debug purposes only)


getProcessID

public static int getProcessID()
Gets the Process-ID of this JVM invocation.
IMPORTANT: This implementation relies on a "convention", rather that a documented method of obtaining the process-id of this JVM within the OS. Caveat Emptor!
(On Windows, this returns the 'WINPID' which is probably useless anyway)

Returns:
The Process-ID

createJavaCommand

public static java.lang.String[] createJavaCommand(java.lang.String[] classpath,
                                                   java.lang.String className,
                                                   java.lang.String[] args)
Returns a Java command set up to be executed by Runtime.getRuntime().exec(...)

Parameters:
classpath - The classpath
className - The main Java class name
args - The command line arguments
Returns:
A command to call and it's arguments

instanceOf

public static boolean instanceOf(java.lang.Object obj,
                                 java.lang.String className)
Returns true if the specified object is an instance of (or equal to) the specified class name.


sleepMS

public static boolean sleepMS(long ms)
Sleeps for the specified number of milliseconds

Parameters:
ms - Number of milliseconds to sleep
Returns:
True if sleep was performed without interruption, false otherwise

sleepSec

public static boolean sleepSec(long sec)
Sleeps for the specified number of seconds

Parameters:
sec - Number of milliseconds to sleep
Returns:
True if sleep was performed without interruption, false otherwise

main

public static void main(java.lang.String[] argv)
Main entry point for testing/debugging

Parameters:
argv - Comand-line arguments