diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2014-09-17 18:15:04 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2014-09-17 18:19:06 -0700 |
commit | 12ecba2b73b78458d45020085bd5e8851e94e11b (patch) | |
tree | 80a10db03a3432285b7671a21999d31d038849cc | |
parent | fab18f8c80ff287f5a41935f1e648984018fad16 (diff) | |
download | tooz-12ecba2b73b78458d45020085bd5e8851e94e11b.tar.gz |
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
-rw-r--r-- | tooz/drivers/ipc.py | 4 | ||||
-rw-r--r-- | tooz/drivers/zookeeper.py | 19 | ||||
-rw-r--r-- | tooz/locking.py | 2 |
3 files changed, 18 insertions, 7 deletions
diff --git a/tooz/drivers/ipc.py b/tooz/drivers/ipc.py index 1f1c4f7..6de8f0d 100644 --- a/tooz/drivers/ipc.py +++ b/tooz/drivers/ipc.py @@ -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]) diff --git a/tooz/drivers/zookeeper.py b/tooz/drivers/zookeeper.py index 5585743..07cf0d2 100644 --- a/tooz/drivers/zookeeper.py +++ b/tooz/drivers/zookeeper.py @@ -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 = [] diff --git a/tooz/locking.py b/tooz/locking.py index 43b43f7..b12912e 100644 --- a/tooz/locking.py +++ b/tooz/locking.py @@ -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) |