* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.controller.cluster.sharding;
+import static java.util.Objects.requireNonNull;
+
import akka.actor.ActorRef;
import akka.actor.ActorSelection;
import akka.actor.ActorSystem;
import akka.dispatch.OnComplete;
import akka.pattern.Patterns;
import akka.util.Timeout;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import org.opendaylight.controller.cluster.access.concepts.MemberName;
import org.opendaylight.controller.cluster.datastore.AbstractDataStore;
import org.opendaylight.controller.cluster.datastore.ClusterWrapper;
import org.opendaylight.controller.cluster.datastore.config.PrefixShardConfiguration;
-import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
+import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
import org.opendaylight.controller.cluster.datastore.utils.ClusterUtils;
import org.opendaylight.controller.cluster.raft.client.messages.FindLeader;
import org.opendaylight.controller.cluster.raft.client.messages.FindLeaderReply;
private final ClusterWrapper clusterWrapper;
// helper actorContext used only for static calls to executeAsync etc
// for calls that need specific actor context tied to a datastore use the one provided in the DistributedDataStore
- private final ActorContext actorContext;
+ private final ActorUtils actorUtils;
private final ShardingServiceAddressResolver resolver;
private final AbstractDataStore distributedConfigDatastore;
private final AbstractDataStore distributedOperDatastore;
distributedConfigDatastore = builder.getDistributedConfigDatastore();
distributedOperDatastore = builder.getDistributedOperDatastore();
lookupTaskMaxRetries = builder.getLookupTaskMaxRetries();
- actorContext = distributedConfigDatastore.getActorContext();
+ actorUtils = distributedConfigDatastore.getActorUtils();
resolver = new ShardingServiceAddressResolver(
DistributedShardedDOMDataTree.ACTOR_ID, clusterWrapper.getCurrentMemberName());
final ActorSelection actorSelection = actorSystem.actorSelection(address);
futures.add(
FutureConverters.toJava(
- actorContext.executeOperationAsync(
+ actorUtils.executeOperationAsync(
actorSelection, new NotifyProducerCreated(subtrees), DEFAULT_ASK_TIMEOUT))
.toCompletableFuture());
}
final ActorSelection selection = actorSystem.actorSelection(address);
futures.add(FutureConverters.toJava(
- actorContext.executeOperationAsync(selection, new NotifyProducerRemoved(message.getSubtrees())))
+ actorUtils.executeOperationAsync(selection, new NotifyProducerRemoved(message.getSubtrees())))
.toCompletableFuture());
}
final DOMDataTreeIdentifier prefix = message.getPrefix();
- final ActorContext context = prefix.getDatastoreType() == LogicalDatastoreType.CONFIGURATION
- ? distributedConfigDatastore.getActorContext() : distributedOperDatastore.getActorContext();
+ final ActorUtils utils = prefix.getDatastoreType() == LogicalDatastoreType.CONFIGURATION
+ ? distributedConfigDatastore.getActorUtils() : distributedOperDatastore.getActorUtils();
// schedule a notification task for the reply
actorSystem.scheduler().scheduleOnce(SHARD_LOOKUP_TASK_INTERVAL,
new ShardCreationLookupTask(actorSystem, getSender(), clusterWrapper,
- context, shardingService, prefix, lookupTaskMaxRetries), actorSystem.dispatcher());
+ utils, shardingService, prefix, lookupTaskMaxRetries), actorSystem.dispatcher());
}
private void onPrefixShardCreated(final PrefixShardCreated message) {
final ShardRemovalLookupTask removalTask =
new ShardRemovalLookupTask(actorSystem, getSender(),
- actorContext, message.getPrefix(), lookupTaskMaxRetries);
+ actorUtils, message.getPrefix(), lookupTaskMaxRetries);
actorSystem.scheduler().scheduleOnce(SHARD_LOOKUP_TASK_INTERVAL, removalTask, actorSystem.dispatcher());
}
private void onStartConfigShardLookup(final StartConfigShardLookup message) {
LOG.debug("Received StartConfigShardLookup: {}", message);
- final ActorContext context =
+ final ActorUtils context =
message.getType().equals(LogicalDatastoreType.CONFIGURATION)
- ? distributedConfigDatastore.getActorContext() : distributedOperDatastore.getActorContext();
+ ? distributedConfigDatastore.getActorUtils() : distributedOperDatastore.getActorUtils();
// schedule a notification task for the reply
actorSystem.scheduler().scheduleOnce(SHARD_LOOKUP_TASK_INTERVAL,
private final ActorSystem system;
private final ActorRef replyTo;
private final ClusterWrapper clusterWrapper;
- private final ActorContext context;
+ private final ActorUtils context;
private final DistributedShardedDOMDataTree shardingService;
private final DOMDataTreeIdentifier toLookup;
private final int lookupMaxRetries;
ShardCreationLookupTask(final ActorSystem system,
final ActorRef replyTo,
final ClusterWrapper clusterWrapper,
- final ActorContext context,
+ final ActorUtils context,
final DistributedShardedDOMDataTree shardingService,
final DOMDataTreeIdentifier toLookup,
final int lookupMaxRetries) {
localShardFuture.onComplete(new OnComplete<ActorRef>() {
@Override
- public void onComplete(Throwable throwable, ActorRef actorRef) {
+ public void onComplete(final Throwable throwable, final ActorRef actorRef) {
if (throwable != null) {
tryReschedule(throwable);
} else {
}
@Override
- void reschedule(int retries) {
+ void reschedule(final int retries) {
LOG.debug("Local backend for shard[{}] not found, try: {}, rescheduling..", toLookup, retries);
system.scheduler().scheduleOnce(
SHARD_LOOKUP_TASK_INTERVAL, ShardCreationLookupTask.this, system.dispatcher());
private final ActorSystem system;
private final ActorRef replyTo;
- private final ActorContext context;
+ private final ActorUtils context;
private final ClusterWrapper clusterWrapper;
private final ActorRef shard;
private final DistributedShardedDOMDataTree shardingService;
ShardLeaderLookupTask(final ActorSystem system,
final ActorRef replyTo,
- final ActorContext context,
+ final ActorUtils context,
final ClusterWrapper clusterWrapper,
final ActorRef shard,
final DistributedShardedDOMDataTree shardingService,
tryReschedule(throwable);
} else {
final FindLeaderReply findLeader = (FindLeaderReply) findLeaderReply;
- final java.util.Optional<String> leaderActor = findLeader.getLeaderActor();
+ final Optional<String> leaderActor = findLeader.getLeaderActor();
if (leaderActor.isPresent()) {
// leader is found, backend seems ready, check if the frontend is ready
LOG.debug("{} - Leader for shard[{}] backend ready, starting frontend lookup..",
}
@Override
- void reschedule(int retries) {
+ void reschedule(final int retries) {
LOG.debug("{} - Leader for shard[{}] backend not found on try: {}, retrying..",
clusterWrapper.getCurrentMemberName(), toLookup, retries);
system.scheduler().scheduleOnce(
return false;
}
- if (YangInstanceIdentifier.EMPTY.equals(prefix.getRootIdentifier())) {
+ if (YangInstanceIdentifier.empty().equals(prefix.getRootIdentifier())) {
return true;
}
}
@Override
- void reschedule(int retries) {
+ void reschedule(final int retries) {
LOG.debug("Frontend for shard[{}] not found on try: {}, retrying..", toLookup, retries);
system.scheduler().scheduleOnce(
SHARD_LOOKUP_TASK_INTERVAL, FrontendLookupTask.this, system.dispatcher());
private final ActorSystem system;
private final ActorRef replyTo;
- private final ActorContext context;
+ private final ActorUtils context;
private final DOMDataTreeIdentifier toLookup;
ShardRemovalLookupTask(final ActorSystem system,
final ActorRef replyTo,
- final ActorContext context,
+ final ActorUtils context,
final DOMDataTreeIdentifier toLookup,
final int lookupMaxRetries) {
super(replyTo, lookupMaxRetries);
localShardFuture.onComplete(new OnComplete<ActorRef>() {
@Override
- public void onComplete(Throwable throwable, ActorRef actorRef) {
+ public void onComplete(final Throwable throwable, final ActorRef actorRef) {
if (throwable != null) {
//TODO Shouldn't we check why findLocalShard failed?
LOG.debug("Backend shard[{}] removal lookup successful notifying the registration future",
}
@Override
- void reschedule(int retries) {
+ void reschedule(final int retries) {
LOG.debug("Backend shard[{}] removal lookup failed, shard is still present, try: {}, rescheduling..",
toLookup, retries);
system.scheduler().scheduleOnce(
private final ActorSystem system;
private final ActorRef replyTo;
- private final ActorContext context;
+ private final ActorUtils context;
ConfigShardLookupTask(final ActorSystem system,
final ActorRef replyTo,
- final ActorContext context,
+ final ActorUtils context,
final StartConfigShardLookup message,
final int lookupMaxRetries) {
super(replyTo, lookupMaxRetries);
}
@Override
- void reschedule(int retries) {
+ void reschedule(final int retries) {
LOG.debug("Local backend for prefix configuration shard not found, try: {}, rescheduling..", retries);
system.scheduler().scheduleOnce(
SHARD_LOOKUP_TASK_INTERVAL, ConfigShardLookupTask.this, system.dispatcher());
private final ActorSystem system;
private final ActorRef replyTo;
- private final ActorContext context;
+ private final ActorUtils context;
private final ClusterWrapper clusterWrapper;
private final ActorRef shard;
ConfigShardReadinessTask(final ActorSystem system,
final ActorRef replyTo,
- final ActorContext context,
+ final ActorUtils context,
final ClusterWrapper clusterWrapper,
final ActorRef shard,
final int lookupMaxRetries) {
}
@Override
- void reschedule(int retries) {
+ void reschedule(final int retries) {
LOG.debug("{} - Leader for config shard not found on try: {}, retrying..",
clusterWrapper.getCurrentMemberName(), retries);
system.scheduler().scheduleOnce(
tryReschedule(throwable);
} else {
final FindLeaderReply findLeader = (FindLeaderReply) findLeaderReply;
- final java.util.Optional<String> leaderActor = findLeader.getLeaderActor();
+ final Optional<String> leaderActor = findLeader.getLeaderActor();
if (leaderActor.isPresent()) {
// leader is found, backend seems ready, check if the frontend is ready
LOG.debug("{} - Leader for config shard is ready. Ending lookup.",
}
private void verify() {
- Preconditions.checkNotNull(shardingService);
- Preconditions.checkNotNull(actorSystem);
- Preconditions.checkNotNull(cluster);
- Preconditions.checkNotNull(distributedConfigDatastore);
- Preconditions.checkNotNull(distributedOperDatastore);
+ requireNonNull(shardingService);
+ requireNonNull(actorSystem);
+ requireNonNull(cluster);
+ requireNonNull(distributedConfigDatastore);
+ requireNonNull(distributedOperDatastore);
}
public Props props() {