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.RunnablePrevents multiple instances of a program from running. On startup, the class'smakeExclusivemethod 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 returntrueif the calling instance should keep running after the method returns, orfalseif it should stop. Afalsereturn value indicates that the program arguments were successfully sent to an instance that is already running. A value oftrueindicates 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 voidcallListener(InstanceControllerListener l, boolean initial, java.lang.String[] args)static booleanmakeExclusive(java.lang.String programName, int port, java.lang.String[] args, InstanceControllerListener listener)voidrun()static voidstopExclusion()
-
-
-
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:
runin interfacejava.lang.Runnable
-
-