Search in sources :

Example 1 with Success

use of org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Success in project controller by opendaylight.

the class DataTreeCohortActorTest method askAndAwait.

private static void askAndAwait(ActorRef actor, CommitProtocolCommand<?> message) throws Exception {
    Timeout timeout = new Timeout(5, TimeUnit.SECONDS);
    Object result = Await.result(Patterns.ask(actor, message, timeout), timeout.duration());
    assertTrue("Expected Success but was " + result, result instanceof Success);
    assertEquals("Success", message.getTxId(), ((Success) result).getTxId());
}
Also used : Timeout(akka.util.Timeout) Success(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Success)

Example 2 with Success

use of org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Success in project controller by opendaylight.

the class CompositeDataTreeCohort method sendMessageToSuccessful.

private List<Entry<ActorRef, Future<Object>>> sendMessageToSuccessful(final Object message) {
    LOG.debug("{}: sendMesageToSuccessful: {}", txId, message);
    final List<Entry<ActorRef, Future<Object>>> ret = new ArrayList<>(successfulFromPrevious.size());
    for (Success s : successfulFromPrevious) {
        final ActorRef actor = s.getCohort();
        ret.add(new SimpleImmutableEntry<>(actor, Patterns.ask(actor, message, timeout)));
    }
    return ret;
}
Also used : SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) Entry(java.util.Map.Entry) ActorRef(akka.actor.ActorRef) ArrayList(java.util.ArrayList) Success(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Success)

Example 3 with Success

use of org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Success in project controller by opendaylight.

the class CompositeDataTreeCohort method abort.

Optional<CompletionStage<?>> abort() {
    LOG.debug("{}: abort - successfulFromPrevious: {}", txId, successfulFromPrevious);
    state = State.ABORTED;
    if (successfulFromPrevious.isEmpty()) {
        return Optional.empty();
    }
    final DataTreeCohortActor.Abort message = new DataTreeCohortActor.Abort(txId);
    final List<Future<Object>> futures = new ArrayList<>(successfulFromPrevious.size());
    for (Success s : successfulFromPrevious) {
        futures.add(Patterns.ask(s.getCohort(), message, timeout));
    }
    return Optional.of(FutureConverters.toJava(Futures.sequence(futures, ExecutionContexts.global())));
}
Also used : ArrayList(java.util.ArrayList) CompletableFuture(java.util.concurrent.CompletableFuture) Future(scala.concurrent.Future) Success(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Success)

Aggregations

Success (org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Success)3 ArrayList (java.util.ArrayList)2 ActorRef (akka.actor.ActorRef)1 Timeout (akka.util.Timeout)1 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)1 Entry (java.util.Map.Entry)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Future (scala.concurrent.Future)1