diff --git a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/lock/ZookeeperLockRegistry.java b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/lock/ZookeeperLockRegistry.java index 689d0ec5fd0..d20d9e899f9 100644 --- a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/lock/ZookeeperLockRegistry.java +++ b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/lock/ZookeeperLockRegistry.java @@ -29,7 +29,6 @@ import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.recipes.locks.InterProcessMutex; -import org.apache.zookeeper.CreateMode; import org.springframework.beans.factory.DisposableBean; import org.springframework.core.task.AsyncTaskExecutor; @@ -275,28 +274,24 @@ public boolean tryLock() { @Override public boolean tryLock(long time, TimeUnit unit) throws InterruptedException { - Future future = null; + Future future = null; try { long startTime = System.currentTimeMillis(); - future = this.mutexTaskExecutor.submit(new Callable() { + future = this.mutexTaskExecutor.submit(new Callable() { @Override - public String call() throws Exception { - return ZkLock.this.client.create() - .creatingParentContainersIfNeeded() - .withProtection() - .withMode(CreateMode.EPHEMERAL_SEQUENTIAL) - .forPath(ZkLock.this.path); + public Boolean call() throws Exception { + return ZkLock.this.client.checkExists().forPath("/") != null; } }); long waitTime = unit.toMillis(time); - String ourPath = future.get(waitTime, TimeUnit.MILLISECONDS); + boolean connected = future.get(waitTime, TimeUnit.MILLISECONDS); - if (ourPath == null) { + if (!connected) { future.cancel(true); return false; }