Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.util.launchutils
Class SipCommunicatorLock

java.lang.Object
  extended by java.lang.Thread
      extended by net.java.sip.communicator.util.launchutils.SipCommunicatorLock
All Implemented Interfaces:
Runnable

public class SipCommunicatorLock
extends Thread

This class is used to prevent from running multiple instances of Jitsi. The class binds a socket somewhere on the localhost domain and records its socket address in the Jitsi configuration directory. All following instances of Jitsi (and hence this class) will look for this record in the configuration directory and try to connect to the original instance through the socket address in there.

Author:
Emil Ivov

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
static int ALREADY_STARTED
          Returned by the soft start method to indicate that an instance of Jitsi has been already started and we should exit.
static int LOCK_ERROR
          Indicates that something went wrong.
static int SUCCESS
          Returned by the soft start method to indicate that we have successfully started and locked the configuration directory.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SipCommunicatorLock()
           
 
Method Summary
 int tryLock(String[] args)
          Tries to lock the configuration directory.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOCK_ERROR

public static final int LOCK_ERROR
Indicates that something went wrong. More information will probably be available in the console ... if anyone cares at all.

See Also:
Constant Field Values

SUCCESS

public static final int SUCCESS
Returned by the soft start method to indicate that we have successfully started and locked the configuration directory.

See Also:
Constant Field Values

ALREADY_STARTED

public static final int ALREADY_STARTED
Returned by the soft start method to indicate that an instance of Jitsi has been already started and we should exit. This return code also indicates that all arguments were passed to that new instance.

See Also:
Constant Field Values
Constructor Detail

SipCommunicatorLock

public SipCommunicatorLock()
Method Detail

tryLock

public int tryLock(String[] args)
Tries to lock the configuration directory. If lock-ing is not possible because a previous instance is already running, then it transmits the list of args to that running instance.

There are three possible outcomes of this method. 1. We lock successfully; 2. We fail to lock because another instance of Jitsi is already running; 3. We fail to lock for some unknown error. Each of these cases is represented by an error code returned as a result.

Parameters:
args - the array of arguments that we are to submit in case an instance of Jitsi has already been started.
Returns:
an error or success code indicating the outcome of the lock operation.

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.