Index: src/main/java/net/sf/katta/zk/ZKClient.java =================================================================== --- src/main/java/net/sf/katta/zk/ZKClient.java (revision 11343) +++ src/main/java/net/sf/katta/zk/ZKClient.java Thu Jun 04 15:35:47 PDT 2009 @@ -46,7 +46,7 @@ /** * Abstracts the interation with zookeeper and allows permanent (not just one * time) watches on nodes in ZooKeeper - * + * */ public class ZKClient implements Watcher { @@ -79,7 +79,7 @@ /** * Starts a zookeeper client and waits until connected with one of the * zookeeper servers. - * + * * @param maxMsToWaitUntilConnected * the milliseconds a method call will wait until the zookeeper * client is connected with the server @@ -168,7 +168,7 @@ /** * Subscribes an {@link IZKEventListener} for permanent notifications for * children changes (adds and removes) of given path. - * + * * @param path * @param listener * @return list of children nodes for given path. @@ -202,7 +202,7 @@ /** * Subscribes notifications for permanent notifications for data changes on * the given node path. - * + * * @param path * @param listener * @throws KattaException @@ -271,7 +271,7 @@ /** * Creates an node for given path without any data. - * + * * @param path * @throws KattaException */ @@ -281,7 +281,7 @@ /** * Creates an node for given path with given {@link Writable} data. - * + * * @param path * @param writable * @throws KattaException @@ -340,7 +340,7 @@ /** * Creates an ephemeral node for give path. In case the client that created * that node disconnects the node is removed. - * + * * @param path * @throws KattaException */ @@ -350,7 +350,7 @@ /** * Creates and ephemeral node with given data of the writable. - * + * * @param path * @param writable * @throws KattaException @@ -362,7 +362,7 @@ /** * Deletes a given path. For recursive deletes use * {@link #deleteRecursive(String)}. - * + * * @param path * @return * @throws KattaException @@ -393,7 +393,7 @@ /** * Deletes a path and all children recursively. - * + * * @param path The path to delete. * @return true if successful. * @throws KattaException @@ -432,23 +432,33 @@ /** * Checks if a node with given path exists. - * + * * @param path * @return * @throws KattaException */ public boolean exists(final String path) throws KattaException { ensureZkRunning(); + for (int i = 0; i < 5; i++) { - try { + try { + try { - return _zk.exists(path, false) != null; + return _zk.exists(path, false) != null; - } catch (final Exception e) { + } catch (KeeperException.ConnectionLossException e) { + // should try again after a very short time + Thread.sleep(10); + } catch (KeeperException e) { - throw new KattaException("unable to check path: " + path, e); - } + throw new KattaException("unable to check path: " + path, e); + } + } catch (InterruptedException e1) { + // ignore this since it just made us wake up a little early - } + } + } + throw new KattaException("unable to check path after many retries: " + path); + } /** * Returns an List of all Children names of given path. - * + * * @param path * @return * @throws KattaException @@ -613,7 +623,7 @@ /** * Reads that data of given path into a writeable instance. Make sure you use * the same writable implementation as you used to write the data. - * + * * @param path * @param writable * @return @@ -666,7 +676,7 @@ /** * Shows the full node structure of the Zookeeper server. Useful for * debugging. - * + * * @throws KattaException */ public void showFolders(boolean all) throws KattaException { @@ -709,7 +719,7 @@ /** * Creates a node and writes data of writable into the given path. - * + * * @param path * @param writable * @throws KattaException @@ -738,7 +748,7 @@ /** * Creates a set of default folder structure for katta within a zookeeper . - * + * * @throws KattaException */ public void createDefaultNameSpace() throws KattaException { @@ -789,7 +799,7 @@ public ZkConfiguration getConfig() { return _conf; } - + public static class ZkLock extends ReentrantLock { private static final long serialVersionUID = 1L;