Tom White commented on ZOOKEEPER-78:


I'm glad this is being worked on again. Some comments:

* Not sure if a Runnable is right for whenOwner, as Runnable implementations 
are often one-shot and can't be re-run, whereas it looks like WriteLock can be 
locked and unlocked repeatedly (is this right?). There's also no way to tell 
when the lock has been released. Might be better to have a standard listener 
interface called LockListener, with lockAcquired and lockReleased methods. 
Writing an implementation to run a Runnable would be trivial.
* I worry a little about WriteLock implementing 
java.util.concurrent.locks.Lock, since Lock seems oriented to single-process 
programs. By making WriteLock a Lock we make it easy for programmers to drop it 
in to programs that use Lock, without having to think about distributed error 
recovery. For example, Lock#lock() cannot throw checked exceptions, so we would 
have to wrap KeeperException in an unchecked exception, which could too readily 
be ignored. Perhaps the answer is to make the method naming and semantics as 
close as possible, without actually implementing Lock proper? (I think this is 
similar to the discussion in ZOOKEEPER-104.)
* Lots of classes and methods are public when they don't need to be. Really 
only WriteLock should be public, with public methods lock(), unlock(), getDir() 
(better named as getLockPath() or similar?), getWhenOwner(), setWhenOwner() (or 
whatever replaces the last two).

> added a high level protocol/feature - for easy Leader Election or exclusive 
> Write Lock creation
> -----------------------------------------------------------------------------------------------
>                 Key: ZOOKEEPER-78
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-78
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: java client
>    Affects Versions: 3.0.0
>            Reporter: james strachan
>            Assignee: james strachan
>             Fix For: 3.2.0
>         Attachments: patch_with_including_Benjamin's_fix.patch, 
> using_zookeeper_facade.patch, ZOOKEEPER-78.patch, ZOOKEEPER-78.patch
> Here's a patch which adds a little WriteLock helper class for performing 
> leader elections or creating exclusive locks in some directory znode. Note 
> its an early cut; am sure we can improve it over time. The aim is to avoid 
> folks having to use the low level ZK stuff but provide a simpler high level 
> abstraction.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

Reply via email to