public class BaseLockManager extends Object implements ILockManager
Modifier and Type | Class and Description |
---|---|
protected static class |
BaseLockManager.LockDescription |
Modifier and Type | Field and Description |
---|---|
static String |
_rcsid |
protected static String |
activePrefix
A flag prefix, followed by the service type, and then followed by "_" and the service name
|
protected static String |
anonymousServiceNamePrefix
Anonymous service name prefix, to be followed by an integer
|
protected static String |
anonymousServiceTypeCounter
Anonymous global variable name prefix, to be followed by the service type
|
protected static Map<String,byte[]> |
globalData
Global resource data.
|
protected static Map<String,Boolean> |
globalFlags
Global flag information.
|
protected LocalLockPool |
localLocks |
protected LocalLockPool |
localSections |
protected static LockPool |
myLocks |
protected static LockPool |
mySections |
protected static String |
serviceDataPrefix
A data name prefix, followed by the service type, and then followed by "_" and the service name and "_" and the datatype
|
protected static String |
serviceListPrefix
A data name prefix, followed by the service type, and then followed by "_" and the instance number
|
protected static String |
servicePrefix
A flag prefix, followed by the service type, and then followed by "_" and the service name
|
protected static String |
serviceTypeLockPrefix
The service-type global write lock to control sync, followed by the service type
|
protected Long |
threadID |
protected static int |
TYPE_READ |
protected static int |
TYPE_WRITE |
protected static int |
TYPE_WRITENONEX |
Constructor and Description |
---|
BaseLockManager() |
Modifier and Type | Method and Description |
---|---|
protected static String |
buildServiceListEntry(String serviceType,
int i) |
protected static String |
buildServiceTypeLockName(String serviceType) |
boolean |
checkGlobalFlag(String flagName)
Check the condition of a specified flag.
|
boolean |
checkServiceActive(String serviceType,
String serviceName)
Check whether a service is active or not.
|
boolean |
cleanupInactiveService(String serviceType,
IServiceCleanup cleanup)
Clean up any inactive services found.
|
protected static void |
clear(String description,
LocalLockPool localLocks,
LockPool crossLocks) |
void |
clearGlobalFlag(String flagName)
Clear a flag.
|
void |
clearLocks()
Clear all outstanding locks in the system.
|
protected String |
constructUniqueServiceName(String serviceType)
Construct a unique service name given the service type.
|
int |
countActiveServices(String serviceType)
Count all active services of a given type.
|
protected void |
deleteServiceData(String serviceType,
String serviceName) |
void |
endServiceActivity(String serviceType,
String serviceName)
End service activity.
|
protected static void |
enter(Long threadID,
String[] readLocks,
String[] nonExWriteLocks,
String[] writeLocks,
String description,
LocalLockPool localLocks,
LockPool crossLocks) |
void |
enterCriticalSections(String[] readSectionKeys,
String[] nonExSectionKeys,
String[] writeSectionKeys)
Enter multiple critical sections simultaneously.
|
void |
enterLocks(String[] readLocks,
String[] nonExWriteLocks,
String[] writeLocks)
Enter multiple locks
|
void |
enterLocksNoWait(String[] readLocks,
String[] nonExWriteLocks,
String[] writeLocks)
Enter multiple locks simultaneously.
|
protected static void |
enterNonExWrite(Long threadID,
String lockKey,
String description,
LocalLockPool localLocks,
LockPool crossLocks) |
void |
enterNonExWriteCriticalSection(String sectionKey)
Enter a named, non-exclusive write critical section (NOT a lock).
|
void |
enterNonExWriteLock(String lockKey)
Enter a non-exclusive write-locked area (blocking out all readers, but letting in other "writers").
|
void |
enterNonExWriteLockNoWait(String lockKey)
Enter a non-exclusive write-locked area (blocking out all readers, but letting in other "writers").
|
protected static void |
enterNonExWriteNoWait(Long threadID,
String lockKey,
String description,
LocalLockPool localLocks,
LockPool crossLocks) |
protected static void |
enterNoWait(Long threadID,
String[] readLocks,
String[] nonExWriteLocks,
String[] writeLocks,
String description,
LocalLockPool localLocks,
LockPool crossLocks) |
protected static void |
enterRead(Long threadID,
String lockKey,
String description,
LocalLockPool localLocks,
LockPool crossLocks) |
void |
enterReadCriticalSection(String sectionKey)
Enter a named, read critical section (NOT a lock).
|
void |
enterReadLock(String lockKey)
Enter a read-only locked area (i.e., block ONLY if there's a writer)
|
void |
enterReadLockNoWait(String lockKey)
Enter a read-only locked area (i.e., block ONLY if there's a writer).
|
protected static void |
enterReadNoWait(Long threadID,
String lockKey,
String description,
LocalLockPool localLocks,
LockPool crossLocks) |
protected static void |
enterWrite(Long threadID,
String lockKey,
String description,
LocalLockPool localLocks,
LockPool crossLocks) |
void |
enterWriteCriticalSection(String sectionKey)
Enter a named, exclusive critical section (NOT a lock).
|
void |
enterWriteLock(String lockKey)
Enter a write locked area (i.e., block out both readers and other writers)
NOTE: Can't enter until all readers have left.
|
void |
enterWriteLockNoWait(String lockKey)
Enter a write locked code area (i.e., block out both readers and other writers),
but do not wait if the lock cannot be obtained.
|
protected static void |
enterWriteNoWait(Long threadID,
String lockKey,
String description,
LocalLockPool localLocks,
LockPool crossLocks) |
protected LockPool |
getGlobalLockPool()
Override this method to change the nature of global locks.
|
ManifoldCFConfiguration |
getSharedConfiguration()
Get the current shared configuration.
|
protected static BaseLockManager.LockDescription[] |
getSortedUniqueLocks(String[] readLocks,
String[] writeNonExLocks,
String[] writeLocks)
Process inbound locks into a sorted vector of most-restrictive unique locks
|
protected static void |
leave(String[] readLocks,
String[] writeNonExLocks,
String[] writeLocks,
String description,
LocalLockPool localLocks,
LockPool crossLocks) |
void |
leaveCriticalSections(String[] readSectionKeys,
String[] nonExSectionKeys,
String[] writeSectionKeys)
Leave multiple critical sections simultaneously.
|
void |
leaveLocks(String[] readLocks,
String[] writeNonExLocks,
String[] writeLocks)
Leave multiple locks
|
protected static void |
leaveNonExWrite(String lockKey,
String description,
LocalLockPool localLocks,
LockPool crossLocks) |
void |
leaveNonExWriteCriticalSection(String sectionKey)
Leave a named, non-exclusive write critical section (NOT a lock).
|
void |
leaveNonExWriteLock(String lockKey)
Leave a non-exclusive write lock.
|
protected static void |
leaveRead(String lockKey,
String description,
LocalLockPool localLocks,
LockPool crossLocks) |
void |
leaveReadCriticalSection(String sectionKey)
Leave a named, read critical section (NOT a lock).
|
void |
leaveReadLock(String lockKey)
Leave a read-locked code area.
|
protected static void |
leaveWrite(String lockKey,
String description,
LocalLockPool localLocks,
LockPool crossLocks) |
void |
leaveWriteCriticalSection(String sectionKey)
Leave a named, exclusive critical section (NOT a lock).
|
void |
leaveWriteLock(String lockKey)
Leave a write locked code area.
|
protected static String |
makeActiveServiceFlagName(String serviceType,
String serviceName) |
protected static String |
makeRegisteredServiceFlagName(String serviceType,
String serviceName) |
protected static String |
makeServiceCounterName(String serviceType)
Make the service counter name for a service type.
|
protected static String |
makeServiceDataName(String serviceType,
String serviceName) |
byte[] |
readData(String resourceName)
Read data from a shared data resource.
|
protected int |
readServiceCounter(String serviceCounterName)
Read service counter.
|
protected byte[] |
readServiceData(String serviceType,
String serviceName) |
protected String |
readServiceName(String resourceName) |
String |
registerServiceBeginServiceActivity(String serviceType,
String serviceName,
byte[] initialData,
IServiceCleanup cleanup)
Register a service and begin service activity.
|
String |
registerServiceBeginServiceActivity(String serviceType,
String serviceName,
IServiceCleanup cleanup)
Register a service and begin service activity.
|
byte[] |
retrieveServiceData(String serviceType,
String serviceName)
Retrieve service data for a service.
|
void |
scanServiceData(String serviceType,
IServiceDataAcceptor dataAcceptor)
Scan service data for a service type.
|
void |
setGlobalFlag(String flagName)
Raise a flag.
|
void |
timedWait(int time)
Wait for a time before retrying a lock.
|
void |
updateServiceData(String serviceType,
String serviceName,
byte[] serviceData)
Set service data for a service.
|
void |
writeData(String resourceName,
byte[] data)
Write data to a shared data resource.
|
protected void |
writeServiceCounter(String serviceCounterName,
int counter)
Write service counter.
|
protected void |
writeServiceData(String serviceType,
String serviceName,
byte[] serviceData) |
protected void |
writeServiceName(String resourceName,
String serviceName) |
public static final String _rcsid
protected static final int TYPE_READ
protected static final int TYPE_WRITENONEX
protected static final int TYPE_WRITE
protected final Long threadID
protected final LocalLockPool localLocks
protected static final LockPool myLocks
protected final LocalLockPool localSections
protected static final LockPool mySections
protected static final Map<String,Boolean> globalFlags
protected static final Map<String,byte[]> globalData
protected static final String serviceTypeLockPrefix
protected static final String serviceListPrefix
protected static final String servicePrefix
protected static final String activePrefix
protected static final String serviceDataPrefix
protected static final String anonymousServiceNamePrefix
protected static final String anonymousServiceTypeCounter
public BaseLockManager() throws ManifoldCFException
ManifoldCFException
public String registerServiceBeginServiceActivity(String serviceType, String serviceName, IServiceCleanup cleanup) throws ManifoldCFException
registerServiceBeginServiceActivity
in interface ILockManager
serviceType
- is the type of service.serviceName
- is the name of the service to register. If null is passed, a transient unique service name will be
created, and will be returned to the caller.cleanup
- is called to clean up either the current service, or all services of this type, if no other active service exists.
May be null. Local service cleanup is never called if the serviceName argument is null.ManifoldCFException
public String registerServiceBeginServiceActivity(String serviceType, String serviceName, byte[] initialData, IServiceCleanup cleanup) throws ManifoldCFException
registerServiceBeginServiceActivity
in interface ILockManager
serviceType
- is the type of service.serviceName
- is the name of the service to register. If null is passed, a transient unique service name will be
created, and will be returned to the caller.initialData
- is the initial service data for this service.cleanup
- is called to clean up either the current service, or all services of this type, if no other active service exists.
May be null. Local service cleanup is never called if the serviceName argument is null.ManifoldCFException
public void updateServiceData(String serviceType, String serviceName, byte[] serviceData) throws ManifoldCFException
updateServiceData
in interface ILockManager
serviceType
- is the type of service.serviceName
- is the name of the service.serviceData
- is the data to update to (may be null).
This updates the service's transient data (or deletes it). If the service is not active, an exception is thrown.ManifoldCFException
public byte[] retrieveServiceData(String serviceType, String serviceName) throws ManifoldCFException
retrieveServiceData
in interface ILockManager
serviceType
- is the type of service.serviceName
- is the name of the service.ManifoldCFException
public void scanServiceData(String serviceType, IServiceDataAcceptor dataAcceptor) throws ManifoldCFException
scanServiceData
in interface ILockManager
serviceType
- is the type of service.dataType
- is the type of data.dataAcceptor
- is the object that will be notified of each item of data for each service name found.ManifoldCFException
public int countActiveServices(String serviceType) throws ManifoldCFException
countActiveServices
in interface ILockManager
serviceType
- is the service type.ManifoldCFException
public boolean cleanupInactiveService(String serviceType, IServiceCleanup cleanup) throws ManifoldCFException
cleanupInactiveService
in interface ILockManager
serviceType
- is the service type.cleanup
- is the object to call to clean up an inactive service.ManifoldCFException
public void endServiceActivity(String serviceType, String serviceName) throws ManifoldCFException
endServiceActivity
in interface ILockManager
serviceType
- is the type of service.serviceName
- is the name of the service to exit.ManifoldCFException
public boolean checkServiceActive(String serviceType, String serviceName) throws ManifoldCFException
checkServiceActive
in interface ILockManager
serviceType
- is the type of service.serviceName
- is the name of the service to check on.ManifoldCFException
protected String constructUniqueServiceName(String serviceType) throws ManifoldCFException
ManifoldCFException
protected static String makeServiceCounterName(String serviceType)
protected int readServiceCounter(String serviceCounterName) throws ManifoldCFException
ManifoldCFException
protected void writeServiceCounter(String serviceCounterName, int counter) throws ManifoldCFException
ManifoldCFException
protected void writeServiceData(String serviceType, String serviceName, byte[] serviceData) throws ManifoldCFException
ManifoldCFException
protected byte[] readServiceData(String serviceType, String serviceName) throws ManifoldCFException
ManifoldCFException
protected void deleteServiceData(String serviceType, String serviceName) throws ManifoldCFException
ManifoldCFException
protected static String makeServiceDataName(String serviceType, String serviceName)
protected static String makeActiveServiceFlagName(String serviceType, String serviceName)
protected static String makeRegisteredServiceFlagName(String serviceType, String serviceName)
protected String readServiceName(String resourceName) throws ManifoldCFException
ManifoldCFException
protected void writeServiceName(String resourceName, String serviceName) throws ManifoldCFException
ManifoldCFException
public ManifoldCFConfiguration getSharedConfiguration() throws ManifoldCFException
getSharedConfiguration
in interface ILockManager
configurationData
- is the globally-shared configuration information.ManifoldCFException
public void setGlobalFlag(String flagName) throws ManifoldCFException
setGlobalFlag
in interface ILockManager
flagName
- is the name of the flag to set.ManifoldCFException
public void clearGlobalFlag(String flagName) throws ManifoldCFException
clearGlobalFlag
in interface ILockManager
flagName
- is the name of the flag to clear.ManifoldCFException
public boolean checkGlobalFlag(String flagName) throws ManifoldCFException
checkGlobalFlag
in interface ILockManager
flagName
- is the name of the flag to check.ManifoldCFException
public byte[] readData(String resourceName) throws ManifoldCFException
readData
in interface ILockManager
resourceName
- is the global name of the resource.ManifoldCFException
public void writeData(String resourceName, byte[] data) throws ManifoldCFException
writeData
in interface ILockManager
resourceName
- is the global name of the resource.data
- is the byte array containing the data. Pass null if you want to delete the resource completely.ManifoldCFException
public final void timedWait(int time) throws ManifoldCFException
timedWait
in interface ILockManager
time
- is the amount of time to wait, in milliseconds. Zero is a legal
value, and will wait no time, but will give up the current timeslice to another
thread.ManifoldCFException
protected LockPool getGlobalLockPool()
public final void enterNonExWriteLock(String lockKey) throws ManifoldCFException
enterNonExWriteLock
in interface ILockManager
lockKey
- is the name of the lock.ManifoldCFException
public final void enterNonExWriteLockNoWait(String lockKey) throws ManifoldCFException, LockException
ILockManager
enterNonExWriteLockNoWait
in interface ILockManager
lockKey
- is the name of the lock.ManifoldCFException
LockException
public final void leaveNonExWriteLock(String lockKey) throws ManifoldCFException
leaveNonExWriteLock
in interface ILockManager
lockKey
- is the name of the lock.ManifoldCFException
public final void enterWriteLock(String lockKey) throws ManifoldCFException
enterWriteLock
in interface ILockManager
lockKey
- is the name of the lock.ManifoldCFException
public final void enterWriteLockNoWait(String lockKey) throws ManifoldCFException, LockException
ILockManager
enterWriteLockNoWait
in interface ILockManager
lockKey
- is the name of the lock.ManifoldCFException
LockException
public final void leaveWriteLock(String lockKey) throws ManifoldCFException
ILockManager
leaveWriteLock
in interface ILockManager
lockKey
- is the name of the lock.ManifoldCFException
public final void enterReadLock(String lockKey) throws ManifoldCFException
enterReadLock
in interface ILockManager
lockKey
- is the name of the lock.ManifoldCFException
public final void enterReadLockNoWait(String lockKey) throws ManifoldCFException, LockException
ILockManager
enterReadLockNoWait
in interface ILockManager
lockKey
- is the name of the lock.ManifoldCFException
LockException
public final void leaveReadLock(String lockKey) throws ManifoldCFException
ILockManager
leaveReadLock
in interface ILockManager
lockKey
- is the name of the lock.ManifoldCFException
public final void enterLocks(String[] readLocks, String[] nonExWriteLocks, String[] writeLocks) throws ManifoldCFException
enterLocks
in interface ILockManager
readLocks
- is an array of read lock names, or null if there are no read locks desired.nonExWriteLocks
- is an array of non-ex write lock names, or null if none desired.writeLocks
- is an array of write lock names, or null if there are none desired.ManifoldCFException
public final void enterLocksNoWait(String[] readLocks, String[] nonExWriteLocks, String[] writeLocks) throws ManifoldCFException, LockException
ILockManager
enterLocksNoWait
in interface ILockManager
readLocks
- is an array of read lock names, or null if there are no read locks desired.nonExWriteLocks
- is an array of non-ex write lock names, or null if none desired.writeLocks
- is an array of write lock names, or null if there are none desired.ManifoldCFException
LockException
public final void leaveLocks(String[] readLocks, String[] writeNonExLocks, String[] writeLocks) throws ManifoldCFException
leaveLocks
in interface ILockManager
readLocks
- is an array of read lock names, or null if there are no read locks desired.writeNonExLocks
- is an array of non-ex write lock names, or null if none desired.writeLocks
- is an array of write lock names, or null if there are none desired.ManifoldCFException
public final void clearLocks() throws ManifoldCFException
ILockManager
clearLocks
in interface ILockManager
ManifoldCFException
public final void enterReadCriticalSection(String sectionKey) throws ManifoldCFException
enterReadCriticalSection
in interface ILockManager
sectionKey
- is the name of the section to enter. Only one thread can be in any given named
section at a time.ManifoldCFException
public final void leaveReadCriticalSection(String sectionKey) throws ManifoldCFException
leaveReadCriticalSection
in interface ILockManager
sectionKey
- is the name of the section to leave. Only one thread can be in any given named
section at a time.ManifoldCFException
public final void enterNonExWriteCriticalSection(String sectionKey) throws ManifoldCFException
enterNonExWriteCriticalSection
in interface ILockManager
sectionKey
- is the name of the section to enter. Only one thread can be in any given named
section at a time.ManifoldCFException
public final void leaveNonExWriteCriticalSection(String sectionKey) throws ManifoldCFException
leaveNonExWriteCriticalSection
in interface ILockManager
sectionKey
- is the name of the section to leave. Only one thread can be in any given named
section at a time.ManifoldCFException
public final void enterWriteCriticalSection(String sectionKey) throws ManifoldCFException
enterWriteCriticalSection
in interface ILockManager
sectionKey
- is the name of the section to enter. Only one thread can be in any given named
section at a time.ManifoldCFException
public final void leaveWriteCriticalSection(String sectionKey) throws ManifoldCFException
leaveWriteCriticalSection
in interface ILockManager
sectionKey
- is the name of the section to leave. Only one thread can be in any given named
section at a time.ManifoldCFException
public final void enterCriticalSections(String[] readSectionKeys, String[] nonExSectionKeys, String[] writeSectionKeys) throws ManifoldCFException
enterCriticalSections
in interface ILockManager
readSectionKeys
- is an array of read section descriptors, or null if there are no read sections desired.nonExSectionKeys
- is an array of non-ex write section descriptors, or null if none desired.writeSectionKeys
- is an array of write section descriptors, or null if there are none desired.ManifoldCFException
public final void leaveCriticalSections(String[] readSectionKeys, String[] nonExSectionKeys, String[] writeSectionKeys) throws ManifoldCFException
leaveCriticalSections
in interface ILockManager
readSectionKeys
- is an array of read section descriptors, or null if there are no read sections desired.nonExSectionKeys
- is an array of non-ex write section descriptors, or null if none desired.writeSectionKeys
- is an array of write section descriptors, or null if there are none desired.ManifoldCFException
protected static void enterNonExWrite(Long threadID, String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFException
protected static void enterNonExWriteNoWait(Long threadID, String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException, LockException
ManifoldCFException
LockException
protected static void leaveNonExWrite(String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFException
protected static void enterWrite(Long threadID, String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFException
protected static void enterWriteNoWait(Long threadID, String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException, LockException
ManifoldCFException
LockException
protected static void leaveWrite(String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFException
protected static void enterRead(Long threadID, String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFException
protected static void enterReadNoWait(Long threadID, String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException, LockException
ManifoldCFException
LockException
protected static void leaveRead(String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFException
protected static void clear(String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFException
protected static void enter(Long threadID, String[] readLocks, String[] nonExWriteLocks, String[] writeLocks, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFException
protected static void enterNoWait(Long threadID, String[] readLocks, String[] nonExWriteLocks, String[] writeLocks, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException, LockException
ManifoldCFException
LockException
protected static void leave(String[] readLocks, String[] writeNonExLocks, String[] writeLocks, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFException
protected static BaseLockManager.LockDescription[] getSortedUniqueLocks(String[] readLocks, String[] writeNonExLocks, String[] writeLocks)