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 akka.cluster.Cluster;
16 import com.google.common.annotations.VisibleForTesting;
17 import java.util.Collection;
18 import java.util.Optional;
19 import java.util.function.LongSupplier;
20 import javax.annotation.Nullable;
21 import org.opendaylight.controller.cluster.DataPersistenceProvider;
22 import org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior;
23 import org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload;
24 import org.opendaylight.controller.cluster.raft.policy.RaftPolicy;
25 import org.slf4j.Logger;
28 * The RaftActorContext contains that portion of the RaftActors state that
29 * needs to be shared with it's behaviors. A RaftActorContext should NEVER be
30 * used in any actor context outside the RaftActor that constructed it.
32 public interface RaftActorContext {
34 * Create a new local actor
36 * @return a reference to the newly created actor
38 ActorRef actorOf(Props props);
41 * Create a actor selection
43 * @return an actor selection for the given actor path
45 ActorSelection actorSelection(String path);
48 * Get the identifier for the RaftActor. This identifier represents the
49 * name of the actor whose common state is being shared. For example the
50 * id could be 'inventory'
52 * @return the identifier
57 * @return A reference to the RaftActor itself. This could be used to send messages
63 * The akka Cluster singleton for the actor system if one is configured.
65 * @return an Optional containing the CLuster instance is present.
67 Optional<Cluster> getCluster();
70 * @return the ElectionTerm information
72 ElectionTerm getTermInformation();
75 * @return index of highest log entry known to be committed (initialized to 0, increases monotonically)
77 long getCommitIndex();
81 * @param commitIndex new commit index
83 void setCommitIndex(long commitIndex);
86 * @return index of highest log entry applied to state machine (initialized to 0, increases monotonically)
88 long getLastApplied();
92 * @param lastApplied the index of the last log entry that was applied to the state
94 void setLastApplied(long lastApplied);
98 * @param replicatedLog the replicated log of the current RaftActor
100 void setReplicatedLog(ReplicatedLog replicatedLog);
103 * @return A representation of the log
105 ReplicatedLog getReplicatedLog();
108 * @return The ActorSystem associated with this context
110 ActorSystem getActorSystem();
113 * @return the logger to be used for logging messages to a log file
118 * Get the address of the peer as a String. This is the same format in
119 * which a consumer would provide the address
122 * @return The address of the peer or null if the address has not yet been
125 String getPeerAddress(String peerId);
128 * @param serverCfgPayload
130 void updatePeerIds(ServerConfigurationPayload serverCfgPayload);
133 * @return list of PeerInfo
135 Collection<PeerInfo> getPeers();
138 * @return the list of peer IDs.
140 Collection<String> getPeerIds();
143 * Get the PeerInfo for the given peer.
146 * @return the PeerInfo
148 PeerInfo getPeerInfo(String peerId);
156 void addToPeers(String name, String address, VotingState votingState);
162 void removePeer(String name);
165 * Given a peerId return the corresponding actor
170 * @return The actorSelection corresponding to the peer or null if the
171 * address has not yet been resolved
173 ActorSelection getPeerActorSelection(String peerId);
176 * Set Peer Address can be called at a later time to change the address of
180 * Throws an IllegalStateException if the peer is unknown
185 void setPeerAddress(String peerId, String peerAddress);
188 * @return ConfigParams
190 ConfigParams getConfigParams();
194 * @return the SnapshotManager for this RaftActor
196 SnapshotManager getSnapshotManager();
200 * @return the DataPersistenceProvider for this RaftActor
202 DataPersistenceProvider getPersistenceProvider();
206 * @return true if the RaftActor has followers else false
208 boolean hasFollowers();
212 * @return the total memory used by the ReplicatedLog
214 long getTotalMemory();
218 * @param retriever a supplier of the total memory metric
221 void setTotalMemoryRetriever(LongSupplier retriever);
225 * @return the payload version to be used when replicating data
227 short getPayloadVersion();
230 * @return an implementation of the RaftPolicy so that the Raft code can be adapted
232 RaftPolicy getRaftPolicy();
235 * @return true if there are any dynamic server configuration changes available,
236 * false if static peer configurations are still in use
238 boolean isDynamicServerConfigurationInUse();
241 * Configures the dynamic server configurations are avaialble for the RaftActor
243 void setDynamicServerConfigurationInUse();
246 * @return the RaftActor's peer information as a ServerConfigurationPayload if the
247 * dynamic server configurations are available, otherwise returns null
249 @Nullable ServerConfigurationPayload getPeerServerInfo(boolean includeSelf);
252 * @return true if this RaftActor is a voting member of the cluster, false otherwise.
254 boolean isVotingMember();
257 * @return true if there are any voting peers, false otherwise.
259 boolean anyVotingPeers();
262 * @return current behavior attached to the raft actor.
264 RaftActorBehavior getCurrentBehavior();