private static class LockTableUpdater.UpdateWorker
extends java.lang.Object
implements java.lang.Runnable
Note that some analysis of the lock event has to occur in the user session in which the lock event occurred, but as much of the work as possible is deferred until the separate thread processes the events.
Modifier and Type | Class and Description |
---|---|
private static class |
LockTableUpdater.UpdateWorker.Handler
Invocation handler which delegates calls to the
LockTableUpdater.MinimalLock proxy methods to the
backing DMO instance. |
Modifier and Type | Field and Description |
---|---|
private static java.lang.Class<?> |
dmoClass
MetaLockImpl DMO implementation class
|
private static java.lang.String |
dmoEntity
MetaLockImpl DMO entity name
|
private boolean |
done
Termination flag
|
private java.util.List<RecordLockEvent> |
eventQueue
Event queue to which many threads can write and from which only one thread reads
|
private java.util.Map<java.lang.String,java.lang.Integer> |
fileNums
Cache of converted table names to file numbers
|
private LockTableUpdater.UpdateWorker.Handler |
handler
Invocation handler which maps proxy method calls to underlying DMO methods
|
private long |
lastAddedID
Unique and sequential ID of the last event added to the queue
|
private long |
lastProcessedID
Unique and sequential ID of the last event read from the queue and processed
|
private static java.lang.String |
LOCK_TABLE
Metadata lock table name
|
private static java.util.Map<java.lang.reflect.Method,java.lang.reflect.Method> |
methodMap
Map of
MinimalLock methods to MetaLockImpl methods |
private long |
nextPrimaryKey
Next available primary key for a new lock metadata record
|
private Persistence |
persistence
Persistence helper object for metadata database
|
private LockTableUpdater.MinimalLock |
proxy
Proxy object for the current metadata lock DMO
|
private java.lang.Object |
readLock
Lock needed to read from queue; must be obtained first if write lock is needed also
|
private static java.lang.String |
SQL_FILENUM
SQL query to find a file number by converted table name (used by lock manager)
|
private static java.lang.String |
SQL_LOCK
SQL query to find a lock record by lock recid and user
|
private AssociatedThread |
workThread
Update worker thread
|
private java.lang.Object |
writeLock
Lock needed to write to queue; must be obtained second if read lock is needed also
|
Constructor and Description |
---|
UpdateWorker(Persistence persistence)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
addEvent(RecordLockEvent event)
Add a record lock event to the queue, locking out other write and read operations until
the queue is updated.
|
private Persistable |
createRecord(RecordLockEvent event)
Create a metadata lock record for the given record lock event.
|
private Persistable |
findRecord(RecordLockEvent event)
Find the metadata lock record associated with the user ID and lock record ID specified by
the given record lock event.
|
(package private) void |
forceFlush()
This method is called within a user context to force any pending lock events to be
processed.
|
private java.lang.Integer |
getFileNum(RecordLockEvent event)
Get the file number associated with a lock event.
|
private long |
getLockRecordID(RecordLockEvent event)
Extract an integral lock record ID from the lock event.
|
private void |
processEvent(RecordLockEvent event)
Process an individual record lock event, updating the metadata lock table as appropriate.
|
private void |
processPendingEvents()
Process all pending record lock events in the queue.
|
void |
run()
This method executes in the worker thread, reading record lock events from the queue when
they become available, and updating the metadata database accordingly.
|
(package private) void |
terminate()
Set a flag to terminate the queue, removing any pending events which have not yet been
processed.
|
private static final java.lang.String LOCK_TABLE
private static final java.lang.String SQL_LOCK
private static final java.lang.String SQL_FILENUM
private static final java.lang.Class<?> dmoClass
private static final java.lang.String dmoEntity
private static final java.util.Map<java.lang.reflect.Method,java.lang.reflect.Method> methodMap
MinimalLock
methods to MetaLockImpl
methodsprivate final java.util.List<RecordLockEvent> eventQueue
private final Persistence persistence
private final LockTableUpdater.MinimalLock proxy
private final LockTableUpdater.UpdateWorker.Handler handler
private final AssociatedThread workThread
private final java.util.Map<java.lang.String,java.lang.Integer> fileNums
private boolean done
private java.lang.Object readLock
private java.lang.Object writeLock
private long lastAddedID
private long lastProcessedID
private long nextPrimaryKey
UpdateWorker(Persistence persistence)
persistence
- Persistence helper object for metadata database.public void run()
run
in interface java.lang.Runnable
void addEvent(RecordLockEvent event)
event
- Record lock event to be added.void forceFlush()
void terminate()
This method should invoked when the primary database associated with the enclosing lock table updater is deregistered, as part of cleaning up the associated metadata database.
private void processPendingEvents()
private void processEvent(RecordLockEvent event)
event
- Record lock event describing a new lock or a change in state of an existing
lock.private long getLockRecordID(RecordLockEvent event) throws PersistenceException
event
- A record lock event.PersistenceException
private Persistable findRecord(RecordLockEvent event) throws PersistenceException
event
- Record lock event.PersistenceException
- if a lock record cannot be found for the given event, or if there is an error
executing the query.private Persistable createRecord(RecordLockEvent event) throws PersistenceException
event
- Event which specifies information to be stored in the lock record.PersistenceException
- if there is any error querying related metadata, or if there is a reflection
error instantiating the DMO.private java.lang.Integer getFileNum(RecordLockEvent event) throws PersistenceException
event
- Record lock event.PersistenceException