Package org.cyclos.impl.sql
Interface DbLockHandler
-
public interface DbLockHandlerManages 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.
-
-
Field Summary
Fields Modifier and Type Field Description static intKEEPALIVE_SECONDSInterval in seconds which nodes should update the db_lock row
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidkeepalive(String hostId)Send a keep-alive to the databasevoidlock(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 secondsvoidprepare()Makes sure the table existsDbLockread()Return the current row, if anyvoidsleepUntilTryingAgain(DbLock dbLock)Sleeps for a few seconds before attempting to check again if the db is lockedvoidthrowAlreadyLocked(DbLock dbLock)Throws an appropriate error indicating the current db is already lockedvoidunlock()Delete the row
-
-
-
Field Detail
-
KEEPALIVE_SECONDS
static final int KEEPALIVE_SECONDS
Interval in seconds which nodes should update the db_lock row- See Also:
- Constant Field Values
-
-
Method Detail
-
keepalive
void keepalive(String hostId)
Send a keep-alive to the database
-
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
-
-