Skip to content

Commit 5ae022b

Browse files
committed
curator fix
1 parent 0787245 commit 5ae022b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

lts-core/src/main/java/com/lts/zookeeper/curator/CuratorZkClient.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.IOException;
2222
import java.io.Serializable;
2323
import java.util.List;
24+
import java.util.concurrent.atomic.AtomicBoolean;
2425

2526
/**
2627
* @author Robert HG (254963746@qq.com) on 5/16/15.
@@ -234,6 +235,7 @@ protected void doClose() {
234235
public class PathChildrenListener {
235236
private PathChildrenCache childrenCache;
236237
private PathChildrenCacheListener childrenCacheListener;
238+
private AtomicBoolean start = new AtomicBoolean(false);
237239

238240
public PathChildrenListener(String path, final ChildListener listener) {
239241
childrenCache = new PathChildrenCache(client, path, true);
@@ -259,18 +261,22 @@ public void childEvent(CuratorFramework c, PathChildrenCacheEvent event)
259261

260262
public void startListener() {
261263
try {
262-
childrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
263-
childrenCache.getListenable().addListener(childrenCacheListener);
264+
if (start.compareAndSet(false, true)) {
265+
childrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
266+
childrenCache.getListenable().addListener(childrenCacheListener);
267+
}
264268
} catch (Exception e) {
265269
throw new ZkException(e);
266270
}
267271
}
268272

269273
public void stopListener() {
270274
try {
271-
childrenCache.getListenable().removeListener(childrenCacheListener);
272-
childrenCache.clear();
273-
childrenCache.close();
275+
if (start.compareAndSet(true, false)) {
276+
childrenCache.getListenable().removeListener(childrenCacheListener);
277+
childrenCache.clear();
278+
childrenCache.close();
279+
}
274280
} catch (IOException e) {
275281
throw new ZkException(e);
276282
}
@@ -290,9 +296,9 @@ public void nodeChanged() throws Exception {
290296

291297
Object data = nodeCache.getCurrentData().getData();
292298

293-
if(data == null){
299+
if (data == null) {
294300
listener.dataDeleted(path);
295-
}else{
301+
} else {
296302
listener.dataChange(path, data);
297303
}
298304
}

lts-example/src/main/java/com/lts/example/api/JobClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static void console() throws IOException {
9090
// jobClient.setIdentity("test_jobclient_0000001");
9191
// jobClient.addConfig(SpiKey.LTS_JSON, "fastjson");
9292
// jobClient.addConfig("lts.remoting", "netty");
93-
jobClient.addConfig("zk.client", "curator");
93+
// jobClient.addConfig("zk.client", "curator");
9494
jobClient.start();
9595

9696
JobClientTest jobClientTest = new JobClientTest();

0 commit comments

Comments
 (0)