@Singleton @Named(value="file-lock") public class FileLockNamedLockFactory extends NamedLockFactorySupport
FileLockNamedLock
s. This is a bit special implementation, as it
expects locks names to be fully qualified absolute file system paths.Modifier and Type | Field and Description |
---|---|
private static int |
ATTEMPTS
Tweak: on Windows, the presence of
StandardOpenOption.DELETE_ON_CLOSE causes concurrency issues. |
private static boolean |
DELETE_LOCK_FILES
Tweak: on Windows, the presence of
StandardOpenOption.DELETE_ON_CLOSE causes concurrency issues. |
private java.util.concurrent.ConcurrentMap<java.lang.String,java.nio.channels.FileChannel> |
fileChannels |
static java.lang.String |
NAME |
private static long |
SLEEP_MILLIS
Tweak: When
ATTEMPTS used, the amount of milliseconds to sleep between subsequent retries. |
logger
Constructor and Description |
---|
FileLockNamedLockFactory() |
Modifier and Type | Method and Description |
---|---|
protected NamedLockSupport |
createLock(java.lang.String name)
Implementations shall create and return
NamedLockSupport for given name , this method must never
return null . |
protected void |
destroyLock(java.lang.String name)
Implementation may override this (empty) method to perform some sort of implementation specific cleanup for
given lock name.
|
closeLock, getLock, shutdown
public static final java.lang.String NAME
private static final boolean DELETE_LOCK_FILES
StandardOpenOption.DELETE_ON_CLOSE
causes concurrency issues. This
flag allows to have it removed from effective flags, at the cost that lockfile directory becomes crowded
with 0 byte sized lock files that are never cleaned up. Default value is true
.private static final int ATTEMPTS
StandardOpenOption.DELETE_ON_CLOSE
causes concurrency issues. This
flag allows to implement similar fix as referenced JDK bug report: retry and hope the best. Default value is
5 attempts (will retry 4 times).private static final long SLEEP_MILLIS
ATTEMPTS
used, the amount of milliseconds to sleep between subsequent retries. Default
value is 50 milliseconds.private final java.util.concurrent.ConcurrentMap<java.lang.String,java.nio.channels.FileChannel> fileChannels
protected NamedLockSupport createLock(java.lang.String name)
NamedLockFactorySupport
NamedLockSupport
for given name
, this method must never
return null
.createLock
in class NamedLockFactorySupport
protected void destroyLock(java.lang.String name)
NamedLockFactorySupport
destroyLock
in class NamedLockFactorySupport