Class SystemLevelLocker

java.lang.Object
org.terracotta.utilities.test.net.SystemLevelLocker

class SystemLevelLocker extends 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.
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • RELATIVE_LOCK_FILE_PATH

      private static final Path RELATIVE_LOCK_FILE_PATH
    • lockFilePath

      private final Path lockFilePath
    • openChannel

      private FileChannel openChannel
    • outstandingLocks

      private int outstandingLocks
  • Constructor Details

    • 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:
      IllegalStateException - if the common locking file cannot be created or is otherwise not accessible
  • Method Details

    • 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:
      IllegalStateException - if the lock cannot be obtained because of an IOException
    • release

      private void release(int port, 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.