2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.datastore;
10 import akka.actor.ActorPath;
11 import akka.actor.ActorRef;
12 import akka.actor.ActorSelection;
13 import akka.actor.Props;
14 import com.google.common.base.Preconditions;
17 * Base class for factories instantiating delegates which are local to the
22 * <I> initial state type
24 abstract class LeaderLocalDelegateFactory<M, D, I> extends DelegateFactory<M, D, I> {
25 private final Shard shard;
27 protected LeaderLocalDelegateFactory(final Shard shard) {
28 this.shard = Preconditions.checkNotNull(shard);
31 protected final ActorRef getSelf() {
32 return shard.getSelf();
35 protected final Shard getShard() {
39 protected final String persistenceId() {
40 return shard.persistenceId();
43 protected final void tellSender(final Object message) {
44 shard.getSender().tell(message, getSelf());
47 protected final ActorRef createActor(final Props props) {
48 return shard.getContext().actorOf(props);
51 protected final ActorSelection selectActor(ActorRef ref) {
52 return shard.getContext().system().actorSelection(ref.path());
55 protected final ActorSelection selectActor(ActorPath path) {
56 return shard.getContext().system().actorSelection(path);
60 * Invoked whenever the local shard's leadership role changes.
62 * @param isLeader true if the shard has become leader, false if it has
65 abstract void onLeadershipChange(boolean isLeader);
66 abstract void onMessage(M message, boolean isLeader);