2 * Copyright (c) 2014 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
9 package org.opendaylight.controller.cluster.raft;
11 import akka.actor.ActorRef;
12 import akka.actor.ActorSelection;
13 import akka.actor.ActorSystem;
14 import akka.actor.Props;
15 import com.google.common.annotations.VisibleForTesting;
16 import com.google.common.base.Supplier;
18 import org.opendaylight.controller.cluster.DataPersistenceProvider;
19 import org.opendaylight.controller.cluster.raft.policy.RaftPolicy;
20 import org.slf4j.Logger;
23 * The RaftActorContext contains that portion of the RaftActors state that
24 * needs to be shared with it's behaviors. A RaftActorContext should NEVER be
25 * used in any actor context outside the RaftActor that constructed it.
27 public interface RaftActorContext {
29 * Create a new local actor
31 * @return a reference to the newly created actor
33 ActorRef actorOf(Props props);
36 * Create a actor selection
38 * @return an actor selection for the given actor path
40 ActorSelection actorSelection(String path);
43 * Get the identifier for the RaftActor. This identifier represents the
44 * name of the actor whose common state is being shared. For example the
45 * id could be 'inventory'
47 * @return the identifier
52 * @return A reference to the RaftActor itself. This could be used to send messages
58 * @return the ElectionTerm information
60 ElectionTerm getTermInformation();
63 * @return index of highest log entry known to be committed (initialized to 0, increases monotonically)
65 long getCommitIndex();
69 * @param commitIndex new commit index
71 void setCommitIndex(long commitIndex);
74 * @return index of highest log entry applied to state machine (initialized to 0, increases monotonically)
76 long getLastApplied();
80 * @param lastApplied the index of the last log entry that was applied to the state
82 void setLastApplied(long lastApplied);
86 * @param replicatedLog the replicated log of the current RaftActor
88 void setReplicatedLog(ReplicatedLog replicatedLog);
91 * @return A representation of the log
93 ReplicatedLog getReplicatedLog();
96 * @return The ActorSystem associated with this context
98 ActorSystem getActorSystem();
101 * @return the logger to be used for logging messages to a log file
106 * @return a mapping of peerId's to their addresses
109 Map<String, String> getPeerAddresses();
112 * Get the address of the peer as a String. This is the same format in
113 * which a consumer would provide the address
116 * @return The address of the peer or null if the address has not yet been
119 String getPeerAddress(String peerId);
127 void addToPeers(String name, String address);
133 void removePeer(String name);
136 * Given a peerId return the corresponding actor
141 * @return The actorSelection corresponding to the peer or null if the
142 * address has not yet been resolved
144 ActorSelection getPeerActorSelection(String peerId);
147 * Set Peer Address can be called at a later time to change the address of
151 * Throws an IllegalStateException if the peer is unknown
156 void setPeerAddress(String peerId, String peerAddress);
159 * @return ConfigParams
161 ConfigParams getConfigParams();
165 * @return the SnapshotManager for this RaftActor
167 SnapshotManager getSnapshotManager();
171 * @return the DataPersistenceProvider for this RaftActor
173 DataPersistenceProvider getPersistenceProvider();
177 * @return true if the RaftActor has followers else false
179 boolean hasFollowers();
183 * @return the total memory used by the ReplicatedLog
185 long getTotalMemory();
189 * @param retriever a supplier of the total memory metric
192 void setTotalMemoryRetriever(Supplier<Long> retriever);
196 * @return the payload version to be used when replicating data
198 short getPayloadVersion();
201 * @return an implementation of the RaftPolicy so that the Raft code can be adapted
203 RaftPolicy getRaftPolicy();