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;
17 import java.util.Collection;
18 import javax.annotation.Nullable;
19 import org.opendaylight.controller.cluster.DataPersistenceProvider;
20 import org.opendaylight.controller.cluster.raft.policy.RaftPolicy;
21 import org.slf4j.Logger;
24 * The RaftActorContext contains that portion of the RaftActors state that
25 * needs to be shared with it's behaviors. A RaftActorContext should NEVER be
26 * used in any actor context outside the RaftActor that constructed it.
28 public interface RaftActorContext {
30 * Create a new local actor
32 * @return a reference to the newly created actor
34 ActorRef actorOf(Props props);
37 * Create a actor selection
39 * @return an actor selection for the given actor path
41 ActorSelection actorSelection(String path);
44 * Get the identifier for the RaftActor. This identifier represents the
45 * name of the actor whose common state is being shared. For example the
46 * id could be 'inventory'
48 * @return the identifier
53 * @return A reference to the RaftActor itself. This could be used to send messages
59 * @return the ElectionTerm information
61 ElectionTerm getTermInformation();
64 * @return index of highest log entry known to be committed (initialized to 0, increases monotonically)
66 long getCommitIndex();
70 * @param commitIndex new commit index
72 void setCommitIndex(long commitIndex);
75 * @return index of highest log entry applied to state machine (initialized to 0, increases monotonically)
77 long getLastApplied();
81 * @param lastApplied the index of the last log entry that was applied to the state
83 void setLastApplied(long lastApplied);
87 * @param replicatedLog the replicated log of the current RaftActor
89 void setReplicatedLog(ReplicatedLog replicatedLog);
92 * @return A representation of the log
94 ReplicatedLog getReplicatedLog();
97 * @return The ActorSystem associated with this context
99 ActorSystem getActorSystem();
102 * @return the logger to be used for logging messages to a log file
107 * Get the address of the peer as a String. This is the same format in
108 * which a consumer would provide the address
111 * @return The address of the peer or null if the address has not yet been
114 String getPeerAddress(String peerId);
117 * @param serverCfgPayload
119 void updatePeerIds(ServerConfigurationPayload serverCfgPayload);
122 * @return list of PeerInfo
124 Collection<PeerInfo> getPeers();
127 * @return the list of peer IDs.
129 Collection<String> getPeerIds();
132 * Get the PeerInfo for the given peer.
135 * @return the PeerInfo
137 PeerInfo getPeerInfo(String peerId);
145 void addToPeers(String name, String address, VotingState votingState);
151 void removePeer(String name);
154 * Given a peerId return the corresponding actor
159 * @return The actorSelection corresponding to the peer or null if the
160 * address has not yet been resolved
162 ActorSelection getPeerActorSelection(String peerId);
165 * Set Peer Address can be called at a later time to change the address of
169 * Throws an IllegalStateException if the peer is unknown
174 void setPeerAddress(String peerId, String peerAddress);
177 * @return ConfigParams
179 ConfigParams getConfigParams();
183 * @return the SnapshotManager for this RaftActor
185 SnapshotManager getSnapshotManager();
189 * @return the DataPersistenceProvider for this RaftActor
191 DataPersistenceProvider getPersistenceProvider();
195 * @return true if the RaftActor has followers else false
197 boolean hasFollowers();
201 * @return the total memory used by the ReplicatedLog
203 long getTotalMemory();
207 * @param retriever a supplier of the total memory metric
210 void setTotalMemoryRetriever(Supplier<Long> retriever);
214 * @return the payload version to be used when replicating data
216 short getPayloadVersion();
219 * @return an implementation of the RaftPolicy so that the Raft code can be adapted
221 RaftPolicy getRaftPolicy();
224 * @return true if there are any dynamic server configuration changes available,
225 * false if static peer configurations are still in use
227 boolean isDynamicServerConfigurationInUse();
230 * Configures the dynamic server configurations are avaialble for the RaftActor
232 void setDynamicServerConfigurationInUse();
235 * @return the RaftActor's peer information as a ServerConfigurationPayload if the
236 * dynamic server configurations are available, otherwise returns null
238 @Nullable ServerConfigurationPayload getPeerServerInfo();
241 * @return true if this RaftActor is a voting member of the cluster, false otherwise.
243 boolean isVotingMember();