Package org.eclipse.aether.named.support
Class FileLockNamedLock
java.lang.Object
org.eclipse.aether.named.support.NamedLockSupport
org.eclipse.aether.named.support.FileLockNamedLock
- All Implemented Interfaces:
AutoCloseable,NamedLock
Named lock that uses
FileLock. An instance of this class is about ONE LOCK (one file)
and is possibly used by multiple threads. Each thread (if properly coded re boxing) will try to
obtain either shared or exclusive lock. As file locks are JVM-scoped (so one JVM can obtain
same file lock only once), the threads share file lock and synchronize according to it. Still,
as file lock obtain operation does not block (or in other words, the method that does block
cannot be controlled for how long it blocks), we are "simulating" thread blocking using
Retry utility.
This implementation performs coordination not only on thread (JVM-local) level, but also on
process level, as long as other parties are using this same "advisory" locking mechanism.- Since:
- 1.7.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ReentrantLockLock protecting "critical region": this is where threads are allowed to perform locking but should leave this region as quick as possible.private final FileChannelTheFileChannelthis instance is about.private final AtomicReference<FileLock> The reference ofFileLock, if obtained.private static final longprivate static final longprivate static final longThread -> steps stack (true = shared, false = exclusive)Fields inherited from class org.eclipse.aether.named.support.NamedLockSupport
logger -
Constructor Summary
ConstructorsConstructorDescriptionFileLockNamedLock(String name, FileChannel fileChannel, NamedLockFactorySupport factory) -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanReturnstrueif any other than this thread using this instance has any step recorded.private Booleanprotected booleandoLockExclusively(long time, TimeUnit unit) private Booleanprotected booleandoLockShared(long time, TimeUnit unit) protected voiddoUnlock()private FileLockobtainFileLock(boolean shared) Attempts to obtain realFileLock, returns non-null value is succeeds, ornullif cannot.Methods inherited from class org.eclipse.aether.named.support.NamedLockSupport
close, diagnosticState, doClose, lockExclusively, lockShared, name, toString, unlock
-
Field Details
-
RETRY_SLEEP_MILLIS
private static final long RETRY_SLEEP_MILLIS- See Also:
-
LOCK_POSITION
private static final long LOCK_POSITION- See Also:
-
LOCK_SIZE
private static final long LOCK_SIZE- See Also:
-
threadSteps
Thread -> steps stack (true = shared, false = exclusive) -
fileChannel
TheFileChannelthis instance is about. -
fileLockRef
The reference ofFileLock, if obtained. -
criticalRegion
Lock protecting "critical region": this is where threads are allowed to perform locking but should leave this region as quick as possible.
-
-
Constructor Details
-
FileLockNamedLock
-
-
Method Details
-
doLockExclusively
- Specified by:
doLockExclusivelyin classNamedLockSupport- Throws:
InterruptedException
-
doLockExclusively
-
doUnlock
protected void doUnlock()- Specified by:
doUnlockin classNamedLockSupport
-
anyOtherThreadHasSteps
private boolean anyOtherThreadHasSteps()Returnstrueif any other than this thread using this instance has any step recorded. -
obtainFileLock
Attempts to obtain realFileLock, returns non-null value is succeeds, ornullif cannot.