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, writeServiceName
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clearLocks, enterCriticalSections, enterLocks, enterLocksNoWait, enterNonExWriteCriticalSection, enterNonExWriteLock, enterNonExWriteLockNoWait, enterReadCriticalSection, enterReadLock, enterReadLockNoWait, enterWriteCriticalSection, enterWriteLock, enterWriteLockNoWait, leaveCriticalSections, leaveLocks, leaveNonExWriteCriticalSection, leaveNonExWriteLock, leaveReadCriticalSection, leaveReadLock, leaveWriteCriticalSection, leaveWriteLock, timedWait
public 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
ManifoldCFException
public String registerServiceBeginServiceActivity(String serviceType, String serviceName, IServiceCleanup cleanup) throws ManifoldCFException
registerServiceBeginServiceActivity
in interface ILockManager
registerServiceBeginServiceActivity
in class BaseLockManager
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
registerServiceBeginServiceActivity
in class BaseLockManager
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
updateServiceData
in class BaseLockManager
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
retrieveServiceData
in class BaseLockManager
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
scanServiceData
in class BaseLockManager
serviceType
- is the type of service.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
countActiveServices
in class BaseLockManager
serviceType
- is the service type.ManifoldCFException
public boolean cleanupInactiveService(String serviceType, IServiceCleanup cleanup) throws ManifoldCFException
cleanupInactiveService
in interface ILockManager
cleanupInactiveService
in class BaseLockManager
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
endServiceActivity
in class BaseLockManager
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
checkServiceActive
in class BaseLockManager
serviceType
- is the type of service.serviceName
- is the name of the service to check on.ManifoldCFException
protected 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 ILockManager
getSharedConfiguration
in class BaseLockManager
configurationData
- is the globally-shared configuration information.ManifoldCFException
public void setSharedConfiguration(InputStream configurationInputStream) throws ManifoldCFException
ManifoldCFException
public void setGlobalFlag(String flagName) throws ManifoldCFException
setGlobalFlag
in interface ILockManager
setGlobalFlag
in class BaseLockManager
flagName
- is the name of the flag to set.ManifoldCFException
public void clearGlobalFlag(String flagName) throws ManifoldCFException
clearGlobalFlag
in interface ILockManager
clearGlobalFlag
in class BaseLockManager
flagName
- is the name of the flag to clear.ManifoldCFException
public boolean checkGlobalFlag(String flagName) throws ManifoldCFException
checkGlobalFlag
in interface ILockManager
checkGlobalFlag
in class BaseLockManager
flagName
- is the name of the flag to check.ManifoldCFException
public byte[] readData(String resourceName) throws ManifoldCFException
readData
in interface ILockManager
readData
in class BaseLockManager
resourceName
- is the global name of the resource.ManifoldCFException
public void writeData(String resourceName, byte[] data) throws ManifoldCFException
writeData
in interface ILockManager
writeData
in class BaseLockManager
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 static void main(String[] argv)
protected LockPool getGlobalLockPool()
getGlobalLockPool
in class BaseLockManager
protected static void shutdownPool() throws ManifoldCFException
ManifoldCFException