public class ZooKeeperLockManager extends BaseLockManager implements ILockManager
| Modifier and Type | Class and Description |
|---|---|
protected static class |
ZooKeeperLockManager.ZooKeeperShutdown |
BaseLockManager.LockDescription| Modifier and Type | Field and Description |
|---|---|
static String |
_rcsid |
protected static String |
anonymousServiceNamePrefix
Anonymous service name prefix, to be followed by an integer
|
protected ManifoldCFConfiguration |
cachedConfiguration |
protected static Integer |
connectionPoolLock |
protected static Integer |
ephemeralPoolLocker |
protected static ZooKeeperEphemeralNodePool |
myEphemeralNodes |
protected static LockPool |
myZooKeeperLocks |
protected static ZooKeeperConnectionPool |
pool |
protected static String |
zookeeperConnectStringParameter |
protected static Integer |
zookeeperPoolLocker |
protected static String |
zookeeperSessionTimeoutParameter |
activePrefix, anonymousServiceTypeCounter, globalData, globalFlags, localLocks, localSections, myLocks, mySections, serviceDataPrefix, serviceListPrefix, servicePrefix, serviceTypeLockPrefix, threadID, TYPE_READ, TYPE_WRITE, TYPE_WRITENONEX| Constructor and Description |
|---|
ZooKeeperLockManager()
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
protected static String |
buildServiceTypeActivePath(String serviceType,
String encodedServiceName)
Build a zk path for the active node for a specific service of a specific type.
|
protected static String |
buildServiceTypeLockPath(String serviceType)
Build a zk path for the lock for a specific service type.
|
protected static String |
buildServiceTypeRegistrationPath(String serviceType)
Build a zk path for the registration node for a specific service type.
|
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.
|
void |
clearGlobalFlag(String flagName)
Clear a flag.
|
protected String |
constructUniqueServiceName(ZooKeeperConnection connection,
String serviceType)
Construct a unique service name given the service type.
|
int |
countActiveServices(String serviceType)
Count all active services of a given type.
|
void |
endServiceActivity(String serviceType,
String serviceName)
End service activity.
|
protected void |
enterServiceRegistryReadLock(ZooKeeperConnection connection,
String serviceType)
Enter service registry read lock
|
protected void |
enterServiceRegistryWriteLock(ZooKeeperConnection connection,
String serviceType)
Enter service registry write lock
|
protected LockPool |
getGlobalLockPool()
Override this method to change the nature of global locks.
|
ManifoldCFConfiguration |
getSharedConfiguration()
Get the current shared configuration.
|
protected void |
leaveServiceRegistryLock(ZooKeeperConnection connection)
Leave service registry lock
|
static void |
main(String[] argv) |
protected static String |
makeServiceCounterName(String serviceType)
Make the service counter name for a service type.
|
byte[] |
readData(String resourceName)
Read data from a shared data resource.
|
protected int |
readServiceCounter(ZooKeeperConnection connection,
String serviceCounterName)
Read service counter.
|
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 |
setSharedConfiguration(InputStream configurationInputStream)
Write shared configuration.
|
protected static void |
shutdownPool()
Shutdown the connection pool.
|
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(ZooKeeperConnection connection,
String serviceCounterName,
int counter)
Write service counter.
|
buildServiceListEntry, buildServiceTypeLockName, clear, clearLocks, constructUniqueServiceName, deleteServiceData, enter, enterCriticalSections, enterLocks, enterLocksNoWait, enterNonExWrite, enterNonExWriteCriticalSection, enterNonExWriteLock, enterNonExWriteLockNoWait, enterNonExWriteNoWait, enterNoWait, enterRead, enterReadCriticalSection, enterReadLock, enterReadLockNoWait, enterReadNoWait, enterWrite, enterWriteCriticalSection, enterWriteLock, enterWriteLockNoWait, enterWriteNoWait, getSortedUniqueLocks, leave, leaveCriticalSections, leaveLocks, leaveNonExWrite, leaveNonExWriteCriticalSection, leaveNonExWriteLock, leaveRead, leaveReadCriticalSection, leaveReadLock, leaveWrite, leaveWriteCriticalSection, leaveWriteLock, makeActiveServiceFlagName, makeRegisteredServiceFlagName, makeServiceDataName, readServiceCounter, readServiceData, readServiceName, timedWait, writeServiceCounter, writeServiceData, writeServiceNameclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitclearLocks, enterCriticalSections, enterLocks, enterLocksNoWait, enterNonExWriteCriticalSection, enterNonExWriteLock, enterNonExWriteLockNoWait, enterReadCriticalSection, enterReadLock, enterReadLockNoWait, enterWriteCriticalSection, enterWriteLock, enterWriteLockNoWait, leaveCriticalSections, leaveLocks, leaveNonExWriteCriticalSection, leaveNonExWriteLock, leaveReadCriticalSection, leaveReadLock, leaveWriteCriticalSection, leaveWriteLock, timedWaitpublic static final String _rcsid
protected static final String zookeeperConnectStringParameter
protected static final String zookeeperSessionTimeoutParameter
protected static final String anonymousServiceNamePrefix
protected static Integer connectionPoolLock
protected static ZooKeeperConnectionPool pool
protected static Integer zookeeperPoolLocker
protected static LockPool myZooKeeperLocks
protected static Integer ephemeralPoolLocker
protected static ZooKeeperEphemeralNodePool myEphemeralNodes
protected ManifoldCFConfiguration cachedConfiguration
public ZooKeeperLockManager()
throws ManifoldCFException
ManifoldCFExceptionpublic String registerServiceBeginServiceActivity(String serviceType, String serviceName, IServiceCleanup cleanup) throws ManifoldCFException
registerServiceBeginServiceActivity in interface ILockManagerregisterServiceBeginServiceActivity in class BaseLockManagerserviceType - 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 ILockManagerregisterServiceBeginServiceActivity in class BaseLockManagerserviceType - 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 ILockManagerupdateServiceData in class BaseLockManagerserviceType - 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 ILockManagerretrieveServiceData in class BaseLockManagerserviceType - is the type of service.serviceName - is the name of the service.ManifoldCFExceptionpublic void scanServiceData(String serviceType, IServiceDataAcceptor dataAcceptor) throws ManifoldCFException
scanServiceData in interface ILockManagerscanServiceData in class BaseLockManagerserviceType - is the type of service.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 ILockManagercountActiveServices in class BaseLockManagerserviceType - is the service type.ManifoldCFExceptionpublic boolean cleanupInactiveService(String serviceType, IServiceCleanup cleanup) throws ManifoldCFException
cleanupInactiveService in interface ILockManagercleanupInactiveService in class BaseLockManagerserviceType - 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 ILockManagerendServiceActivity in class BaseLockManagerserviceType - 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 ILockManagercheckServiceActive in class BaseLockManagerserviceType - is the type of service.serviceName - is the name of the service to check on.ManifoldCFExceptionprotected void enterServiceRegistryReadLock(ZooKeeperConnection connection, String serviceType) throws ManifoldCFException, InterruptedException
protected void enterServiceRegistryWriteLock(ZooKeeperConnection connection, String serviceType) throws ManifoldCFException, InterruptedException
protected void leaveServiceRegistryLock(ZooKeeperConnection connection) throws ManifoldCFException, InterruptedException
protected String constructUniqueServiceName(ZooKeeperConnection connection, String serviceType) throws ManifoldCFException, InterruptedException
protected static String makeServiceCounterName(String serviceType)
protected int readServiceCounter(ZooKeeperConnection connection, String serviceCounterName) throws ManifoldCFException, InterruptedException
protected void writeServiceCounter(ZooKeeperConnection connection, String serviceCounterName, int counter) throws ManifoldCFException, InterruptedException
protected static String buildServiceTypeLockPath(String serviceType)
protected static String buildServiceTypeActivePath(String serviceType, String encodedServiceName)
protected static String buildServiceTypeRegistrationPath(String serviceType)
public ManifoldCFConfiguration getSharedConfiguration() throws ManifoldCFException
getSharedConfiguration in interface ILockManagergetSharedConfiguration in class BaseLockManagerconfigurationData - is the globally-shared configuration information.ManifoldCFExceptionpublic void setSharedConfiguration(InputStream configurationInputStream) throws ManifoldCFException
ManifoldCFExceptionpublic void setGlobalFlag(String flagName) throws ManifoldCFException
setGlobalFlag in interface ILockManagersetGlobalFlag in class BaseLockManagerflagName - is the name of the flag to set.ManifoldCFExceptionpublic void clearGlobalFlag(String flagName) throws ManifoldCFException
clearGlobalFlag in interface ILockManagerclearGlobalFlag in class BaseLockManagerflagName - is the name of the flag to clear.ManifoldCFExceptionpublic boolean checkGlobalFlag(String flagName) throws ManifoldCFException
checkGlobalFlag in interface ILockManagercheckGlobalFlag in class BaseLockManagerflagName - is the name of the flag to check.ManifoldCFExceptionpublic byte[] readData(String resourceName) throws ManifoldCFException
readData in interface ILockManagerreadData in class BaseLockManagerresourceName - is the global name of the resource.ManifoldCFExceptionpublic void writeData(String resourceName, byte[] data) throws ManifoldCFException
writeData in interface ILockManagerwriteData in class BaseLockManagerresourceName - 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 static void main(String[] argv)
protected LockPool getGlobalLockPool()
getGlobalLockPool in class BaseLockManagerprotected static void shutdownPool()
throws ManifoldCFException
ManifoldCFException