public final class LockManagerMultiplexerImpl extends DatabaseMultiplexer<LockManager> implements LockManagerMultiplexer
Service requests may originate from more than one external server, so this implementation is threadsafe.
Modifier and Type | Field and Description |
---|---|
private static LockManagerMultiplexer |
instance
Singleton instance of this class
|
Modifier | Constructor and Description |
---|---|
private |
LockManagerMultiplexerImpl()
Default constructor which initializes the resources needed for this
multiplexer to service lock manager requests.
|
Modifier and Type | Method and Description |
---|---|
protected LockManager |
getWorker(Database database)
Get the lock manager which is associated with the given database.
|
static void |
initialize()
Initialize the lock manager multiplexer for this server instance.
|
void |
lock(int database,
int lockType,
RecordIdentifier ident,
boolean update)
Lock or release a single database record in the current context.
|
void |
lock(int database,
int lockType,
RecordIdentifier ident,
boolean update,
long timeout)
Lock or release a single database record in the current context.
|
LockType |
lockTable(int database,
int lockType,
java.lang.String table,
boolean update)
Attempt to obtain the specified lock type on a table.
|
int |
queryLock(int database,
RecordIdentifier ident)
Query the lock type currently held by the current context for the
specified database record.
|
getMultiplexID, lookupWorker
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getMultiplexID
private static LockManagerMultiplexer instance
private LockManagerMultiplexerImpl()
public static void initialize()
This method enforces the singleton pattern.
java.lang.IllegalStateException
- if this method is invoked more than once.public void lock(int database, int lockType, RecordIdentifier ident, boolean update) throws LockUnavailableException
LockType.NONE
is used to release
a record; any other lock type is used to lock a record. Specifying LockType.NONE
for a record not locked in the current context is logically a no-op, though some overhead
is required for the check, and the caller may block waiting on the lock table monitor.
Before obtaining any record lock, lockTable(LockType.SHARE, table, true)
is
invoked to acquire a share lock on the table. After releasing any record lock, lockTable(LockType.NONE, table, true)
is invoked to release that lock.
Any normal return from this method indicates the requested lock was acquired (or released) successfully. Any error will result in an exceptional return. In the event a record cannot be locked due to a conflicting lock held by another context, the current thread will block until the lock is acquired, unless the requested lock is a "no-wait" variant, in which case an exception is thrown.
This method also operates in a check-only mode (if update
is set to false
)
where it goes through the motions of obtaining the specified lock type, but does not
actually change the lock status. This is at best an unreliable check, since another
context can change the lock status as soon as the lock status monitor is released, rendering
the check stale. Nevertheless, it exists to mimic the effect of the lock type option to the
Progress can-find function.
lock
in interface LockManagerMultiplexer
database
- Value that uniquely identifies the target database on the
remote server.lockType
- Type of lock to be obtained. LockType.NONE
is
used to release an existing lock, and to continue with no
lock.ident
- ID which uniquely identifies the record being locked.update
- true
if the lock state for the current record
should be updated; else false
.LockUnavailableException
- if a "no-wait" lock cannot be acquired immediately.public void lock(int database, int lockType, RecordIdentifier ident, boolean update, long timeout) throws LockUnavailableException
LockType.NONE
is used to release
a record; any other lock type is used to lock a record. Specifying LockType.NONE
for a record not locked in the current context is logically a no-op, though some overhead
is required for the check, and the caller may block waiting on the lock table monitor.
Before obtaining any record lock, lockTable(LockType.SHARE, table, true)
is
invoked to acquire a share lock on the table. After releasing any record lock, lockTable(LockType.NONE, table, true)
is invoked to release that lock.
Any normal return from this method indicates the requested lock was acquired (or released) successfully. Any error or timeout will result in an exceptional return. In the event a record cannot be locked due to a conflicting lock held by another context, the current thread will block until the lock is acquired, unless either (a) the requested lock is a "no-wait" variant; or (b) a positive timeout value was provided and at least that number of milliseconds has elapsed without acquiring the lock. In either case, an exception is thrown as described below.
This method also operates in a check-only mode (if update
is set to false
)
where it goes through the motions of obtaining the specified lock type, but does not
actually change the lock status. This is at best an unreliable check, since another
context can change the lock status as soon as the lock status monitor is released, rendering
the check stale. Nevertheless, it exists to mimic the effect of the lock type option to the
Progress can-find function.
lock
in interface LockManagerMultiplexer
database
- Value that uniquely identifies the target database on the
remote server.lockType
- Type of lock to be obtained. LockType.NONE
is
used to release an existing lock, and to continue with no
lock.ident
- ID which uniquely identifies the record being locked.update
- true
if the lock state for the current record
should be updated; else false
.timeout
- Positive number of milliseconds to wait before throwing LockTimeoutException
, or 0L to wait indefinitely. Ignored if a no-wait lock
variant is requested.LockUnavailableException
- if a "no-wait" lock cannot be acquired immediately.public LockType lockTable(int database, int lockType, java.lang.String table, boolean update) throws LockUnavailableException
A lock currently held can be released by specifying
LockType.NONE
for the lockType
parameter.
Method returns previous lock type (so that calling code knows what to set it back to after bulk delete). The normal return of this method indicates that the lock request (or lack thereof) completed successfully, and that the current context now holds a lock of the requested type.
lockTable
in interface LockManagerMultiplexer
database
- Value that uniquely identifies the target database on the remote server.lockType
- Type of lock to be obtained. LockType.NONE
is used to release
an existing lock, and to continue with no lock.table
- Table name.update
- true
if the lock state for the current record should be updated;
else false
.LockUnavailableException
- if a "no-wait" lock cannot be acquired immediately.public int queryLock(int database, RecordIdentifier ident)
This method should always return the non-NO_WAIT
variants of a lock type. That is, even if the actual lock type is
LockType.EXCLUSIVE_NO_WAIT
or
LockType.SHARE_NO_WAIT
, the simpler types of
LockType.EXCLUSIVE
and LockType.SHARE
,
respectively, should be returned. The lack of a lock is required to
return LockType.NONE
rather than null
.
queryLock
in interface LockManagerMultiplexer
database
- Value that uniquely identifies the target database on the
remote server.ident
- ID which uniquely identifies the record being queried.null
.protected LockManager getWorker(Database database)
getWorker
in class DatabaseMultiplexer<LockManager>
database
- Physical database with which the returned worker is associated.