Search in sources :

Example 1 with NotifyProducerCreated

use of org.opendaylight.controller.cluster.sharding.messages.NotifyProducerCreated in project controller by opendaylight.

the class ShardedDataTreeActor method onProducerCreated.

private void onProducerCreated(final ProducerCreated message) {
    LOG.debug("Received ProducerCreated: {}", message);
    // fastpath if we have no peers
    if (resolver.getShardingServicePeerActorAddresses().isEmpty()) {
        getSender().tell(new Status.Success(null), noSender());
    }
    final ActorRef sender = getSender();
    final Collection<DOMDataTreeIdentifier> subtrees = message.getSubtrees();
    final List<CompletableFuture<Object>> futures = new ArrayList<>();
    for (final String address : resolver.getShardingServicePeerActorAddresses()) {
        final ActorSelection actorSelection = actorSystem.actorSelection(address);
        futures.add(FutureConverters.toJava(actorContext.executeOperationAsync(actorSelection, new NotifyProducerCreated(subtrees), DEFAULT_ASK_TIMEOUT)).toCompletableFuture());
    }
    final CompletableFuture<Void> combinedFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()]));
    combinedFuture.thenRun(() -> sender.tell(new Success(null), noSender())).exceptionally(throwable -> {
        sender.tell(new Status.Failure(throwable), self());
        return null;
    });
}
Also used : Status(akka.actor.Status) ActorRef(akka.actor.ActorRef) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) ArrayList(java.util.ArrayList) Success(akka.actor.Status.Success) Success(akka.actor.Status.Success) CompletableFuture(java.util.concurrent.CompletableFuture) ActorSelection(akka.actor.ActorSelection) NotifyProducerCreated(org.opendaylight.controller.cluster.sharding.messages.NotifyProducerCreated)

Aggregations

ActorRef (akka.actor.ActorRef)1 ActorSelection (akka.actor.ActorSelection)1 Status (akka.actor.Status)1 Success (akka.actor.Status.Success)1 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 NotifyProducerCreated (org.opendaylight.controller.cluster.sharding.messages.NotifyProducerCreated)1 DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)1