Class/Object

com.ebiznext.comet.utils

FileLock

Related Docs: object FileLock | package utils

Permalink

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 tahn 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.

Linear Supertypes
StrictLogging, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. FileLock
  2. StrictLogging
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new FileLock(path: Path, storageHandler: StorageHandler)

    Permalink

    path

    Lock File path

    storageHandler

    Filesystem Handler

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def checkinPeriod: Long

    Permalink
  6. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  7. def doExclusively[T](timeoutInMillis: Long = 1L)(op: ⇒ T): T

    Permalink

    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

    Exceptions thrown

    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.

  8. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  14. val logger: Logger

    Permalink
    Attributes
    protected
    Definition Classes
    StrictLogging
  15. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  16. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  18. def refreshPeriod: Long

    Permalink
  19. def release(): Unit

    Permalink

    Release the lock and delete the lock file.

  20. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  21. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  22. def tryExclusively[T](timeoutInMillis: Long = 1L)(op: ⇒ T): Try[T]

    Permalink

    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.

  23. def tryLock(timeoutInMillis: Long = 1): Boolean

    Permalink

    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

  24. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from StrictLogging

Inherited from AnyRef

Inherited from Any

Ungrouped