public class OnDemandFileAccess extends AbstractFileAccess
| Constructor and Description |
|---|
OnDemandFileAccess(File targetFile,
String displayName,
FileLockManager manager) |
| Modifier and Type | Method and Description |
|---|---|
<T> T |
readFromFile(Factory<? extends T> action)
Runs the given action under a shared or exclusive lock on the target file.
|
void |
writeToFile(Runnable action)
Runs the given action under an exclusive lock on the target file.
|
readFromFilepublic OnDemandFileAccess(File targetFile, String displayName, FileLockManager manager)
public <T> T readFromFile(Factory<? extends T> action) throws LockTimeoutException
FileAccessIf an exclusive or shared lock is already held, the lock level is not changed and the action is executed. If no lock is already held, a shared lock is acquired, the action executed, and the lock released. This method blocks until the lock can be acquired.
LockTimeoutException - On timeout acquiring lock, if required.public void writeToFile(Runnable action) throws LockTimeoutException
FileAccessIf an exclusive lock is already held, the lock level is not changed and the action is executed. If a shared lock is already held, the lock is escalated to an exclusive lock, and reverted back to a shared lock when the action completes. If no lock is already held, an exclusive lock is acquired, the action executed, and the lock released.
LockTimeoutException - On timeout acquiring lock, if required.Copyright © 2013. All rights reserved