|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.isti.util.ProgramSingleton
public class ProgramSingleton
Class ProgramSingleton manages a "program singleton" file used to determine if another instance of the given program is already running. The name of the "program singleton" file will be the program name given to the constructor plus the extension ".psf". While the file-manager thread created by this class is running, the file will be written to once every 30 seconds. 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()').
Nested Class Summary | |
---|---|
protected class |
ProgramSingleton.FileManagerThread
Class FileManagerThread defines the "program singleton" file managing thread. |
Field Summary | |
---|---|
protected ProgramSingleton.FileManagerThread |
fileManagerThreadObj
|
static java.lang.String |
SINGLETON_FILE_EXT
The singleton file extension. |
protected java.io.RandomAccessFile |
singletonFileAccessObj
|
protected java.io.File |
singletonFileObj
|
protected int |
UPDATE_INTERVAL_MS
|
Constructor Summary | |
---|---|
ProgramSingleton(java.io.File singletonFileObj)
Creates a "program singleton" file manager. |
|
ProgramSingleton(java.io.File parent,
java.lang.String programNameStr)
Creates a "program singleton" file manager. |
|
ProgramSingleton(java.lang.String programNameStr)
Creates a "program singleton" file manager. |
|
ProgramSingleton(java.lang.String parent,
java.lang.String programNameStr)
Creates a "program singleton" file manager. |
Method Summary | |
---|---|
void |
close()
Terminates the "program singleton" file manager thread and closes and deletes the "program singleton" file. |
boolean |
initialize()
Checks to see if another instance of the program is running and, if not, initializes the "program singleton" file manager thread. |
boolean |
isRunning()
Determines if another instance of the program is running or not. |
boolean |
waitForClose(int millis)
Wait for the program close. |
boolean |
waitForClose(int millis,
int retry)
Wait for the program close. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String SINGLETON_FILE_EXT
protected final java.io.File singletonFileObj
protected final int UPDATE_INTERVAL_MS
protected ProgramSingleton.FileManagerThread fileManagerThreadObj
protected java.io.RandomAccessFile singletonFileAccessObj
Constructor Detail |
---|
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 ProgramSingleton(java.io.File parent, java.lang.String programNameStr)
parent
- the parent file.programNameStr
- the program name to be used.public ProgramSingleton(java.io.File singletonFileObj)
singletonFileObj
- the singleton file object.Method Detail |
---|
public boolean isRunning()
public boolean initialize()
public void close()
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.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |