R
- the generic type.public final class FileLocker<R>
extends Object
Constructor and Description |
---|
FileLocker()
Instantiates a new file locker.
|
Modifier and Type | Method and Description |
---|---|
boolean |
acquireLock(FileInputStream in)
Locks the given file input stream.
|
boolean |
acquireLock(FileInputStream in,
int retry,
int sleepTime)
Locks the given file input stream.
|
boolean |
acquireLock(FileOutputStream out)
Locks the given file output stream.
|
boolean |
acquireLock(FileOutputStream out,
int retry,
int sleepTime)
Locks the given file output stream.
|
boolean |
createLock(String fileName,
boolean exclusive)
Creates a locks file with the given name.
|
boolean |
createLock(String fileName,
int retry,
int sleepTime,
boolean exclusive)
Creates a locks file with the given name.
|
R |
execute(Callable<R> callable,
String fileName,
boolean exclusive)
Executes the
Callable.call() method. |
R |
execute(Callable<R> callable,
String fileName,
int retry,
int sleepTime,
boolean exclusive)
Executes the
Callable.call() method. |
static String |
getDefaultLockFileName(String fileName)
Gets the default lock file name using given file name.
|
boolean |
releaseLock()
Releases current lock.
|
public static String getDefaultLockFileName(String fileName)
fileName
- the file namepublic boolean acquireLock(FileInputStream in)
DEFAULT_RETRY
for the number of retries andin
- the the file input streamDEFAULT_SLEEP_TIME
for the sleep time between retries.public boolean acquireLock(FileInputStream in, int retry, int sleepTime)
in
- the the file input streamretry
- the number of retriessleepTime
- the sleep time between retriespublic boolean acquireLock(FileOutputStream out)
DEFAULT_RETRY
for the number of retries andout
- the the file output streamDEFAULT_SLEEP_TIME
for the sleep time between retries.public boolean acquireLock(FileOutputStream out, int retry, int sleepTime)
out
- the the file output streamretry
- the number of retriessleepTime
- the sleep time between retriespublic boolean createLock(String fileName, boolean exclusive)
DEFAULT_RETRY
for the number of retries andfileName
- the file nameexclusive
- if true
try to acquire exclusive lockDEFAULT_SLEEP_TIME
for the sleep time between retries.public boolean createLock(String fileName, int retry, int sleepTime, boolean exclusive)
fileName
- the file nameretry
- the number of retriessleepTime
- the sleep time between retriesexclusive
- if true
try to acquire exclusive lockpublic R execute(Callable<R> callable, String fileName, boolean exclusive) throws Exception
Callable.call()
method. If fileName != null
crates a lock file
with the given name before and deletes it after. Uses DEFAULT_RETRY
for the number of retries and DEFAULT_SLEEP_TIME
for the sleep time between retries.callable
- the instance of the Callable interfacefileName
- the lock file nameexclusive
- if true
try to acquire exclusive lockException
- the exception in case of any errorpublic R execute(Callable<R> callable, String fileName, int retry, int sleepTime, boolean exclusive) throws Exception
Callable.call()
method. If fileName != null
crates a lock file
with the given name before and deletes it after.callable
- the instance of the Callable interfacefileName
- the lock file nameretry
- the number of retriessleepTime
- the sleep time between retriesexclusive
- if true
try to acquire exclusive lockException
- the exception in case of any errorpublic boolean releaseLock()
Copyright © 2010-2020 Toolsverse. All Rights Reserved.