|
16 | 16 |
|
17 | 17 | package org.springframework.integration.zookeeper.metadata;
|
18 | 18 |
|
| 19 | +import java.lang.reflect.Method; |
19 | 20 | import java.util.List;
|
20 | 21 | import java.util.concurrent.ConcurrentHashMap;
|
21 | 22 | import java.util.concurrent.ConcurrentMap;
|
22 | 23 | import java.util.concurrent.CopyOnWriteArrayList;
|
| 24 | +import java.util.concurrent.atomic.AtomicReference; |
23 | 25 |
|
24 | 26 | import org.apache.curator.framework.CuratorFramework;
|
| 27 | +import org.apache.curator.framework.api.ExistsBuilder; |
| 28 | +import org.apache.curator.framework.api.ExistsBuilderMain; |
25 | 29 | import org.apache.curator.framework.recipes.cache.ChildData;
|
26 | 30 | import org.apache.curator.framework.recipes.cache.PathChildrenCache;
|
27 | 31 | import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
|
|
35 | 39 | import org.springframework.integration.metadata.MetadataStoreListener;
|
36 | 40 | import org.springframework.integration.support.utils.IntegrationUtils;
|
37 | 41 | import org.springframework.util.Assert;
|
| 42 | +import org.springframework.util.ReflectionUtils; |
38 | 43 |
|
39 | 44 | /**
|
40 | 45 | * Zookeeper-based {@link ListenableMetadataStore} based on a Zookeeper node.
|
|
48 | 53 | */
|
49 | 54 | public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLifecycle {
|
50 | 55 |
|
| 56 | + private final static Method creatingParentContainersIfNeeded; |
| 57 | + |
| 58 | + static { |
| 59 | + AtomicReference<Method> method = new AtomicReference<>(); |
| 60 | + try { |
| 61 | + ReflectionUtils.doWithMethods(ExistsBuilder.class, m -> { |
| 62 | + method.set(m); |
| 63 | + }, m -> { |
| 64 | + return "creatingParentContainersIfNeeded".equals(m.getName()) && m.getParameterCount() == 0; |
| 65 | + }); |
| 66 | + } |
| 67 | + catch (Exception e) { |
| 68 | + throw new IllegalStateException("Cannot find ExistsBuilder.creatingParentContainersIfNeeded()", e); |
| 69 | + } |
| 70 | + if (method.get() == null) { |
| 71 | + throw new IllegalStateException("Cannot find ExistsBuilder.creatingParentContainersIfNeeded()"); |
| 72 | + } |
| 73 | + creatingParentContainersIfNeeded = method.get(); |
| 74 | + } |
| 75 | + |
51 | 76 | private final Object lifecycleMonitor = new Object();
|
52 | 77 |
|
53 | 78 | private final CuratorFramework client;
|
@@ -277,9 +302,10 @@ public void start() {
|
277 | 302 | synchronized (this.lifecycleMonitor) {
|
278 | 303 | if (!this.running) {
|
279 | 304 | try {
|
280 |
| - this.client.checkExists() |
281 |
| - .creatingParentContainersIfNeeded() |
282 |
| - .forPath(this.root); |
| 305 | + ExistsBuilder checkExists = this.client.checkExists(); |
| 306 | + ExistsBuilderMain builderMain = (ExistsBuilderMain) creatingParentContainersIfNeeded |
| 307 | + .invoke(checkExists, new Object[0]); |
| 308 | + builderMain.forPath(this.root); |
283 | 309 |
|
284 | 310 | this.cache = new PathChildrenCache(this.client, this.root, true);
|
285 | 311 | this.cache.getListenable()
|
|
0 commit comments