X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatabroker%2Factors%2Fdds%2FAbstractShardBackendResolver.java;h=faffe0a3764985f5439e13867928a1ee2a1f2511;hp=46e035d0ec63ec025d0b78d1260cf519ffc51a15;hb=a6af137c30470b86d4bc624d4c48cb686495a182;hpb=b712eb01354ddb5878008e2a2e8f03fb19b92555 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractShardBackendResolver.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractShardBackendResolver.java index 46e035d0ec..faffe0a376 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractShardBackendResolver.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractShardBackendResolver.java @@ -65,9 +65,9 @@ abstract class AbstractShardBackendResolver extends BackendInfoResolver { - if (failure != null) { - LOG.debug("Connect attempt to {} failed, will retry", shardName, failure); - future.completeExceptionally(wrap("Connection attempt failed", failure)); - return; - } - if (response instanceof RequestFailure) { - final Throwable cause = ((RequestFailure) response).getCause().unwrap(); - LOG.debug("Connect attempt to {} failed to process", shardName, cause); - final Throwable result = cause instanceof NotLeaderException - ? wrap("Leader moved during establishment", cause) : cause; - future.completeExceptionally(result); - return; - } - - LOG.debug("Resolved backend information to {}", response); - Preconditions.checkArgument(response instanceof ConnectClientSuccess, "Unhandled response %s", - response); - final ConnectClientSuccess success = (ConnectClientSuccess) response; - future.complete(new ShardBackendInfo(success.getBackend(), nextSessionId.getAndIncrement(), - success.getVersion(), shardName, UnsignedLong.fromLongBits(cookie), success.getDataTree(), - success.getMaxMessages())); - }); + .whenComplete((response, failure) -> onConnectResponse(shardName, cookie, future, response, failure)); + } + + private void onConnectResponse(final String shardName, final long cookie, + final CompletableFuture future, final Object response, final Throwable failure) { + if (failure != null) { + LOG.debug("Connect attempt to {} failed, will retry", shardName, failure); + future.completeExceptionally(wrap("Connection attempt failed", failure)); + return; + } + if (response instanceof RequestFailure) { + final Throwable cause = ((RequestFailure) response).getCause().unwrap(); + LOG.debug("Connect attempt to {} failed to process", shardName, cause); + final Throwable result = cause instanceof NotLeaderException + ? wrap("Leader moved during establishment", cause) : cause; + future.completeExceptionally(result); + return; + } + + LOG.debug("Resolved backend information to {}", response); + Preconditions.checkArgument(response instanceof ConnectClientSuccess, "Unhandled response %s", + response); + final ConnectClientSuccess success = (ConnectClientSuccess) response; + future.complete(new ShardBackendInfo(success.getBackend(), nextSessionId.getAndIncrement(), + success.getVersion(), shardName, UnsignedLong.fromLongBits(cookie), success.getDataTree(), + success.getMaxMessages())); } }