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.persisted.ServerConfigurationPayload;
22 import org.opendaylight.controller.cluster.raft.policy.RaftPolicy;
23 import org.slf4j.Logger;
26 * The RaftActorContext contains that portion of the RaftActors state that
27 * needs to be shared with it's behaviors. A RaftActorContext should NEVER be
28 * used in any actor context outside the RaftActor that constructed it.
30 public interface RaftActorContext {
32 * Create a new local actor
34 * @return a reference to the newly created actor
36 ActorRef actorOf(Props props);
39 * Create a actor selection
41 * @return an actor selection for the given actor path
43 ActorSelection actorSelection(String path);
46 * Get the identifier for the RaftActor. This identifier represents the
47 * name of the actor whose common state is being shared. For example the
48 * id could be 'inventory'
50 * @return the identifier
55 * @return A reference to the RaftActor itself. This could be used to send messages
61 * @return the ElectionTerm information
63 ElectionTerm getTermInformation();
66 * @return index of highest log entry known to be committed (initialized to 0, increases monotonically)
68 long getCommitIndex();
72 * @param commitIndex new commit index
74 void setCommitIndex(long commitIndex);
77 * @return index of highest log entry applied to state machine (initialized to 0, increases monotonically)
79 long getLastApplied();
83 * @param lastApplied the index of the last log entry that was applied to the state
85 void setLastApplied(long lastApplied);
89 * @param replicatedLog the replicated log of the current RaftActor
91 void setReplicatedLog(ReplicatedLog replicatedLog);
94 * @return A representation of the log
96 ReplicatedLog getReplicatedLog();
99 * @return The ActorSystem associated with this context
101 ActorSystem getActorSystem();
104 * @return the logger to be used for logging messages to a log file
109 * Get the address of the peer as a String. This is the same format in
110 * which a consumer would provide the address
113 * @return The address of the peer or null if the address has not yet been
116 String getPeerAddress(String peerId);
119 * @param serverCfgPayload
121 void updatePeerIds(ServerConfigurationPayload serverCfgPayload);
124 * @return list of PeerInfo
126 Collection<PeerInfo> getPeers();
129 * @return the list of peer IDs.
131 Collection<String> getPeerIds();
134 * Get the PeerInfo for the given peer.
137 * @return the PeerInfo
139 PeerInfo getPeerInfo(String peerId);
147 void addToPeers(String name, String address, VotingState votingState);
153 void removePeer(String name);
156 * Given a peerId return the corresponding actor
161 * @return The actorSelection corresponding to the peer or null if the
162 * address has not yet been resolved
164 ActorSelection getPeerActorSelection(String peerId);
167 * Set Peer Address can be called at a later time to change the address of
171 * Throws an IllegalStateException if the peer is unknown
176 void setPeerAddress(String peerId, String peerAddress);
179 * @return ConfigParams
181 ConfigParams getConfigParams();
185 * @return the SnapshotManager for this RaftActor
187 SnapshotManager getSnapshotManager();
191 * @return the DataPersistenceProvider for this RaftActor
193 DataPersistenceProvider getPersistenceProvider();
197 * @return true if the RaftActor has followers else false
199 boolean hasFollowers();
203 * @return the total memory used by the ReplicatedLog
205 long getTotalMemory();
209 * @param retriever a supplier of the total memory metric
212 void setTotalMemoryRetriever(LongSupplier retriever);
216 * @return the payload version to be used when replicating data
218 short getPayloadVersion();
221 * @return an implementation of the RaftPolicy so that the Raft code can be adapted
223 RaftPolicy getRaftPolicy();
226 * @return true if there are any dynamic server configuration changes available,
227 * false if static peer configurations are still in use
229 boolean isDynamicServerConfigurationInUse();
232 * Configures the dynamic server configurations are avaialble for the RaftActor
234 void setDynamicServerConfigurationInUse();
237 * @return the RaftActor's peer information as a ServerConfigurationPayload if the
238 * dynamic server configurations are available, otherwise returns null
240 @Nullable ServerConfigurationPayload getPeerServerInfo(boolean includeSelf);
243 * @return true if this RaftActor is a voting member of the cluster, false otherwise.
245 boolean isVotingMember();
248 * @return true if there are any voting peers, false otherwise.
250 boolean anyVotingPeers();
253 * @return current behavior attached to the raft actor.
255 RaftActorBehavior getCurrentBehavior();