Author: jstrachan
Date: Thu Jul 24 03:29:20 2008
New Revision: 679341
URL: http://svn.apache.org/viewvc?rev=679341&view=rev
Log:
added patch to fix https://issues.apache.org/jira/browse/ZOOKEEPER-90
Modified:
activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/WriteLock.java
activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/ZooKeeperFacade.java
activemq/sandbox/zookeeper/zookeeper-protocols/src/test/java/org/apache/zookeeper/protocols/WriteLockTest.java
Modified: activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/WriteLock.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/WriteLock.java?rev=679341&r1=679340&r2=679341&view=diff
==============================================================================
--- activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/WriteLock.java (original)
+++ activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/WriteLock.java Thu Jul 24 03:29:20 2008
@@ -54,6 +54,7 @@
super(zookeeper);
this.dir = dir;
this.whenOwnerListener = whenOwnerListener;
+ zookeeper.addWhenOwnerListener(whenOwnerListener);
}
/**
@@ -213,6 +214,8 @@
@Override
protected void doClose() {
+ whenOwnerListener.whenNotOwner();
+ zookeeper.removeWhenOwnerListener(whenOwnerListener);
unlock();
}
Modified: activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/ZooKeeperFacade.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/ZooKeeperFacade.java?rev=679341&r1=679340&r2=679341&view=diff
==============================================================================
--- activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/ZooKeeperFacade.java (original)
+++ activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/ZooKeeperFacade.java Thu Jul 24 03:29:20 2008
@@ -27,6 +27,7 @@
import java.io.IOException;
import java.util.List;
+import java.util.ArrayList;
/**
* A facade around the {@link ZooKeeper} instance which can deal with sessions expiring so that the facade is capable
@@ -41,6 +42,7 @@
private volatile Watcher defaultWatcher;
private long sessionId;
private byte[] sessionPasswd;
+ private List<WhenOwnerListener> whenOwnerListeners = new ArrayList<WhenOwnerListener>();
public ZooKeeperFacade(String host, int sessionTimeout, Watcher watcher) throws IOException {
this.host = host;
@@ -71,6 +73,24 @@
}
/**
+ * Adds a listener to be notified if the connection restarts due to a session expiration
+ *
+ * @param listener
+ */
+ public synchronized void addWhenOwnerListener(WhenOwnerListener listener) {
+ whenOwnerListeners.add(listener);
+ }
+
+ /**
+ * Removes the listener
+ *
+ * @param listener
+ */
+ public synchronized void removeWhenOwnerListener(WhenOwnerListener listener) {
+ whenOwnerListeners.remove(listener);
+ }
+
+ /**
* Forces reconnection to the ZooKeeper server with a new session ID.
* This method should only be called after the session has expired (which should be rare!)
* as the TCP connection will be closed and all ephemeral files deleted!
@@ -78,7 +98,10 @@
* @throws InterruptedException
* @throws IOException
*/
- public void reconnectWithNewSession() throws InterruptedException, IOException {
+ public synchronized void reconnectWithNewSession() throws InterruptedException, IOException {
+ for (WhenOwnerListener listener : whenOwnerListeners) {
+ listener.whenNotOwner();
+ }
close();
// now lets force the reconnection
Modified: activemq/sandbox/zookeeper/zookeeper-protocols/src/test/java/org/apache/zookeeper/protocols/WriteLockTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/zookeeper/zookeeper-protocols/src/test/java/org/apache/zookeeper/protocols/WriteLockTest.java?rev=679341&r1=679340&r2=679341&view=diff
==============================================================================
--- activemq/sandbox/zookeeper/zookeeper-protocols/src/test/java/org/apache/zookeeper/protocols/WriteLockTest.java (original)
+++ activemq/sandbox/zookeeper/zookeeper-protocols/src/test/java/org/apache/zookeeper/protocols/WriteLockTest.java Thu Jul 24 03:29:20 2008
@@ -59,7 +59,7 @@
}
public void whenNotOwner() {
- // TODO
+ LOG.info("ZNode " + nodeId + " is no longer the owner!");
}
});
nodes[i] = leader;