Package ca.cgjennings.apps.util
Class InstanceController
- java.lang.Object
-
- ca.cgjennings.apps.util.InstanceController
-
- All Implemented Interfaces:
java.lang.Runnable
public class InstanceController extends java.lang.Object implements java.lang.Runnable
Prevents multiple instances of a program from running. On startup, the class'smakeExclusive
method will be called with any file parameters from the command line. This method will attempt to create a server on a certain port. If it fails, it assumes a previous instance has already registered the port. In this case, it sends a message to the existing server to identify itself and to specify which file(s) to were requested on this instance's command line. This method will returntrue
if the calling instance should keep running after the method returns, orfalse
if it should stop. Afalse
return value indicates that the program arguments were successfully sent to an instance that is already running. A value oftrue
indicates that the current instance is the first, exclusive instance, or that the method is unable to verify whether an existing instance is running.- Author:
- Chris Jennings
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static void
callListener(InstanceControllerListener l, boolean initial, java.lang.String[] args)
static boolean
makeExclusive(java.lang.String programName, int port, java.lang.String[] args, InstanceControllerListener listener)
void
run()
static void
stopExclusion()
-
-
-
Method Detail
-
makeExclusive
public static boolean makeExclusive(java.lang.String programName, int port, java.lang.String[] args, InstanceControllerListener listener)
-
callListener
protected static void callListener(InstanceControllerListener l, boolean initial, java.lang.String[] args)
-
stopExclusion
public static void stopExclusion()
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
-