to.etc.dbutil
Class DbLockKeeper

java.lang.Object
  extended by to.etc.dbutil.DbLockKeeper

@ThreadSafe
public final class DbLockKeeper
extends java.lang.Object


Nested Class Summary
static class DbLockKeeper.LockHandle
          Handle for a specific lock.
 
Method Summary
static DbLockKeeper getInstance()
           
static void init(javax.sql.DataSource ds)
          Initializes the DbLockKeeper.
 DbLockKeeper.LockHandle lock(java.lang.String lockName)
          Method should be used to create a lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static DbLockKeeper getInstance()

init

public static void init(javax.sql.DataSource ds)
Initializes the DbLockKeeper. Creates the required tables and sets the datasource. Should be called before the first use of this class.

Parameters:
ds - the datasource used to create the connections.

lock

public DbLockKeeper.LockHandle lock(java.lang.String lockName)
                             throws java.lang.Exception
Method should be used to create a lock. It can be used to make sure that certain processes won't run at the same time on multiple servers. The method won't finish untill lock is given. IMPORTANT The lock must be released after execution of the code.

Parameters:
lockName - the name of the lock
Throws:
java.lang.Exception