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;
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 * @return a copy of the mapping of peerId's to their addresses
110 Map<String, String> getPeerAddresses();
113 * Get the address of the peer as a String. This is the same format in
114 * which a consumer would provide the address
117 * @return The address of the peer or null if the address has not yet been
120 String getPeerAddress(String peerId);
123 * @return the list of peer IDs.
125 Collection<String> getPeerIds();
133 void addToPeers(String name, String address);
139 void removePeer(String name);
142 * Given a peerId return the corresponding actor
147 * @return The actorSelection corresponding to the peer or null if the
148 * address has not yet been resolved
150 ActorSelection getPeerActorSelection(String peerId);
153 * Set Peer Address can be called at a later time to change the address of
157 * Throws an IllegalStateException if the peer is unknown
162 void setPeerAddress(String peerId, String peerAddress);
165 * @return ConfigParams
167 ConfigParams getConfigParams();
171 * @return the SnapshotManager for this RaftActor
173 SnapshotManager getSnapshotManager();
177 * @return the DataPersistenceProvider for this RaftActor
179 DataPersistenceProvider getPersistenceProvider();
183 * @return true if the RaftActor has followers else false
185 boolean hasFollowers();
189 * @return the total memory used by the ReplicatedLog
191 long getTotalMemory();
195 * @param retriever a supplier of the total memory metric
198 void setTotalMemoryRetriever(Supplier<Long> retriever);
202 * @return the payload version to be used when replicating data
204 short getPayloadVersion();
207 * @return an implementation of the RaftPolicy so that the Raft code can be adapted
209 RaftPolicy getRaftPolicy();