Skip to content

Commit 493b4aa

Browse files
garyrussellartembilan
authored andcommitted
INT-4493: ZK MStore binary compatiblity
JIRA: https://jira.spring.io/browse/INT-4493 Use reflection to enable binary compatibility with curator 4.x. The return type of `ExistsBuilder.creatingParentContainersIfNeeded()` is now a sub-interface of `ExistsBuilderMain`. Tested with a boot app with curator 4.0.1. * Polishing - add cause
1 parent 67fdac8 commit 493b4aa

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616

1717
package org.springframework.integration.zookeeper.metadata;
1818

19+
import java.lang.reflect.Method;
1920
import java.util.List;
2021
import java.util.concurrent.ConcurrentHashMap;
2122
import java.util.concurrent.ConcurrentMap;
2223
import java.util.concurrent.CopyOnWriteArrayList;
24+
import java.util.concurrent.atomic.AtomicReference;
2325

2426
import org.apache.curator.framework.CuratorFramework;
27+
import org.apache.curator.framework.api.ExistsBuilder;
28+
import org.apache.curator.framework.api.ExistsBuilderMain;
2529
import org.apache.curator.framework.recipes.cache.ChildData;
2630
import org.apache.curator.framework.recipes.cache.PathChildrenCache;
2731
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
@@ -35,6 +39,7 @@
3539
import org.springframework.integration.metadata.MetadataStoreListener;
3640
import org.springframework.integration.support.utils.IntegrationUtils;
3741
import org.springframework.util.Assert;
42+
import org.springframework.util.ReflectionUtils;
3843

3944
/**
4045
* Zookeeper-based {@link ListenableMetadataStore} based on a Zookeeper node.
@@ -48,6 +53,26 @@
4853
*/
4954
public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLifecycle {
5055

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+
5176
private final Object lifecycleMonitor = new Object();
5277

5378
private final CuratorFramework client;
@@ -277,9 +302,10 @@ public void start() {
277302
synchronized (this.lifecycleMonitor) {
278303
if (!this.running) {
279304
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);
283309

284310
this.cache = new PathChildrenCache(this.client, this.root, true);
285311
this.cache.getListenable()

0 commit comments

Comments
 (0)