org.pf.util
Class SysUtil

java.lang.Object
  extended by org.pf.util.SysUtil

public class SysUtil
extends java.lang.Object

Provides generally useful methods for system inquiries and other system related functionality.

For example it is strongly recommended to uset exit(int) rather than System.exit(int) to terminate a JVM. It allows registered listeners to be notified just before the exit happens.

Version:
1.3
Author:
Manfred Duchrow

Field Summary
static java.lang.String OS_FAMILY_MACINTOSH
          "macintosh"
static java.lang.String OS_FAMILY_UNIX
          "unix"
static java.lang.String OS_FAMILY_UNKNOWN
          "unknown"
static java.lang.String OS_FAMILY_WINDOWS
          "windows"
 
Method Summary
 void addSystemExitListener(ISystemExitListener listener)
          Add the given listener to an internal list so that it would be called right before system exit gets executed via the exit(int) method.
static SysUtil current()
          Returns the only instance this class supports (design pattern "Singleton")
 void exit(int rc)
          Calling this method terminates the JVM.
 void exit(int rc, long sleepBeforeExit)
          Calling this method terminates the JVM after the specified sleep time.
 java.lang.String getOsFamily()
          Returns the family name of the current oparting system according to the name specified in system property "os.name".
 boolean isEclipse()
          Returns true if the environment is based on eclipse.
 boolean isWindows()
          Returns true if the current operating-system is Windows.
 void removeSystemExitListener(ISystemExitListener listener)
          Removes the given listener from the internal list so that it would not be notified anymore before system exit gets executed via the exit(int) method.
 void sleep(long milliseconds)
          Sets the current thread to sleep for the specified time in milliseconds or until it gets interrupted.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OS_FAMILY_UNKNOWN

public static final java.lang.String OS_FAMILY_UNKNOWN
"unknown"

See Also:
Constant Field Values

OS_FAMILY_WINDOWS

public static final java.lang.String OS_FAMILY_WINDOWS
"windows"

See Also:
Constant Field Values

OS_FAMILY_UNIX

public static final java.lang.String OS_FAMILY_UNIX
"unix"

See Also:
Constant Field Values

OS_FAMILY_MACINTOSH

public static final java.lang.String OS_FAMILY_MACINTOSH
"macintosh"

See Also:
Constant Field Values
Method Detail

current

public static SysUtil current()
Returns the only instance this class supports (design pattern "Singleton")


isWindows

public boolean isWindows()
Returns true if the current operating-system is Windows.


isEclipse

public boolean isEclipse()
Returns true if the environment is based on eclipse. That is, this class is loaded within an eclipse plug-in. Can also be defined by setting system property "org.pf.util.isEclipse" to true or false.


getOsFamily

public java.lang.String getOsFamily()
Returns the family name of the current oparting system according to the name specified in system property "os.name".

Returns:
"windows or "unix" or "macintosh" or "unknown" for all others
See Also:
OS_FAMILY_UNKNOWN, OS_FAMILY_UNIX, OS_FAMILY_MACINTOSH, OS_FAMILY_WINDOWS

sleep

public void sleep(long milliseconds)
Sets the current thread to sleep for the specified time in milliseconds or until it gets interrupted. Avoids throwing an InterruptedException.

Parameters:
milliseconds - The time to sleep

exit

public void exit(int rc)
Calling this method terminates the JVM.
It should be used instead of System.exit(int) because it will notify all registered ISystemExitListener before it actually calls System.exit(rc).

Parameters:
rc - The return code to the program that started the JVM.

exit

public void exit(int rc,
                 long sleepBeforeExit)
Calling this method terminates the JVM after the specified sleep time.
It should be used instead of System.exit(int) because it will notify all registered ISystemExitListener before it actually calls System.exit(rc).
This method waits the specified sleep time before it actually exits.

Parameters:
rc - The return code to the program that started the JVM.
sleepBeforeExit - The time to sleep (in milliseconds) before exiting.

addSystemExitListener

public void addSystemExitListener(ISystemExitListener listener)
Add the given listener to an internal list so that it would be called right before system exit gets executed via the exit(int) method.
If the listener is already in the internal listener list it will not be added again.

Parameters:
listener - The listener to add. Will be ignored if null.

removeSystemExitListener

public void removeSystemExitListener(ISystemExitListener listener)
Removes the given listener from the internal list so that it would not be notified anymore before system exit gets executed via the exit(int) method.
If the listener is not in the internal listener list, nothing happens.

Parameters:
listener - The listener to remove. Will be ignored if null.