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 java.util.Collection;
17 import java.util.function.LongSupplier;
18 import javax.annotation.Nullable;
19 import org.opendaylight.controller.cluster.DataPersistenceProvider;
20 import org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior;
21 import org.opendaylight.controller.cluster.raft.policy.RaftPolicy;
22 import org.slf4j.Logger;
25 * The RaftActorContext contains that portion of the RaftActors state that
26 * needs to be shared with it's behaviors. A RaftActorContext should NEVER be
27 * used in any actor context outside the RaftActor that constructed it.
29 public interface RaftActorContext {
31 * Create a new local actor
33 * @return a reference to the newly created actor
35 ActorRef actorOf(Props props);
38 * Create a actor selection
40 * @return an actor selection for the given actor path
42 ActorSelection actorSelection(String path);
45 * Get the identifier for the RaftActor. This identifier represents the
46 * name of the actor whose common state is being shared. For example the
47 * id could be 'inventory'
49 * @return the identifier
54 * @return A reference to the RaftActor itself. This could be used to send messages
60 * @return the ElectionTerm information
62 ElectionTerm getTermInformation();
65 * @return index of highest log entry known to be committed (initialized to 0, increases monotonically)
67 long getCommitIndex();
71 * @param commitIndex new commit index
73 void setCommitIndex(long commitIndex);
76 * @return index of highest log entry applied to state machine (initialized to 0, increases monotonically)
78 long getLastApplied();
82 * @param lastApplied the index of the last log entry that was applied to the state
84 void setLastApplied(long lastApplied);
88 * @param replicatedLog the replicated log of the current RaftActor
90 void setReplicatedLog(ReplicatedLog replicatedLog);
93 * @return A representation of the log
95 ReplicatedLog getReplicatedLog();
98 * @return The ActorSystem associated with this context
100 ActorSystem getActorSystem();
103 * @return the logger to be used for logging messages to a log file
108 * Get the address of the peer as a String. This is the same format in
109 * which a consumer would provide the address
112 * @return The address of the peer or null if the address has not yet been
115 String getPeerAddress(String peerId);
118 * @param serverCfgPayload
120 void updatePeerIds(ServerConfigurationPayload serverCfgPayload);
123 * @return list of PeerInfo
125 Collection<PeerInfo> getPeers();
128 * @return the list of peer IDs.
130 Collection<String> getPeerIds();
133 * Get the PeerInfo for the given peer.
136 * @return the PeerInfo
138 PeerInfo getPeerInfo(String peerId);
146 void addToPeers(String name, String address, VotingState votingState);
152 void removePeer(String name);
155 * Given a peerId return the corresponding actor
160 * @return The actorSelection corresponding to the peer or null if the
161 * address has not yet been resolved
163 ActorSelection getPeerActorSelection(String peerId);
166 * Set Peer Address can be called at a later time to change the address of
170 * Throws an IllegalStateException if the peer is unknown
175 void setPeerAddress(String peerId, String peerAddress);
178 * @return ConfigParams
180 ConfigParams getConfigParams();
184 * @return the SnapshotManager for this RaftActor
186 SnapshotManager getSnapshotManager();
190 * @return the DataPersistenceProvider for this RaftActor
192 DataPersistenceProvider getPersistenceProvider();
196 * @return true if the RaftActor has followers else false
198 boolean hasFollowers();
202 * @return the total memory used by the ReplicatedLog
204 long getTotalMemory();
208 * @param retriever a supplier of the total memory metric
211 void setTotalMemoryRetriever(LongSupplier retriever);
215 * @return the payload version to be used when replicating data
217 short getPayloadVersion();
220 * @return an implementation of the RaftPolicy so that the Raft code can be adapted
222 RaftPolicy getRaftPolicy();
225 * @return true if there are any dynamic server configuration changes available,
226 * false if static peer configurations are still in use
228 boolean isDynamicServerConfigurationInUse();
231 * Configures the dynamic server configurations are avaialble for the RaftActor
233 void setDynamicServerConfigurationInUse();
236 * @return the RaftActor's peer information as a ServerConfigurationPayload if the
237 * dynamic server configurations are available, otherwise returns null
239 @Nullable ServerConfigurationPayload getPeerServerInfo(boolean includeSelf);
242 * @return true if this RaftActor is a voting member of the cluster, false otherwise.
244 boolean isVotingMember();
247 * @return true if there are any voting peers, false otherwise.
249 boolean anyVotingPeers();
252 * @return current behavior attached to the raft actor.
254 RaftActorBehavior getCurrentBehavior();