Interface DbLockHandler

  • All Known Implementing Classes:
    BaseDbLockHandlerImpl, PostgresqlLockHandlerImpl

    public interface DbLockHandler
    Manages the database lock, via the db_lock table. The database lock avoids 2 independent Cyclos instances from using the same database at the same time, which could lead to data corruption.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void lock​(String host, DbLock dbLock)
      Locks the database, by either inserting or updating the existing row in db_lock table, and schedules a timer to update the table every few seconds
      void prepare()
      Makes sure the table exists
      DbLock read()
      Return the current row, if any
      void sleepUntilTryingAgain​(DbLock dbLock)
      Sleeps for a few seconds before attempting to check again if the db is locked
      void throwAlreadyLocked​(DbLock dbLock)
      Throws an appropriate error indicating the current db is already locked
      void unlock()
      Delete the row
    • Method Detail

      • lock

        void lock​(String host,
                  @Nullable
                  DbLock dbLock)
        Locks the database, by either inserting or updating the existing row in db_lock table, and schedules a timer to update the table every few seconds
      • prepare

        void prepare()
        Makes sure the table exists
      • read

        @Nullable
        DbLock read()
        Return the current row, if any
      • sleepUntilTryingAgain

        void sleepUntilTryingAgain​(@Nonnull
                                   DbLock dbLock)
        Sleeps for a few seconds before attempting to check again if the db is locked
      • throwAlreadyLocked

        void throwAlreadyLocked​(@Nullable
                                DbLock dbLock)
        Throws an appropriate error indicating the current db is already locked
      • unlock

        void unlock()
        Delete the row