Search in sources :

Example 1 with CompositeOnComplete

use of org.opendaylight.controller.cluster.datastore.utils.CompositeOnComplete in project controller by opendaylight.

the class ShardManager method removeShard.

@SuppressWarnings("checkstyle:IllegalCatch")
private void removeShard(final ShardIdentifier shardId) {
    final String shardName = shardId.getShardName();
    final ShardInformation shardInformation = localShards.remove(shardName);
    if (shardInformation == null) {
        LOG.debug("{} : Shard replica {} is not present in list", persistenceId(), shardId.toString());
        return;
    }
    final ActorRef shardActor = shardInformation.getActor();
    if (shardActor != null) {
        long timeoutInMS = Math.max(shardInformation.getDatastoreContext().getShardRaftConfig().getElectionTimeOutInterval().$times(3).toMillis(), 10000);
        LOG.debug("{} : Sending Shutdown to Shard actor {} with {} ms timeout", persistenceId(), shardActor, timeoutInMS);
        final Future<Boolean> stopFuture = Patterns.gracefulStop(shardActor, FiniteDuration.apply(timeoutInMS, TimeUnit.MILLISECONDS), Shutdown.INSTANCE);
        final CompositeOnComplete<Boolean> onComplete = new CompositeOnComplete<Boolean>() {

            @Override
            public void onComplete(final Throwable failure, final Boolean result) {
                if (failure == null) {
                    LOG.debug("{} : Successfully shut down Shard actor {}", persistenceId(), shardActor);
                } else {
                    LOG.warn("{}: Failed to shut down Shard actor {}", persistenceId(), shardActor, failure);
                }
                self().tell((RunnableMessage) () -> {
                    // At any rate, invalidate primaryShardInfo cache
                    primaryShardInfoCache.remove(shardName);
                    shardActorsStopping.remove(shardName);
                    notifyOnCompleteTasks(failure, result);
                }, ActorRef.noSender());
            }
        };
        shardActorsStopping.put(shardName, onComplete);
        stopFuture.onComplete(onComplete, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
    }
    LOG.debug("{} : Local Shard replica for shard {} has been removed", persistenceId(), shardName);
    persistShardList();
}
Also used : CompositeOnComplete(org.opendaylight.controller.cluster.datastore.utils.CompositeOnComplete) ActorRef(akka.actor.ActorRef) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Aggregations

ActorRef (akka.actor.ActorRef)1 Dispatchers (org.opendaylight.controller.cluster.common.actor.Dispatchers)1 CompositeOnComplete (org.opendaylight.controller.cluster.datastore.utils.CompositeOnComplete)1