Class SingleInstanceLock

java.lang.Object
net.sourceforge.jnlp.services.SingleInstanceLock

class SingleInstanceLock extends Object
This class represents a Lock for single instance jnlp applications.

The lock is per-session, per user.

  • Field Details

    • LOG

      private static final Logger LOG
    • INVALID_PORT

      public static final int INVALID_PORT
      See Also:
    • lockFile

      private final File lockFile
    • port

      private int port
  • Constructor Details

    • SingleInstanceLock

      public SingleInstanceLock(JNLPFile jnlpFile)
      Create an object to manage the instance lock for the specified JNLP file.
      Parameters:
      jnlpFile - the jnlp file to create the lock for
  • Method Details

    • createWithPort

      public void createWithPort(int localPort) throws IOException
      Create/overwrite the instance lock for the jnlp file.
      Parameters:
      localPort - the network port for the lock
      Throws:
      IOException - on any io problems
    • isValid

      public boolean isValid()
      Returns true if the lock if valid. That is, the lock exists, and port it points to is listening for incoming messages.
    • getPort

      public int getPort()
      Returns the port in this lock file.
    • exists

      boolean exists()
      Returns true if the lock file already exists.
    • isPortFree

      private boolean isPortFree(int port)
      Returns true if the port is free.
    • getLockFile

      private File getLockFile(JNLPFile jnlpFile)
      Return a file object that represents the lock file. The lock file itself may or may not exist.
      Parameters:
      jnlpFile - the applicaton for which to create the lock
    • getLockFileName

      private String getLockFileName(JNLPFile jnlpFile)
      Returns the name of the lock file.
      Parameters:
      jnlpFile - the applicaton for which to create the lock
    • parseFile

      private void parseFile() throws NumberFormatException, IOException
      Parse the lock file.
      Throws:
      NumberFormatException
      IOException
    • getCurrentDisplay

      private String getCurrentDisplay()
      Returns a string identifying this display.

      Implementation note: On systems with X support, this is the DISPLAY variable

      Returns:
      a string that is guaranteed to be not null.