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%2FLeaderLocalDelegateFactory.java;h=0f766295409c73e0305f6d45dd3fbc2df605afce;hp=891c0bf6d426c5a65690e55772bb8d82c9f8c0b3;hb=ef3b9a8300db1c791f2c4088d39152ccf9f5b97c;hpb=66d39ecc3effd52c96c7a772a46612008e34fbc9 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderLocalDelegateFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderLocalDelegateFactory.java index 891c0bf6d4..0f76629540 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderLocalDelegateFactory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderLocalDelegateFactory.java @@ -7,20 +7,62 @@ */ package org.opendaylight.controller.cluster.datastore; +import akka.actor.ActorPath; +import akka.actor.ActorRef; +import akka.actor.ActorSelection; +import akka.actor.Props; +import com.google.common.base.Preconditions; + /** * Base class for factories instantiating delegates which are local to the * shard leader. * - * delegate type - * message type + * @param delegate type + * @param message type */ abstract class LeaderLocalDelegateFactory extends DelegateFactory { + private final Shard shard; + + protected LeaderLocalDelegateFactory(final Shard shard) { + this.shard = Preconditions.checkNotNull(shard); + } + + protected final ActorRef getSelf() { + return shard.getSelf(); + } + + protected final Shard getShard() { + return shard; + } + + protected final String persistenceId() { + return shard.persistenceId(); + } + + protected final void tellSender(final Object message) { + shard.getSender().tell(message, getSelf()); + } + + protected final ActorRef createActor(final Props props) { + return shard.getContext().actorOf(props); + } + + protected final ActorSelection selectActor(ActorRef ref) { + return shard.getContext().system().actorSelection(ref.path()); + } + + protected final ActorSelection selectActor(ActorPath path) { + return shard.getContext().system().actorSelection(path); + } + /** * Invoked whenever the local shard's leadership role changes. * * @param isLeader true if the shard has become leader, false if it has - * become a follower. + * become a follower. + * @param hasLeader true if the shard knows about leader ID */ - abstract void onLeadershipChange(boolean isLeader); - abstract void onMessage(M message, boolean isLeader); + abstract void onLeadershipChange(boolean isLeader, boolean hasLeader); + + abstract void onMessage(M message, boolean isLeader, boolean hasLeader); }