class FileLock extends StrictLogging
HDFS does not have a file locking mechanism. We implement it here in the following way - A file is locked when it's modification time is less than 5000ms than the current time - If the modification time is older tahn the current time of more than 5000ms, it is considered unlocked. - The owner of a lock spawn a thread that update the modification every 5s to keep the lock - The process willing to get the lock check every 5s second for the modification time of the file to gain the lock. - When a process gain the lock, it deletes the file first and tries to create a new one, this make sure that of two process gaining the lock, only one will be able to recreate it after deletion.
To gain the lock, call tryLock, to release it, call release().
If you are going to use the lock and release it within the same call stack frame, please consider
calling tryExclusively() (as in exclusive(delay) { action }) instead.
- Alphabetic
- By Inheritance
- FileLock
- StrictLogging
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
FileLock(path: Path, storageHandler: StorageHandler)
- path
Lock File path
- storageHandler
Filesystem Handler
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
- def checkinPeriod: Long
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
doExclusively[T](timeoutInMillis: Long = -1L)(op: ⇒ T): T
Try to perform an operation while holding a lock exclusively
Try to perform an operation while holding a lock exclusively
- timeoutInMillis
number of milliseconds during which the calling process will try to get the lock before it times out. -1 means no timeout
- returns
the result of the operation (if successful) when locked is acquired throws TimeoutException if the lock could not be acquired within timeoutInMillis, or any exception thrown by op if the lock was acquired but the operation failed the lock is guaranteed freed upon normal or exceptional exit from this function.
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
val
logger: Logger
- Attributes
- protected
- Definition Classes
- StrictLogging
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def refreshPeriod: Long
-
def
release(): Unit
Release the lock and delete the lock file.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
tryExclusively[T](timeoutInMillis: Long = -1L)(op: ⇒ T): Try[T]
Try to perform an operation while holding a lock exclusively
Try to perform an operation while holding a lock exclusively
- timeoutInMillis
number of milliseconds during which the calling process will try to get the lock before it time out. -1 means no timeout
- returns
the result of the operation (if successful) when locked is acquired, Failure otherwise the lock is guaranteed freed upon normal or exceptional exit from this function.
-
def
tryLock(timeoutInMillis: Long = -1): Boolean
Try to gain the lock during timeoutInMillis millis
Try to gain the lock during timeoutInMillis millis
- timeoutInMillis
number of milliseconds during which the calling process will try to get the lock before it time out. -1 means no timeout
- returns
true when locked is acquired (caller is responsible for calling
release(), false otherwise
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()