Class SystemLevelLocker
java.lang.Object
org.terracotta.utilities.test.net.SystemLevelLocker
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final Pathprivate static final org.slf4j.Loggerprivate FileChannelprivate intprivate static final Path -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidClosesopenChannelif there are no outstanding locks.(package private) booleanlock(PortManager.PortRef portRef) Obtains a system-level lock against the lock file for the identified port.private voidRelease the system-level lock for the specifiedPortRefinstance.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
RELATIVE_LOCK_FILE_PATH
-
lockFilePath
-
openChannel
-
outstandingLocks
private int outstandingLocks
-
-
Constructor Details
-
SystemLevelLocker
SystemLevelLocker()Creates a new instance ofSystemLevelLocker. This constructor creates or gains access to the common file used for port locking.The common locking file is not deleted when a
SystemLevelLockerinstance 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
Obtains a system-level lock against the lock file for the identified port.- Parameters:
portRef- thePortRefidentifying the port.- Returns:
trueif the system-level lock was obtained;falseotherwise- Throws:
IllegalStateException- if the lock cannot be obtained because of anIOException
-
release
Release the system-level lock for the specifiedPortRefinstance.- Parameters:
port- thePortRefinstance to unlocklock- the existingFileLockinstance
-
closeChannelIfUnused
private void closeChannelIfUnused()ClosesopenChannelif there are no outstanding locks.
-