Package org.cyclos.impl.sql
Class BaseDbLockHandlerImpl
- java.lang.Object
-
- org.cyclos.impl.sql.BaseDbLockHandlerImpl
-
- All Implemented Interfaces:
DbLockHandler
- Direct Known Subclasses:
PostgresqlLockHandlerImpl
public abstract class BaseDbLockHandlerImpl extends Object implements DbLockHandler
Base implementation forDbLockHandler
-
-
Field Summary
Fields Modifier and Type Field Description protected JdbcTemplatejdbcTemplateprotected static intKEEPALIVE_SECONDSInterval in seconds which nodes should update the db_lock rowprotected static intVALID_SECONDS(seconds since the last keepalive) - this constant is the interval to sleep until the next check (when there was a valid row in db_lock)
-
Constructor Summary
Constructors Constructor Description BaseDbLockHandlerImpl(JdbcTemplate jdbcTemplate)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidcreate(String hostId)protected abstract DbLockdoRead()protected abstract voidkeepalive()voidlock(String hostId, 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 secondsDbLockread()Return the current row, if anyprotected voidshutdown()voidsleepUntilTryingAgain(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 lockedprotected abstract booleanupdate(String hostId, int version)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.cyclos.impl.sql.DbLockHandler
prepare, unlock
-
-
-
-
Field Detail
-
KEEPALIVE_SECONDS
protected static final int KEEPALIVE_SECONDS
Interval in seconds which nodes should update the db_lock row- See Also:
- Constant Field Values
-
VALID_SECONDS
protected static final int VALID_SECONDS
(seconds since the last keepalive) - this constant is the interval to sleep until the next check (when there was a valid row in db_lock)- See Also:
- Constant Field Values
-
jdbcTemplate
protected JdbcTemplate jdbcTemplate
-
-
Constructor Detail
-
BaseDbLockHandlerImpl
public BaseDbLockHandlerImpl(JdbcTemplate jdbcTemplate)
-
-
Method Detail
-
lock
public final void lock(String hostId, DbLock dbLock)
Description copied from interface:DbLockHandlerLocks 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- Specified by:
lockin interfaceDbLockHandler
-
read
public final DbLock read()
Description copied from interface:DbLockHandlerReturn the current row, if any- Specified by:
readin interfaceDbLockHandler
-
sleepUntilTryingAgain
public final void sleepUntilTryingAgain(DbLock dbLock)
Description copied from interface:DbLockHandlerSleeps for a few seconds before attempting to check again if the db is locked- Specified by:
sleepUntilTryingAgainin interfaceDbLockHandler
-
throwAlreadyLocked
public final void throwAlreadyLocked(DbLock dbLock)
Description copied from interface:DbLockHandlerThrows an appropriate error indicating the current db is already locked- Specified by:
throwAlreadyLockedin interfaceDbLockHandler
-
create
protected abstract void create(String hostId)
-
doRead
protected abstract DbLock doRead()
-
keepalive
protected abstract void keepalive()
-
shutdown
protected void shutdown()
-
update
protected abstract boolean update(String hostId, int version)
-
-