public final class RemoteLockManager extends java.lang.Object implements LockManager
LockManager
which delegates
requests for database record locking services to the remote P2J server
which is authoritative for the target database. This is necessary in cases
where business logic dynamically connects to a remote database which is not
managed by the current P2J server instance, since record lock actions must
be serialized through a lock manager which is authoritative for the target
database.
An instance of this class works with a local proxy for a remote instance of
LockManagerMultiplexer
residing at the target server. The remote
object may manage multiple databases, each of which is assigned a unique
database identifier. When the database is set
into a RemoteLockManager
instance, the associated
identifier is requested from the remote multiplexer. The ID returned by
the multiplexer is used on all subsequent service requests sent by the
RemoteLockManager
instance.
RemotePersistence
Modifier and Type | Field and Description |
---|---|
private int |
mpID
Multiplex ID for the remote database associated with this object
|
private LockManagerMultiplexer |
multiplexer
Lock manager multiplexer which will service remote requests
|
Constructor and Description |
---|
RemoteLockManager(LockManagerMultiplexer multiplexer)
Constructor which stores a proxy to the remote object which will
service lock manager requests for the remote database.
|
Modifier and Type | Method and Description |
---|---|
LockAdministrator |
getLockAdministrator()
Retrieve the
LockAdministrator object associated with this
LockManager instance. |
void |
lock(LockType lockType,
RecordIdentifier ident,
boolean update)
Lock or release a single database record in the current context.
|
void |
lock(LockType lockType,
RecordIdentifier ident,
boolean update,
long timeout)
Lock or release a single database record in the current context.
|
LockType |
lockTable(LockType lockType,
java.lang.String table,
boolean update)
Attempt to obtain the specified lock type on a table.
|
LockType |
queryLock(RecordIdentifier ident)
Query the lock type currently held by the current context for the
specified database record.
|
void |
setDatabase(Database database)
Set the name of the physical database with which this lock manager is
associated.
|
void |
setLockListener(LockListener listener)
Register a lock listener, which will receive notifications of changes in lock status for any
record managed by this object.
|
private final LockManagerMultiplexer multiplexer
private int mpID
public RemoteLockManager(LockManagerMultiplexer multiplexer)
multiplexer
- Lock manager multiplexer which will service remote requests.public void setDatabase(Database database)
setDatabase
in interface LockManager
database
- Database information object.public void setLockListener(LockListener listener)
Remote lock update notifications are not supported, so this method will throw an exception if invoked.
setLockListener
in interface LockManager
listener
- Listener to be registered or null
to deregister the current listener.java.lang.UnsupportedOperationException
- always.public LockAdministrator getLockAdministrator()
LockAdministrator
object associated with this
LockManager
instance.
This implementation returns null
; the administration of a
remote lock manager is not supported.
getLockAdministrator
in interface LockManager
null
.public void lock(LockType 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 LockManager
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(LockType lockType, RecordIdentifier ident, boolean update, long timeout) throws LockUnavailableException, LockTimeoutException
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 LockManager
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.LockTimeoutException
- if a non-zero timeout was provided and the requested lock has not been acquired
by the time that period has elapsed.public LockType lockTable(LockType 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 LockManager
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 table should be updated;
else false
.LockUnavailableException
- if a "no-wait" lock cannot be acquired immediately.public LockType queryLock(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 LockManager
ident
- ID which uniquely identifies the record being queried.null
.