Package net.sourceforge.jnlp.services
Class SingleInstanceLock
- java.lang.Object
-
- net.sourceforge.jnlp.services.SingleInstanceLock
-
class SingleInstanceLock extends java.lang.ObjectThis class represents a Lock for single instance jnlp applications.The lock is per-session, per user.
-
-
Field Summary
Fields Modifier and Type Field Description static intINVALID_PORTprivate java.io.FilelockFileprivate static LoggerLOGprivate intport
-
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 voidcreateWithPort(int localPort)Create/overwrite the instance lock for the jnlp file.(package private) booleanexists()Returns true if the lock file already exists.private java.lang.StringgetCurrentDisplay()Returns a string identifying this display.private java.io.FilegetLockFile(JNLPFile jnlpFile)Return a file object that represents the lock file.private java.lang.StringgetLockFileName(JNLPFile jnlpFile)Returns the name of the lock file.intgetPort()Returns the port in this lock file.private booleanisPortFree(int port)Returns true if the port is free.booleanisValid()Returns true if the lock if valid.private voidparseFile()Parse the lock file.
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
INVALID_PORT
public static final int INVALID_PORT
- See Also:
- Constant Field Values
-
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.IOExceptionCreate/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.IOExceptionParse the lock file.- Throws:
java.lang.NumberFormatExceptionjava.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.
-
-