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%2Fdatastore%2FCompositeDataTreeCohort.java;h=8115473a0565fb2c3865f4bc03e7216a8029a579;hp=d833962277d9a1c3ee1785c2147737740649b6f5;hb=a47dd7a5d21ca68804a6d0e2e3ca765f223c2ef4;hpb=4d1709660b7af992d4c382a2a38debb5c7d64fb9 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CompositeDataTreeCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CompositeDataTreeCohort.java index d833962277..8115473a05 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CompositeDataTreeCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CompositeDataTreeCohort.java @@ -21,12 +21,13 @@ import com.google.common.base.Throwables; import com.google.common.collect.Iterables; import java.util.Collection; import java.util.Iterator; +import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit; import org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Success; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import scala.concurrent.Await; import scala.concurrent.Future; @@ -85,7 +86,7 @@ class CompositeDataTreeCohort { protected static final Recover EXCEPTION_TO_MESSAGE = new Recover() { @Override - public Failure recover(Throwable error) throws Throwable { + public Failure recover(final Throwable error) throws Throwable { return new Failure(error); } }; @@ -98,21 +99,21 @@ class CompositeDataTreeCohort { private Iterable successfulFromPrevious; private State state = State.IDLE; - CompositeDataTreeCohort(DataTreeCohortActorRegistry registry, TransactionIdentifier transactionID, - SchemaContext schema, Timeout timeout) { + CompositeDataTreeCohort(final DataTreeCohortActorRegistry registry, final TransactionIdentifier transactionID, + final SchemaContext schema, final Timeout timeout) { this.registry = Preconditions.checkNotNull(registry); this.txId = Preconditions.checkNotNull(transactionID); this.schema = Preconditions.checkNotNull(schema); this.timeout = Preconditions.checkNotNull(timeout); } - void canCommit(DataTreeCandidateTip tip) throws ExecutionException, TimeoutException { + void canCommit(final DataTreeCandidate tip) throws ExecutionException, TimeoutException { Collection messages = registry.createCanCommitMessages(txId, tip, schema); // FIXME: Optimize empty collection list with pre-created futures, containing success. Future> canCommitsFuture = Futures.traverse(messages, new Function>() { @Override - public Future apply(CanCommit input) { + public Future apply(final CanCommit input) { return Patterns.ask(input.getCohort(), input, timeout).recover(EXCEPTION_TO_MESSAGE, ExecutionContexts.global()); } @@ -135,24 +136,26 @@ class CompositeDataTreeCohort { processResponses(commitsFuture, State.COMMIT_SENT, State.COMMITED); } - void abort() throws TimeoutException { + Optional>> abort() { if (successfulFromPrevious != null) { - sendMesageToSuccessful(new DataTreeCohortActor.Abort(txId)); + return Optional.of(sendMesageToSuccessful(new DataTreeCohortActor.Abort(txId))); } + + return Optional.empty(); } private Future> sendMesageToSuccessful(final Object message) { return Futures.traverse(successfulFromPrevious, new Function>() { @Override - public Future apply(DataTreeCohortActor.Success cohortResponse) throws Exception { + public Future apply(final DataTreeCohortActor.Success cohortResponse) throws Exception { return Patterns.ask(cohortResponse.getCohort(), message, timeout); } }, ExecutionContexts.global()); } - private void processResponses(Future> resultsFuture, State currentState, State afterState) + private void processResponses(final Future> resultsFuture, final State currentState, final State afterState) throws TimeoutException, ExecutionException { final Iterable results; try { @@ -179,7 +182,7 @@ class CompositeDataTreeCohort { changeStateFrom(currentState, afterState); } - void changeStateFrom(State expected, State followup) { + void changeStateFrom(final State expected, final State followup) { Preconditions.checkState(state == expected); state = followup; }