org.basex.core
Class DBLocking

java.lang.Object
  extended by org.basex.core.DBLocking
All Implemented Interfaces:
Locking

public final class DBLocking
extends java.lang.Object
implements Locking

Manage read and write locks on arbitrary strings. Maximum of MainProp.PARALLEL concurrent transactions are allowed, further will be queued. This class prevents locking deadlocks by sorting all all strings Locks can only be released and downgraded by the same thread which acquired it. Locking methods are not synchronized to each other. The user must make sure not to call them in parallel by the same thread (it is fine to call arbitrary locking methods by different threads at the same time). This locking can be deactivated by setting MainProp.GLOBALLOCK to true.

Author:
BaseX Team 2005-12, BSD License, Jens Erat

Field Summary
static java.lang.String ADMIN
          Special lock identifier for administrative commands.
static java.lang.String BACKUP
          Special lock identifier for backup commands.
static java.lang.String COLL
          Special lock identifier for current document, will be substituted.
static java.lang.String CTX
          Special lock identifier for current context, will be substituted.
static java.lang.String EVENT
          Special lock identifier for event commands.
static java.lang.String REPO
          Special lock identifier for repository commands.
static java.lang.String USER_PREFIX
          Prefix for user defined locks.
 
Constructor Summary
DBLocking(MainProp mp)
          Initialize new Locking instance.
 
Method Summary
 void acquire(Proc pr, StringList read, StringList write)
          Puts read and write locks the specified databases.
 void downgrade(StringList write)
          Only keeps given write locks, downgrades the others to read locks.
 void release(Proc pr)
          Unlock all string locked by a transaction.
 java.lang.String toString()
          Present current locking status.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COLL

public static final java.lang.String COLL
Special lock identifier for current document, will be substituted.

See Also:
Constant Field Values

CTX

public static final java.lang.String CTX
Special lock identifier for current context, will be substituted.

See Also:
Constant Field Values

ADMIN

public static final java.lang.String ADMIN
Special lock identifier for administrative commands.

See Also:
Constant Field Values

BACKUP

public static final java.lang.String BACKUP
Special lock identifier for backup commands.

See Also:
Constant Field Values

EVENT

public static final java.lang.String EVENT
Special lock identifier for event commands.

See Also:
Constant Field Values

REPO

public static final java.lang.String REPO
Special lock identifier for repository commands.

See Also:
Constant Field Values

USER_PREFIX

public static final java.lang.String USER_PREFIX
Prefix for user defined locks.

See Also:
Constant Field Values
Constructor Detail

DBLocking

public DBLocking(MainProp mp)
Initialize new Locking instance.

Parameters:
mp - Main properties, used to read parallel transactions limit.
Method Detail

acquire

public void acquire(Proc pr,
                    StringList read,
                    StringList write)
Description copied from interface: Locking
Puts read and write locks the specified databases. Store and return the token for unlocking these objects again.

Specified by:
acquire in interface Locking
Parameters:
pr - process
read - names of databases to put read locks on. Global locking is performed if the passed on reference is null
write - names of databases to put write locks on. Global locking is performed if the passed on reference is null

downgrade

public void downgrade(StringList write)
Only keeps given write locks, downgrades the others to read locks.

Specified by:
downgrade in interface Locking
Parameters:
write - write locks to keep

release

public void release(Proc pr)
Description copied from interface: Locking
Unlock all string locked by a transaction.

Specified by:
release in interface Locking
Parameters:
pr - process

toString

public java.lang.String toString()
Present current locking status. Not to be seen as a programming API but only for debugging purposes.

Overrides:
toString in class java.lang.Object