Package org.h2.store
Class FileLock
- java.lang.Object
-
- org.h2.store.FileLock
-
- All Implemented Interfaces:
java.lang.Runnable
public class FileLock extends java.lang.Object implements java.lang.RunnableThe file lock is used to lock a database so that only one process can write to it. It uses a cooperative locking protocol. Usually a .lock.db file is used, but locking by creating a socket is supported as well.
-
-
Constructor Summary
Constructors Constructor Description FileLock(TraceSystem traceSystem, java.lang.String fileName, int sleep)Create a new file locking object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FileLockMethodgetFileLockMethod(java.lang.String method)Get the file locking method type given a method name.java.lang.StringgetUniqueId()java.util.Propertiesload()Load the properties file.voidlock(FileLockMethod fileLockMethod)Lock the file if possible.voidrun()java.util.Propertiessave()Save the lock file.voidsetProperty(java.lang.String key, java.lang.String value)Add or change a setting to the properties.voidunlock()Unlock the file.
-
-
-
Constructor Detail
-
FileLock
public FileLock(TraceSystem traceSystem, java.lang.String fileName, int sleep)
Create a new file locking object.- Parameters:
traceSystem- the trace system to usefileName- the file namesleep- the number of milliseconds to sleep
-
-
Method Detail
-
lock
public void lock(FileLockMethod fileLockMethod)
Lock the file if possible. A file may only be locked once.- Parameters:
fileLockMethod- the file locking method to use- Throws:
DbException- if locking was not successful
-
unlock
public void unlock()
Unlock the file. The watchdog thread is stopped. This method does nothing if the file is already unlocked.
-
setProperty
public void setProperty(java.lang.String key, java.lang.String value)Add or change a setting to the properties. This call does not save the file.- Parameters:
key- the keyvalue- the value
-
save
public java.util.Properties save()
Save the lock file.- Returns:
- the saved properties
-
load
public java.util.Properties load()
Load the properties file.- Returns:
- the properties
-
getFileLockMethod
public static FileLockMethod getFileLockMethod(java.lang.String method)
Get the file locking method type given a method name.- Parameters:
method- the method name- Returns:
- the method type
- Throws:
DbException- if the method name is unknown
-
getUniqueId
public java.lang.String getUniqueId()
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
-