Standardize on the same lock acquire method definition

It appears the the other drivers have a acquire that does not
take a timeout, but the zookeeper driver has a acquire method that
does take a timeout.

To be more consistent just standardize on the acquire not taking
a timeout paramater and having it provided by the driver options
like the IPC and memcached drivers do.

Change-Id: I86d5197ad57a4c891615e100365347e3e0bdd4c3
This commit is contained in:
Joshua Harlow 2014-09-17 18:15:04 -07:00
parent fab18f8c80
commit 12ecba2b73
3 changed files with 18 additions and 7 deletions

View File

@ -112,9 +112,7 @@ class IPCDriver(coordination.CoordinationDriver):
:param lock_timeout: how many seconds to wait when trying to acquire
a lock in blocking mode. None means forever, 0
means don't wait, any other value means wait
this amount of seconds. super(IPCDriver,
self).__init__() self.lock_timeout =
lock_timeout
this amount of seconds.
"""
super(IPCDriver, self).__init__()
self.lock_timeout = int(options.get('lock_timeout', ['30'])[-1])

View File

@ -27,11 +27,13 @@ from tooz import locking
class ZooKeeperLock(locking.Lock):
def __init__(self, name, lock):
def __init__(self, name, lock, timeout):
super(ZooKeeperLock, self).__init__(name)
self._lock = lock
self.timeout = timeout
def acquire(self, blocking=True, timeout=None):
def acquire(self, blocking=True):
timeout = self.timeout if blocking else None
return self._lock.acquire(blocking=blocking,
timeout=timeout)
@ -40,6 +42,15 @@ class ZooKeeperLock(locking.Lock):
class BaseZooKeeperDriver(coordination.CoordinationDriver):
"""Initialize the IPC driver.
:param timeout: connection timeout to wait when first connecting to the
zookeeper server
:param lock_timeout: how many seconds to wait when trying to acquire
a lock in blocking mode. None means forever, 0
means don't wait, any other value means wait
this amount of seconds.
"""
_TOOZ_NAMESPACE = b"tooz"
@ -47,6 +58,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
super(BaseZooKeeperDriver, self).__init__()
self._member_id = member_id
self.timeout = int(options.get('timeout', ['10'])[-1])
self.lock_timeout = int(options.get('lock_timeout', ['30'])[-1])
def start(self):
try:
@ -334,7 +346,8 @@ class KazooDriver(BaseZooKeeperDriver):
name,
self._coord.Lock(
self.paths_join(b"/", self._TOOZ_NAMESPACE, b"locks", name),
self._member_id.decode('ascii')))
self._member_id.decode('ascii')),
self.lock_timeout)
def run_watchers(self):
ret = []

View File

@ -44,7 +44,7 @@ class Lock(object):
"""
@abc.abstractmethod
def acquire(self):
def acquire(self, blocking=True):
"""Attempts to acquire the lock.
:returns: returns true if acquired (false if not)