Class 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's makeExclusive 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 return true if the calling instance should keep running after the method returns, or false if it should stop. A false return value indicates that the program arguments were successfully sent to an instance that is already running. A value of true 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 Detail

      • makeExclusive

        public static boolean makeExclusive​(java.lang.String programName,
                                            int port,
                                            java.lang.String[] args,
                                            InstanceControllerListener listener)
      • stopExclusion

        public static void stopExclusion()
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable