You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2017/02/09 18:36:11 UTC
[12/47] curator git commit: lots of refactoring,
eliminate checked exceptions, etc.
lots of refactoring, eliminate checked exceptions, etc.
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/81f0ab26
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/81f0ab26
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/81f0ab26
Branch: refs/heads/CURATOR-3.0
Commit: 81f0ab26ab0a0b57bdb902bb6a0034bd0bd54fcd
Parents: 74f1410
Author: randgalt <ra...@apache.org>
Authored: Thu Jan 5 18:18:30 2017 -0500
Committer: randgalt <ra...@apache.org>
Committed: Thu Jan 5 18:18:30 2017 -0500
----------------------------------------------------------------------
.../curator/x/crimps/async/AsyncCrimps.java | 84 +++++++-----------
.../apache/curator/x/crimps/async/Crimped.java | 4 +-
.../crimps/async/CrimpedBackgroundCallback.java | 10 ++-
.../crimps/async/CrimpedConfigEnsembleable.java | 6 +-
.../x/crimps/async/CrimpedEnsembleable.java | 3 +-
.../x/crimps/async/CrimpedEnsembleableImpl.java | 22 ++++-
.../x/crimps/async/CrimpedMultiTransaction.java | 3 +-
.../curator/x/crimps/async/CrimpedPathable.java | 30 +++++++
.../x/crimps/async/CrimpledEnsembleable.java | 24 +++++
.../crimps/async/CrimpledPathAndBytesable.java | 32 +++++++
.../async/CrimpledPathAndBytesableImpl.java | 92 ++++++++++++++++++++
11 files changed, 243 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/81f0ab26/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/AsyncCrimps.java
----------------------------------------------------------------------
diff --git a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/AsyncCrimps.java b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/AsyncCrimps.java
index afe97da..639deca 100644
--- a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/AsyncCrimps.java
+++ b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/AsyncCrimps.java
@@ -78,57 +78,57 @@ public class AsyncCrimps
return new AsyncCrimps(unhandledErrorListener);
}
- public PathAndBytesable<CompletionStage<String>> name(BackgroundPathAndBytesable<String> builder)
+ public CrimpledPathAndBytesable<CompletionStage<String>> name(BackgroundPathAndBytesable<String> builder)
{
return build(builder, nameProc);
}
- public PathAndBytesable<CompletionStage<String>> path(BackgroundPathAndBytesable<String> builder)
+ public CrimpledPathAndBytesable<CompletionStage<String>> path(BackgroundPathAndBytesable<String> builder)
{
return build(builder, pathProc);
}
- public Pathable<CompletionStage<Void>> ignored(BackgroundPathable<Void> builder)
+ public CrimpedPathable<CompletionStage<Void>> ignored(BackgroundPathable<Void> builder)
{
return build(builder, ignoredProc);
}
- public Pathable<CompletionStage<byte[]>> data(BackgroundPathable<byte[]> builder)
+ public CrimpedPathable<CompletionStage<byte[]>> data(BackgroundPathable<byte[]> builder)
{
return build(builder, dataProc);
}
- public Pathable<CompletionStage<List<String>>> children(BackgroundPathable<List<String>> builder)
+ public CrimpedPathable<CompletionStage<List<String>>> children(BackgroundPathable<List<String>> builder)
{
return build(builder, childrenProc);
}
- public Pathable<CompletionStage<Stat>> stat(BackgroundPathable<Stat> builder)
+ public CrimpedPathable<CompletionStage<Stat>> stat(BackgroundPathable<Stat> builder)
{
return build(builder, statProc);
}
- public Pathable<CompletionStage<Stat>> safeStat(BackgroundPathable<Stat> builder)
+ public CrimpedPathable<CompletionStage<Stat>> safeStat(BackgroundPathable<Stat> builder)
{
return build(builder, safeStatProc);
}
- public Pathable<Crimped<Stat>> statWatched(Watchable<BackgroundPathable<Stat>> builder)
+ public CrimpedPathable<Crimped<Stat>> statWatched(Watchable<BackgroundPathable<Stat>> builder)
{
return build(builder, statProc);
}
- public Pathable<Crimped<Stat>> safeStatWatched(Watchable<BackgroundPathable<Stat>> builder)
+ public CrimpedPathable<Crimped<Stat>> safeStatWatched(Watchable<BackgroundPathable<Stat>> builder)
{
return build(builder, safeStatProc);
}
- public Pathable<CompletionStage<List<ACL>>> acls(BackgroundPathable<List<ACL>> builder)
+ public CrimpedPathable<CompletionStage<List<ACL>>> acls(BackgroundPathable<List<ACL>> builder)
{
return build(builder, aclProc);
}
- public PathAndBytesable<CompletionStage<Stat>> statBytes(BackgroundPathAndBytesable<Stat> builder)
+ public CrimpledPathAndBytesable<CompletionStage<Stat>> statBytes(BackgroundPathAndBytesable<Stat> builder)
{
return build(builder, statProc);
}
@@ -208,66 +208,46 @@ public class AsyncCrimps
ErrorListenerMultiTransactionMain main = builder.inBackground(callback);
CuratorMultiTransactionMain finalBuilder = (unhandledErrorListener != null) ? main.withUnhandledErrorListener(unhandledErrorListener) : main;
return ops -> {
- finalBuilder.forOperations(ops);
+ try
+ {
+ finalBuilder.forOperations(ops);
+ }
+ catch ( Exception e )
+ {
+ callback.completeExceptionally(e);
+ }
return callback;
};
}
- public <T> PathAndBytesable<CompletionStage<T>> build(BackgroundPathAndBytesable<T> builder, BackgroundProc<T> backgroundProc)
+ public <T> CrimpledPathAndBytesable<CompletionStage<T>> build(BackgroundPathAndBytesable<T> builder, BackgroundProc<T> backgroundProc)
{
CrimpedBackgroundCallback<T> callback = new CrimpedBackgroundCallback<T>(backgroundProc);
ErrorListenerPathAndBytesable<T> localBuilder = builder.inBackground(callback);
PathAndBytesable<T> finalLocalBuilder = (unhandledErrorListener != null) ? localBuilder.withUnhandledErrorListener(unhandledErrorListener) : localBuilder;
- return new PathAndBytesable<CompletionStage<T>>()
- {
- @Override
- public CompletionStage<T> forPath(String path) throws Exception
- {
- finalLocalBuilder.forPath(path);
- return callback;
- }
-
- @Override
- public CompletionStage<T> forPath(String path, byte[] data) throws Exception
- {
- finalLocalBuilder.forPath(path, data);
- return callback;
- }
- };
+ return new CrimpledPathAndBytesableImpl<>(finalLocalBuilder, callback, null);
}
- public <T> Pathable<Crimped<T>> build(Watchable<BackgroundPathable<T>> builder, BackgroundProc<T> backgroundProc)
+ public <T> CrimpedPathable<Crimped<T>> build(Watchable<BackgroundPathable<T>> builder, BackgroundProc<T> backgroundProc)
{
CrimpedWatcher crimpedWatcher = new CrimpedWatcher();
- CrimpedBackgroundCallback<T> callback = new CrimpedBackgroundCallback<T>(backgroundProc);
- Pathable<T> finalLocalBuilder = toFinalBuilder(callback, builder.usingWatcher(crimpedWatcher));
- return path -> {
- finalLocalBuilder.forPath(path);
- return new Crimped<T>()
+ CrimpedBackgroundCallback<T> callback = new CrimpedBackgroundCallback<T>(backgroundProc)
+ {
+ @Override
+ public CompletionStage<WatchedEvent> event()
{
- @Override
- public CompletionStage<WatchedEvent> event()
- {
- return crimpedWatcher;
- }
-
- @Override
- public CompletionStage<T> value()
- {
- return callback;
- }
- };
+ return crimpedWatcher;
+ }
};
+ Pathable<T> finalLocalBuilder = toFinalBuilder(callback, builder.usingWatcher(crimpedWatcher));
+ return new CrimpledPathAndBytesableImpl<T, Crimped<T>>(finalLocalBuilder, callback, crimpedWatcher);
}
- public <T> Pathable<CompletionStage<T>> build(BackgroundPathable<T> builder, BackgroundProc<T> backgroundProc)
+ public <T> CrimpedPathable<CompletionStage<T>> build(BackgroundPathable<T> builder, BackgroundProc<T> backgroundProc)
{
CrimpedBackgroundCallback<T> callback = new CrimpedBackgroundCallback<T>(backgroundProc);
Pathable<T> finalLocalBuilder = toFinalBuilder(callback, builder);
- return path -> {
- finalLocalBuilder.forPath(path);
- return callback;
- };
+ return new CrimpledPathAndBytesableImpl<>(finalLocalBuilder, callback, null);
}
private <T> Pathable<T> toFinalBuilder(CrimpedBackgroundCallback<T> callback, BackgroundPathable<T> backgroundPathable)
http://git-wip-us.apache.org/repos/asf/curator/blob/81f0ab26/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/Crimped.java
----------------------------------------------------------------------
diff --git a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/Crimped.java b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/Crimped.java
index 26e300a..dc69019 100644
--- a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/Crimped.java
+++ b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/Crimped.java
@@ -21,9 +21,7 @@ package org.apache.curator.x.crimps.async;
import org.apache.zookeeper.WatchedEvent;
import java.util.concurrent.CompletionStage;
-public interface Crimped<T>
+public interface Crimped<T> extends CompletionStage<T>
{
CompletionStage<WatchedEvent> event();
-
- CompletionStage<T> value();
}
http://git-wip-us.apache.org/repos/asf/curator/blob/81f0ab26/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedBackgroundCallback.java
----------------------------------------------------------------------
diff --git a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedBackgroundCallback.java b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedBackgroundCallback.java
index 5fad73a..b3c20d2 100644
--- a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedBackgroundCallback.java
+++ b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedBackgroundCallback.java
@@ -21,9 +21,11 @@ package org.apache.curator.x.crimps.async;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.api.BackgroundCallback;
import org.apache.curator.framework.api.CuratorEvent;
+import org.apache.zookeeper.WatchedEvent;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
-class CrimpedBackgroundCallback<T> extends CompletableFuture<T> implements BackgroundCallback
+class CrimpedBackgroundCallback<T> extends CompletableFuture<T> implements BackgroundCallback, Crimped<T>
{
private final BackgroundProc<T> resultFunction;
@@ -33,6 +35,12 @@ class CrimpedBackgroundCallback<T> extends CompletableFuture<T> implements Backg
}
@Override
+ public CompletionStage<WatchedEvent> event()
+ {
+ return null;
+ }
+
+ @Override
public void processResult(CuratorFramework client, CuratorEvent event) throws Exception
{
resultFunction.apply(event, this);
http://git-wip-us.apache.org/repos/asf/curator/blob/81f0ab26/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedConfigEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedConfigEnsembleable.java b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedConfigEnsembleable.java
index 9021daf..10c0c35 100644
--- a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedConfigEnsembleable.java
+++ b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedConfigEnsembleable.java
@@ -22,12 +22,12 @@ import org.apache.curator.framework.api.Ensembleable;
import java.util.concurrent.CompletionStage;
public interface CrimpedConfigEnsembleable extends
- Ensembleable<CompletionStage<byte[]>>
+ CrimpledEnsembleable<CompletionStage<byte[]>>
{
/**
* Sets the configuration version to use.
* @param config The version of the configuration.
- * @throws Exception errors
+ * @return this
*/
- Ensembleable<CompletionStage<byte[]>> fromConfig(long config) throws Exception;
+ CrimpledEnsembleable<CompletionStage<byte[]>> fromConfig(long config);
}
http://git-wip-us.apache.org/repos/asf/curator/blob/81f0ab26/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedEnsembleable.java b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedEnsembleable.java
index 3069e39..c8166e7 100644
--- a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedEnsembleable.java
+++ b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedEnsembleable.java
@@ -18,13 +18,12 @@
*/
package org.apache.curator.x.crimps.async;
-import org.apache.curator.framework.api.Ensembleable;
import org.apache.curator.framework.api.Statable;
import java.util.concurrent.CompletionStage;
public interface CrimpedEnsembleable extends
CrimpedConfigEnsembleable,
Statable<CrimpedConfigEnsembleable>,
- Ensembleable<CompletionStage<byte[]>>
+ CrimpledEnsembleable<CompletionStage<byte[]>>
{
}
http://git-wip-us.apache.org/repos/asf/curator/blob/81f0ab26/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedEnsembleableImpl.java
----------------------------------------------------------------------
diff --git a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedEnsembleableImpl.java b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedEnsembleableImpl.java
index 035e9bf..d94d242 100644
--- a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedEnsembleableImpl.java
+++ b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedEnsembleableImpl.java
@@ -48,9 +48,16 @@ class CrimpedEnsembleableImpl implements CrimpedEnsembleable
}
@Override
- public CompletionStage<byte[]> forEnsemble() throws Exception
+ public CompletionStage<byte[]> forEnsemble()
{
- ensembleable.forEnsemble();
+ try
+ {
+ ensembleable.forEnsemble();
+ }
+ catch ( Exception e )
+ {
+ callback.completeExceptionally(e);
+ }
return callback;
}
@@ -62,9 +69,16 @@ class CrimpedEnsembleableImpl implements CrimpedEnsembleable
}
@Override
- public Ensembleable<CompletionStage<byte[]>> fromConfig(long config) throws Exception
+ public CrimpledEnsembleable<CompletionStage<byte[]>> fromConfig(long config)
{
- ensembleable = configureEnsembleable.fromConfig(config);
+ try
+ {
+ ensembleable = configureEnsembleable.fromConfig(config);
+ }
+ catch ( Exception e )
+ {
+ callback.completeExceptionally(e);
+ }
return this;
}
}
http://git-wip-us.apache.org/repos/asf/curator/blob/81f0ab26/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedMultiTransaction.java
----------------------------------------------------------------------
diff --git a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedMultiTransaction.java b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedMultiTransaction.java
index b010624..fdba7b8 100644
--- a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedMultiTransaction.java
+++ b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedMultiTransaction.java
@@ -32,7 +32,6 @@ public interface CrimpedMultiTransaction
*
* @param operations operations that make up the transaction.
* @return result details for foreground operations or <code>null</code> for background operations
- * @throws Exception errors
*/
- CompletionStage<List<CuratorTransactionResult>> forOperations(List<CuratorOp> operations) throws Exception;
+ CompletionStage<List<CuratorTransactionResult>> forOperations(List<CuratorOp> operations);
}
http://git-wip-us.apache.org/repos/asf/curator/blob/81f0ab26/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedPathable.java
----------------------------------------------------------------------
diff --git a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedPathable.java b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedPathable.java
new file mode 100644
index 0000000..300b695
--- /dev/null
+++ b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedPathable.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.crimps.async;
+
+public interface CrimpedPathable<T>
+{
+ /**
+ * Commit the currently building operation using the given path
+ *
+ * @param path the path
+ * @return result
+ */
+ T forPath(String path);
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/81f0ab26/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpledEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpledEnsembleable.java b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpledEnsembleable.java
new file mode 100644
index 0000000..f23349e
--- /dev/null
+++ b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpledEnsembleable.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.crimps.async;
+
+public interface CrimpledEnsembleable<T> {
+
+ T forEnsemble();
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/81f0ab26/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpledPathAndBytesable.java
----------------------------------------------------------------------
diff --git a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpledPathAndBytesable.java b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpledPathAndBytesable.java
new file mode 100644
index 0000000..5e03815
--- /dev/null
+++ b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpledPathAndBytesable.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.x.crimps.async;
+
+public interface CrimpledPathAndBytesable<T> extends CrimpedPathable<T>
+{
+ /**
+ * Commit the currently building operation using the given path and data
+ *
+ * @param path the path
+ * @param data the data
+ * @return result
+ */
+ T forPath(String path, byte[] data);
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/81f0ab26/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpledPathAndBytesableImpl.java
----------------------------------------------------------------------
diff --git a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpledPathAndBytesableImpl.java b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpledPathAndBytesableImpl.java
new file mode 100644
index 0000000..329de64
--- /dev/null
+++ b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpledPathAndBytesableImpl.java
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.crimps.async;
+
+import org.apache.curator.framework.api.PathAndBytesable;
+import org.apache.curator.framework.api.Pathable;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
+
+class CrimpledPathAndBytesableImpl<MAIN, RESULT extends CompletionStage<MAIN>> implements CrimpledPathAndBytesable<RESULT>
+{
+ private final Pathable<MAIN> pathable;
+ private final PathAndBytesable<MAIN> pathAndBytesable;
+ private final RESULT result;
+ private final CompletableFuture second;
+
+ CrimpledPathAndBytesableImpl(Pathable<MAIN> pathable, RESULT result, CompletableFuture second)
+ {
+ this.result = result;
+ this.second = second;
+ this.pathAndBytesable = null;
+ this.pathable = pathable;
+ }
+
+ CrimpledPathAndBytesableImpl(PathAndBytesable<MAIN> pathAndBytesable, RESULT result, CompletableFuture second)
+ {
+ this.pathAndBytesable = pathAndBytesable;
+ this.result = result;
+ this.second = second;
+ this.pathable = null;
+ }
+
+ @Override
+ public RESULT forPath(String path)
+ {
+ try
+ {
+ if ( pathable != null )
+ {
+ pathable.forPath(path);
+ }
+ else
+ {
+ pathAndBytesable.forPath(path);
+ }
+ }
+ catch ( Exception e )
+ {
+ setException(e);
+ }
+ return result;
+ }
+
+ @Override
+ public RESULT forPath(String path, byte[] data)
+ {
+ try
+ {
+ pathAndBytesable.forPath(path, data);
+ }
+ catch ( Exception e )
+ {
+ setException(e);
+ }
+ return result;
+ }
+
+ private void setException(Exception e)
+ {
+ result.toCompletableFuture().completeExceptionally(e);
+ if ( second != null )
+ {
+ second.completeExceptionally(e);
+ }
+ }
+}