com.jogamp.common.util.locks

## Class SingletonInstance

- java.lang.Object
- - com.jogamp.common.util.locks.SingletonInstance

- All Implemented Interfaces:
    Lock

      public abstract class SingletonInstance
      extends Object
      implements Lock

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static boolean` | `DEBUG`

    - ### Fields inherited from interface com.jogamp.common.util.locks.Lock

      `DEFAULT_TIMEOUT, TIMEOUT, TRACE_LOCK`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `SingletonInstance(long poll_ms)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static SingletonInstance` | `createFileLock(long poll_ms, File lockFile)`
    `static SingletonInstance` | `createFileLock(long poll_ms, String lockFileBasename)`
    `static SingletonInstance` | `createServerSocket(long poll_ms, int portNumber)` A user shall use ephemeral ports: IANA suggests 49152 to 65535 as "dynamic and/or private ports". Many GNU/Linux kernels use 32768 to 61000. FreeBSD >= 4.6 uses the IANA port range. FreeBSD < 4.6 and BSD use ports 1024 through 4999. Microsoft Windows operating systems through Server 2003 use the range 1025 to 5000 Windows Vista, Windows 7, and Server 2008 use the IANA range.
    `abstract String` | `getName()`
    `long` | `getPollPeriod()`
    `protected String` | `infoPrefix()`
    `protected String` | `infoPrefix(long currentMillis)`
    `boolean` | `isLocked()` Query if locked
    `void` | `lock()` Blocking until the lock is acquired by this Thread or `Lock.TIMEOUT` is reached.
    `String` | `toString()`
    `boolean` | `tryLock(long maxwait)` Blocking until the lock is acquired by this Thread or `maxwait` in ms is reached.
    `protected abstract boolean` | `tryLockImpl()`
    `void` | `unlock()` Release the lock.
    `protected abstract boolean` | `unlockImpl()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### DEBUG

          protected static final boolean DEBUG

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SingletonInstance

          protected SingletonInstance(long poll_ms)

  - ### Method Detail

    - #### createFileLock

          public static SingletonInstance createFileLock(long poll_ms,
                                         String lockFileBasename)

    - #### createFileLock

          public static SingletonInstance createFileLock(long poll_ms,
                                         File lockFile)

    - #### createServerSocket

          public static SingletonInstance createServerSocket(long poll_ms,
                                             int portNumber)

      A user shall use ephemeral ports:
      - IANA suggests 49152 to 65535 as "dynamic and/or private ports".
      - Many GNU/Linux kernels use 32768 to 61000.
      - FreeBSD >= 4.6 uses the IANA port range.
      - FreeBSD < 4.6 and BSD use ports 1024 through 4999.
      - Microsoft Windows operating systems through Server 2003 use the range 1025 to 5000
      - Windows Vista, Windows 7, and Server 2008 use the IANA range.
      Parameters:
        `pollPeriod` -
        `portNumber` - to be used for this single instance server socket.

    - #### getPollPeriod

          public final long getPollPeriod()

    - #### getName

          public abstract String getName()

    - #### toString

          public final String toString()

      Overrides:
        `toString` in class `Object`

    - #### lock

          public void lock()
                    throws RuntimeException

      Description copied from interface: `Lock`
      Blocking until the lock is acquired by this Thread or `Lock.TIMEOUT` is reached.
      Specified by:
        `lock` in interface `Lock`
      Throws:
        `RuntimeException` - in case of `Lock.TIMEOUT`

    - #### tryLock

          public boolean tryLock(long maxwait)
                          throws RuntimeException

      Description copied from interface: `Lock`
      Blocking until the lock is acquired by this Thread or `maxwait` in ms is reached.
      Specified by:
        `tryLock` in interface `Lock`
      Parameters:
        `maxwait` - Maximum time in ms to wait to acquire the lock. If this value is zero, the call returns immediately either without being able to acquire the lock, or with acquiring the lock directly while ignoring any scheduling order.
      Returns:
        true if the lock has been acquired within `maxwait`, otherwise false
      Throws:
        `RuntimeException`

    - #### tryLockImpl

          protected abstract boolean tryLockImpl()

    - #### unlock

          public void unlock()
                      throws RuntimeException

      Description copied from interface: `Lock`
      Release the lock.
      Specified by:
        `unlock` in interface `Lock`
      Throws:
        `RuntimeException` - in case the lock is not acquired by this thread.

    - #### unlockImpl

          protected abstract boolean unlockImpl()

    - #### isLocked

          public boolean isLocked()

      Description copied from interface: `Lock`
      Query if locked
      Specified by:
        `isLocked` in interface `Lock`

    - #### infoPrefix

          protected String infoPrefix(long currentMillis)

    - #### infoPrefix

          protected String infoPrefix()