summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/endpoint-zookeeper/src/main/java/org/apache/tuscany/sca/endpoint/zookeeper/AbstractDistributedMap.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/sca/modules/endpoint-zookeeper/src/main/java/org/apache/tuscany/sca/endpoint/zookeeper/AbstractDistributedMap.java')
-rw-r--r--java/sca/modules/endpoint-zookeeper/src/main/java/org/apache/tuscany/sca/endpoint/zookeeper/AbstractDistributedMap.java20
1 files changed, 16 insertions, 4 deletions
diff --git a/java/sca/modules/endpoint-zookeeper/src/main/java/org/apache/tuscany/sca/endpoint/zookeeper/AbstractDistributedMap.java b/java/sca/modules/endpoint-zookeeper/src/main/java/org/apache/tuscany/sca/endpoint/zookeeper/AbstractDistributedMap.java
index 94306507ce..68133db7c0 100644
--- a/java/sca/modules/endpoint-zookeeper/src/main/java/org/apache/tuscany/sca/endpoint/zookeeper/AbstractDistributedMap.java
+++ b/java/sca/modules/endpoint-zookeeper/src/main/java/org/apache/tuscany/sca/endpoint/zookeeper/AbstractDistributedMap.java
@@ -50,6 +50,9 @@ import org.oasisopen.sca.ServiceRuntimeException;
*/
public class AbstractDistributedMap<V> extends AbstractMap<String, V> implements Map<String, V>, Watcher {
protected ZooKeeper zooKeeper;
+ protected ClassLoader classLoader;
+ protected String root;
+
/**
* @param zooKeeper
* @param root
@@ -60,13 +63,22 @@ public class AbstractDistributedMap<V> extends AbstractMap<String, V> implements
this.zooKeeper = zooKeeper;
this.root = root;
this.classLoader = classLoader;
+ }
+
+ public void start() {
// FIXME:
this.zooKeeper.register(this);
+ try {
+ String path = getPath(root);
+ Stat stat = zooKeeper.exists(path, false);
+ if (stat == null) {
+ zooKeeper.create(path, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+ }
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
}
- protected ClassLoader classLoader;
- protected String root;
-
@Override
public Set<Map.Entry<String, V>> entrySet() {
String path = getPath(root);
@@ -268,7 +280,7 @@ public class AbstractDistributedMap<V> extends AbstractMap<String, V> implements
public void remove() {
childrenIterator.remove();
try {
- zooKeeper.delete(path, -1);
+ zooKeeper.delete(getPath(root, path), -1);
} catch (Throwable e) {
throw new ServiceRuntimeException(e);
}