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
ManifoldCFExceptionpublic String registerServiceBeginServiceActivity(String serviceType, String serviceName, IServiceCleanup cleanup) throws ManifoldCFException
registerServiceBeginServiceActivity in interface ILockManagerserviceType - 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.ManifoldCFExceptionpublic String registerServiceBeginServiceActivity(String serviceType, String serviceName, byte[] initialData, IServiceCleanup cleanup) throws ManifoldCFException
registerServiceBeginServiceActivity in interface ILockManagerserviceType - 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.ManifoldCFExceptionpublic void updateServiceData(String serviceType, String serviceName, byte[] serviceData) throws ManifoldCFException
updateServiceData in interface ILockManagerserviceType - 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.ManifoldCFExceptionpublic byte[] retrieveServiceData(String serviceType, String serviceName) throws ManifoldCFException
retrieveServiceData in interface ILockManagerserviceType - is the type of service.serviceName - is the name of the service.ManifoldCFExceptionpublic void scanServiceData(String serviceType, IServiceDataAcceptor dataAcceptor) throws ManifoldCFException
scanServiceData in interface ILockManagerserviceType - 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.ManifoldCFExceptionpublic int countActiveServices(String serviceType) throws ManifoldCFException
countActiveServices in interface ILockManagerserviceType - is the service type.ManifoldCFExceptionpublic boolean cleanupInactiveService(String serviceType, IServiceCleanup cleanup) throws ManifoldCFException
cleanupInactiveService in interface ILockManagerserviceType - is the service type.cleanup - is the object to call to clean up an inactive service.ManifoldCFExceptionpublic void endServiceActivity(String serviceType, String serviceName) throws ManifoldCFException
endServiceActivity in interface ILockManagerserviceType - is the type of service.serviceName - is the name of the service to exit.ManifoldCFExceptionpublic boolean checkServiceActive(String serviceType, String serviceName) throws ManifoldCFException
checkServiceActive in interface ILockManagerserviceType - is the type of service.serviceName - is the name of the service to check on.ManifoldCFExceptionprotected String constructUniqueServiceName(String serviceType) throws ManifoldCFException
ManifoldCFExceptionprotected static String makeServiceCounterName(String serviceType)
protected int readServiceCounter(String serviceCounterName) throws ManifoldCFException
ManifoldCFExceptionprotected void writeServiceCounter(String serviceCounterName, int counter) throws ManifoldCFException
ManifoldCFExceptionprotected void writeServiceData(String serviceType, String serviceName, byte[] serviceData) throws ManifoldCFException
ManifoldCFExceptionprotected byte[] readServiceData(String serviceType, String serviceName) throws ManifoldCFException
ManifoldCFExceptionprotected void deleteServiceData(String serviceType, String serviceName) throws ManifoldCFException
ManifoldCFExceptionprotected 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
ManifoldCFExceptionprotected void writeServiceName(String resourceName, String serviceName) throws ManifoldCFException
ManifoldCFExceptionpublic ManifoldCFConfiguration getSharedConfiguration() throws ManifoldCFException
getSharedConfiguration in interface ILockManagerconfigurationData - is the globally-shared configuration information.ManifoldCFExceptionpublic void setGlobalFlag(String flagName) throws ManifoldCFException
setGlobalFlag in interface ILockManagerflagName - is the name of the flag to set.ManifoldCFExceptionpublic void clearGlobalFlag(String flagName) throws ManifoldCFException
clearGlobalFlag in interface ILockManagerflagName - is the name of the flag to clear.ManifoldCFExceptionpublic boolean checkGlobalFlag(String flagName) throws ManifoldCFException
checkGlobalFlag in interface ILockManagerflagName - is the name of the flag to check.ManifoldCFExceptionpublic byte[] readData(String resourceName) throws ManifoldCFException
readData in interface ILockManagerresourceName - is the global name of the resource.ManifoldCFExceptionpublic void writeData(String resourceName, byte[] data) throws ManifoldCFException
writeData in interface ILockManagerresourceName - 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.ManifoldCFExceptionpublic final void timedWait(int time)
throws ManifoldCFException
timedWait in interface ILockManagertime - 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.ManifoldCFExceptionprotected LockPool getGlobalLockPool()
public final void enterNonExWriteLock(String lockKey) throws ManifoldCFException
enterNonExWriteLock in interface ILockManagerlockKey - is the name of the lock.ManifoldCFExceptionpublic final void enterNonExWriteLockNoWait(String lockKey) throws ManifoldCFException, LockException
ILockManagerenterNonExWriteLockNoWait in interface ILockManagerlockKey - is the name of the lock.ManifoldCFExceptionLockExceptionpublic final void leaveNonExWriteLock(String lockKey) throws ManifoldCFException
leaveNonExWriteLock in interface ILockManagerlockKey - is the name of the lock.ManifoldCFExceptionpublic final void enterWriteLock(String lockKey) throws ManifoldCFException
enterWriteLock in interface ILockManagerlockKey - is the name of the lock.ManifoldCFExceptionpublic final void enterWriteLockNoWait(String lockKey) throws ManifoldCFException, LockException
ILockManagerenterWriteLockNoWait in interface ILockManagerlockKey - is the name of the lock.ManifoldCFExceptionLockExceptionpublic final void leaveWriteLock(String lockKey) throws ManifoldCFException
ILockManagerleaveWriteLock in interface ILockManagerlockKey - is the name of the lock.ManifoldCFExceptionpublic final void enterReadLock(String lockKey) throws ManifoldCFException
enterReadLock in interface ILockManagerlockKey - is the name of the lock.ManifoldCFExceptionpublic final void enterReadLockNoWait(String lockKey) throws ManifoldCFException, LockException
ILockManagerenterReadLockNoWait in interface ILockManagerlockKey - is the name of the lock.ManifoldCFExceptionLockExceptionpublic final void leaveReadLock(String lockKey) throws ManifoldCFException
ILockManagerleaveReadLock in interface ILockManagerlockKey - is the name of the lock.ManifoldCFExceptionpublic final void enterLocks(String[] readLocks, String[] nonExWriteLocks, String[] writeLocks) throws ManifoldCFException
enterLocks in interface ILockManagerreadLocks - 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.ManifoldCFExceptionpublic final void enterLocksNoWait(String[] readLocks, String[] nonExWriteLocks, String[] writeLocks) throws ManifoldCFException, LockException
ILockManagerenterLocksNoWait in interface ILockManagerreadLocks - 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.ManifoldCFExceptionLockExceptionpublic final void leaveLocks(String[] readLocks, String[] writeNonExLocks, String[] writeLocks) throws ManifoldCFException
leaveLocks in interface ILockManagerreadLocks - 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.ManifoldCFExceptionpublic final void clearLocks()
throws ManifoldCFException
ILockManagerclearLocks in interface ILockManagerManifoldCFExceptionpublic final void enterReadCriticalSection(String sectionKey) throws ManifoldCFException
enterReadCriticalSection in interface ILockManagersectionKey - is the name of the section to enter. Only one thread can be in any given named
section at a time.ManifoldCFExceptionpublic final void leaveReadCriticalSection(String sectionKey) throws ManifoldCFException
leaveReadCriticalSection in interface ILockManagersectionKey - is the name of the section to leave. Only one thread can be in any given named
section at a time.ManifoldCFExceptionpublic final void enterNonExWriteCriticalSection(String sectionKey) throws ManifoldCFException
enterNonExWriteCriticalSection in interface ILockManagersectionKey - is the name of the section to enter. Only one thread can be in any given named
section at a time.ManifoldCFExceptionpublic final void leaveNonExWriteCriticalSection(String sectionKey) throws ManifoldCFException
leaveNonExWriteCriticalSection in interface ILockManagersectionKey - is the name of the section to leave. Only one thread can be in any given named
section at a time.ManifoldCFExceptionpublic final void enterWriteCriticalSection(String sectionKey) throws ManifoldCFException
enterWriteCriticalSection in interface ILockManagersectionKey - is the name of the section to enter. Only one thread can be in any given named
section at a time.ManifoldCFExceptionpublic final void leaveWriteCriticalSection(String sectionKey) throws ManifoldCFException
leaveWriteCriticalSection in interface ILockManagersectionKey - is the name of the section to leave. Only one thread can be in any given named
section at a time.ManifoldCFExceptionpublic final void enterCriticalSections(String[] readSectionKeys, String[] nonExSectionKeys, String[] writeSectionKeys) throws ManifoldCFException
enterCriticalSections in interface ILockManagerreadSectionKeys - 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.ManifoldCFExceptionpublic final void leaveCriticalSections(String[] readSectionKeys, String[] nonExSectionKeys, String[] writeSectionKeys) throws ManifoldCFException
leaveCriticalSections in interface ILockManagerreadSectionKeys - 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.ManifoldCFExceptionprotected static void enterNonExWrite(Long threadID, String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFExceptionprotected static void enterNonExWriteNoWait(Long threadID, String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException, LockException
ManifoldCFExceptionLockExceptionprotected static void leaveNonExWrite(String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFExceptionprotected static void enterWrite(Long threadID, String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFExceptionprotected static void enterWriteNoWait(Long threadID, String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException, LockException
ManifoldCFExceptionLockExceptionprotected static void leaveWrite(String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFExceptionprotected static void enterRead(Long threadID, String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFExceptionprotected static void enterReadNoWait(Long threadID, String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException, LockException
ManifoldCFExceptionLockExceptionprotected static void leaveRead(String lockKey, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFExceptionprotected static void clear(String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFExceptionprotected static void enter(Long threadID, String[] readLocks, String[] nonExWriteLocks, String[] writeLocks, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFExceptionprotected static void enterNoWait(Long threadID, String[] readLocks, String[] nonExWriteLocks, String[] writeLocks, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException, LockException
ManifoldCFExceptionLockExceptionprotected static void leave(String[] readLocks, String[] writeNonExLocks, String[] writeLocks, String description, LocalLockPool localLocks, LockPool crossLocks) throws ManifoldCFException
ManifoldCFExceptionprotected static BaseLockManager.LockDescription[] getSortedUniqueLocks(String[] readLocks, String[] writeNonExLocks, String[] writeLocks)