Class SingleInstanceLock


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

    The lock is per-session, per user.

    • Constructor Summary

      Constructors 
      Constructor Description
      SingleInstanceLock​(JNLPFile jnlpFile)
      Create an object to manage the instance lock for the specified JNLP file.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void createWithPort​(int localPort)
      Create/overwrite the instance lock for the jnlp file.
      (package private) boolean exists()
      Returns true if the lock file already exists.
      private java.lang.String getCurrentDisplay()
      Returns a string identifying this display.
      private java.io.File getLockFile​(JNLPFile jnlpFile)
      Return a file object that represents the lock file.
      private java.lang.String getLockFileName​(JNLPFile jnlpFile)
      Returns the name of the lock file.
      int getPort()
      Returns the port in this lock file.
      private boolean isPortFree​(int port)
      Returns true if the port is free.
      boolean isValid()
      Returns true if the lock if valid.
      private void parseFile()
      Parse the lock file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        private static final Logger LOG
      • lockFile

        private final java.io.File lockFile
      • port

        private int port
    • Constructor Detail

      • 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 Detail

      • createWithPort

        public void createWithPort​(int localPort)
                            throws java.io.IOException
        Create/overwrite the instance lock for the jnlp file.
        Parameters:
        localPort - the network port for the lock
        Throws:
        java.io.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 java.io.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 java.lang.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 java.lang.NumberFormatException,
                               java.io.IOException
        Parse the lock file.
        Throws:
        java.lang.NumberFormatException
        java.io.IOException
      • getCurrentDisplay

        private java.lang.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.