public class ProgramSingleton
extends java.lang.Object
The standard usage of this class is to call the 'initialize()' method in the main method of the program (aborting if the method returns false) and call the 'close()' method from the shutdown-hook for the program (setup via 'Runtime.getRuntime().addShutdownHook()').
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SINGLETON_FILE_EXT
The singleton file extension.
|
Constructor and Description |
---|
ProgramSingleton(java.io.File singletonFileObj)
Creates a "program singleton" file.
|
ProgramSingleton(java.io.File parent,
java.lang.String programNameStr)
Creates a "program singleton" file.
|
ProgramSingleton(java.lang.String programNameStr)
Creates a "program singleton" file.
|
ProgramSingleton(java.lang.String parent,
java.lang.String programNameStr)
Creates a "program singleton" file.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Unlocks and deletes the "program singleton" file.
|
boolean |
initialize()
Checks to see if another instance of the program is running and, if not,
creates and locks a "program singleton" file.
|
boolean |
isRunning()
Determines if this program is running or not.
|
java.lang.String |
toString()
Returns a string representation of the object.
|
boolean |
waitForClose(int millis)
Wait for the program close.
|
boolean |
waitForClose(int millis,
int retry)
Wait for the program close.
|
public static final java.lang.String SINGLETON_FILE_EXT
public ProgramSingleton(java.io.File singletonFileObj)
singletonFileObj
- the singleton file object.public ProgramSingleton(java.io.File parent, java.lang.String programNameStr)
parent
- the parent file.programNameStr
- the program name to be used.public ProgramSingleton(java.lang.String programNameStr)
programNameStr
- the program name to be used.public ProgramSingleton(java.lang.String parent, java.lang.String programNameStr)
parent
- the parent pathname string.programNameStr
- the program name to be used.public void close()
public boolean initialize()
public boolean isRunning()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean waitForClose(int millis)
millis
- Waits at most millis milliseconds for this program to close.
A timeout of 0 means to wait forever.public boolean waitForClose(int millis, int retry)
millis
- Waits at most millis milliseconds for this program to close.
A timeout of 0 means to wait forever.retry
- the number of millis to wait between retries.