|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.opengts.util.OSTools
public class OSTools
Nested Class Summary | |
---|---|
static class |
OSTools.CpuUsage
|
static class |
OSTools.DiskUsage
|
static class |
OSTools.MemoryUsage
|
Field Summary | |
---|---|
static long |
G_BYTES
|
static long |
K_BYTES
|
static long |
M_BYTES
|
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 int |
exec(java.lang.String[] cmdArgs,
java.lang.StringBuffer outSB,
java.lang.StringBuffer errSB)
Executes the specified command in a separate process |
static java.lang.Class |
getCallerClass(int frame)
Gets the class of the caller at the specified frame index |
static OSTools.CpuUsage |
getCpuUsage()
Gets the CPU usage information |
static OSTools.CpuUsage |
getCpuUsage(OSTools.CpuUsage cpu,
boolean displayWarnings)
Gets the CPU usage information |
static java.lang.String |
getCpuUsageString()
Get the current CPU usage String Note: may not be supported on all platforms |
static java.lang.String |
getCpuUsageString(boolean longFmt)
Get the current CPU usage String Note: may not be supported on all platforms |
static java.lang.String |
getHostIP()
Gets the current host IP address |
static java.lang.String |
getHostName()
Gets the current host name |
static java.lang.instrument.Instrumentation |
getInstrumentation()
Gets the Instrumentation instance |
static java.lang.String |
getJavaHome()
Gets the Java home directory as a String |
static java.lang.String |
getJavaVendor()
Gets the Java vendor |
static java.lang.String |
getJavaVersion()
Gets the Java version |
static java.lang.String |
getMemoryUnits(long D)
|
static OSTools.MemoryUsage |
getMemoryUsage(OSTools.MemoryUsage mu)
Gets the current memory usage (in number of bytes) for the current process |
static java.lang.String |
getMemoryUsageStringMb()
Get the current memory usage String |
static java.lang.String |
getMemoryUsageStringMb(boolean longFmt)
Get the current memory usage String |
static double |
getMemoryUtilization()
Gets the current memory utilization (as a percent/100). |
static long |
getObjectSize(java.lang.Object obj)
Gets the byte size of the specified Object. |
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 java.lang.String |
getSerialNumber()
Attempts to get the computer serial number by executing specific commands to obtain the value from the operating system. |
static OSTools.DiskUsage |
getSystemDiskUsage(java.io.File dir,
OSTools.DiskUsage du)
Gets the System Disk usage information |
static OSTools.MemoryUsage |
getSystemMemoryUsage(OSTools.MemoryUsage mu)
Gets the System Memory usage information |
static java.lang.String |
getUniqueSystemID()
Attempts to get a unique system ID. This ID may be suitable for a GPS tracking "UniqueID", however absolute uniqueness may not be guaranteed. Currently, the returned ID is based on the localhost MAC address, if available. |
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 |
premain(java.lang.String agentArgs,
java.lang.instrument.Instrumentation inst)
"premain" entry point used to obtain an Instramentation instance |
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 int |
readPidFile(java.io.File pidFile)
Reads the PID previously written to the specified file |
static void |
setInstrumentation(java.lang.instrument.Instrumentation inst)
Sets the Instrumentation instance. |
static boolean |
sleepMS(long ms)
Sleeps for the specified number of milliseconds |
static boolean |
sleepSec(long sec)
Sleeps for the specified number of seconds |
static boolean |
writePidFile(java.io.File pidFile,
boolean overwrite)
Writes the current PID into the specified file |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int OS_TYPE_MASK
public static final int OS_SUBTYPE_MASK
public static final int OS_UNKNOWN
public static final int OS_LINUX
public static final int OS_LINUX_FEDORA
public static final int OS_LINUX_CENTOS
public static final int OS_LINUX_UBUNTU
public static final int OS_LINUX_DEBIAN
public static final int OS_UNIX
public static final int OS_UNIX_SOLARIS
public static final int OS_UNIX_SUNOS
public static final int OS_UNIX_AIX
public static final int OS_UNIX_DIGITAL
public static final int OS_UNIX_HPUX
public static final int OS_UNIX_IRIX
public static final int OS_BSD
public static final int OS_BSD_FREEBSD
public static final int OS_MACOS
public static final int OS_MACOS_X
public static final int OS_WINDOWS
public static final int OS_WINDOWS_9X
public static final int OS_WINDOWS_XP
public static final int OS_WINDOWS_VISTA
public static final int OS_WINDOWS_7
public static final int OS_WINDOWS_CE
public static final int OS_WINDOWS_NT
public static final int OS_WINDOWS_2000
public static final int OS_WINDOWS_2003
public static final int OS_WINDOWS_CYGWIN
public static final long K_BYTES
public static final long M_BYTES
public static final long G_BYTES
public static final java.lang.String PROPERTY_JAVA_HOME
public static final java.lang.String PROPERTY_JAVA_VENDOR
public static final java.lang.String PROPERTY_JAVA_SPECIFICATION_VERSION
Constructor Detail |
---|
public OSTools()
Method Detail |
---|
public static int getOSType()
public static java.lang.String getOSTypeName(int type, boolean inclSubtype)
type
- The OS type
public static boolean isOSType(int type)
public static boolean isOSType(int type, int subType)
public static boolean isUnknown()
public static boolean isWindows()
public static boolean isWindowsXP()
public static boolean isWindows9X()
public static boolean isLinux()
public static boolean isMacOS()
public static boolean isMacOSX()
public static java.lang.String getHostName()
public static java.lang.String getHostIP()
public static java.lang.String getSerialNumber()
public static java.lang.String getUniqueSystemID()
public static OSTools.CpuUsage getCpuUsage()
public static OSTools.CpuUsage getCpuUsage(OSTools.CpuUsage cpu, boolean displayWarnings)
cpu
- The CpuUsage instance into which the CPU information is written.displayWarnings
- True to display warnings encountered when attempting read CPU information.
public static java.lang.String getCpuUsageString(boolean longFmt)
public static java.lang.String getCpuUsageString()
public static java.lang.String getMemoryUnits(long D)
public static OSTools.MemoryUsage getSystemMemoryUsage(OSTools.MemoryUsage mu)
mu
- The MemoryUsage instance into which the memory information is written
public static OSTools.DiskUsage getSystemDiskUsage(java.io.File dir, OSTools.DiskUsage du)
dir
- A directory of the partition for which the disk usage will be returned.du
- The DiskUsage instance into which the disk information is written
public static double getMemoryUtilization()
public static OSTools.MemoryUsage getMemoryUsage(OSTools.MemoryUsage mu)
mu
- Am OSTools.MemoryUsage instance that will be updates with the memory usage values.
If 'null', a new MemoryUsage instance will be created.
public static java.lang.String getMemoryUsageStringMb()
public static java.lang.String getMemoryUsageStringMb(boolean longFmt)
public static void printMemoryUsage()
public static void printMemoryUsageMXBean()
public static void checkMemoryUsage(boolean reset)
reset
- True to reset the memory growth-rate checks.public static java.lang.String getJavaVersion()
public static java.lang.String getJavaVendor()
public static java.lang.String getJavaHome()
public static void setInstrumentation(java.lang.instrument.Instrumentation inst)
public static java.lang.instrument.Instrumentation getInstrumentation()
public static long getObjectSize(java.lang.Object obj)
public static void premain(java.lang.String agentArgs, java.lang.instrument.Instrumentation inst)
public static boolean isBrokenToFront()
public static boolean isSunJava()
public static java.lang.Class getCallerClass(int frame)
frame
- The frame index
public static boolean hasGetCallerClass()
public static void printCallerClasses()
public static int getProcessID()
public static boolean writePidFile(java.io.File pidFile, boolean overwrite)
pidFile
- The pid file to writeoverwrite
- True to overwrite if file already exists
public static int readPidFile(java.io.File pidFile)
pidFile
- The file from which the PID is read (must have ".pid" extension).
public static java.lang.String[] createJavaCommand(java.lang.String[] classpath, java.lang.String className, java.lang.String[] args)
classpath
- The classpathclassName
- The main Java class name (or .jar file)args
- The command line arguments
public static int exec(java.lang.String[] cmdArgs, java.lang.StringBuffer outSB, java.lang.StringBuffer errSB)
cmdArgs
- The command and arguments to executeoutSB
- The StringBuffer into which the stdOut output is placederrSB
- The StringBuffer into which the stdErr output is placed
public static boolean instanceOf(java.lang.Object obj, java.lang.String className)
public static boolean sleepMS(long ms)
ms
- Number of milliseconds to sleep
public static boolean sleepSec(long sec)
sec
- Number of milliseconds to sleep
public static void main(java.lang.String[] argv)
argv
- Comand-line arguments
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |