Class SystemLevelLocker


  • class SystemLevelLocker
    extends java.lang.Object
    Supplies a system-level locking mechanism supporting port management. An instance of this class may be used to coordinate port reservations among multiple JVM instances in a single system.
    • Constructor Summary

      Constructors 
      Constructor Description
      SystemLevelLocker()
      Creates a new instance of SystemLevelLocker.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void closeChannelIfUnused()
      Closes openChannel if there are no outstanding locks.
      (package private) boolean lock​(PortManager.PortRef portRef)
      Obtains a system-level lock against the lock file for the identified port.
      private void release​(int port, java.nio.channels.FileLock lock)
      Release the system-level lock for the specified PortRef instance.
      • Methods inherited from class java.lang.Object

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

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • RELATIVE_LOCK_FILE_PATH

        private static final java.nio.file.Path RELATIVE_LOCK_FILE_PATH
      • lockFilePath

        private final java.nio.file.Path lockFilePath
      • openChannel

        private java.nio.channels.FileChannel openChannel
      • outstandingLocks

        private int outstandingLocks
    • Constructor Detail

      • SystemLevelLocker

        SystemLevelLocker()
        Creates a new instance of SystemLevelLocker. This constructor creates or gains access to the common file used for port locking.

        The common locking file is not deleted when a SystemLevelLocker instance is discarded. The common locking file persists across uses and is re-used if available.

        Throws:
        java.lang.IllegalStateException - if the common locking file cannot be created or is otherwise not accessible
    • Method Detail

      • lock

        boolean lock​(PortManager.PortRef portRef)
        Obtains a system-level lock against the lock file for the identified port.
        Parameters:
        portRef - the PortRef identifying the port.
        Returns:
        true if the system-level lock was obtained; false otherwise
        Throws:
        java.lang.IllegalStateException - if the lock cannot be obtained because of an IOException
      • release

        private void release​(int port,
                             java.nio.channels.FileLock lock)
        Release the system-level lock for the specified PortRef instance.
        Parameters:
        port - the PortRef instance to unlock
        lock - the existing FileLock instance
      • closeChannelIfUnused

        private void closeChannelIfUnused()
        Closes openChannel if there are no outstanding locks.