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;
18 import org.opendaylight.controller.cluster.DataPersistenceProvider;
19 import org.slf4j.Logger;
22 * The RaftActorContext contains that portion of the RaftActors state that
23 * needs to be shared with it's behaviors. A RaftActorContext should NEVER be
24 * used in any actor context outside the RaftActor that constructed it.
26 public interface RaftActorContext {
28 * Create a new local actor
30 * @return a reference to the newly created actor
32 ActorRef actorOf(Props props);
35 * Create a actor selection
37 * @return an actor selection for the given actor path
39 ActorSelection actorSelection(String path);
42 * Get the identifier for the RaftActor. This identifier represents the
43 * name of the actor whose common state is being shared. For example the
44 * id could be 'inventory'
46 * @return the identifier
51 * @return A reference to the RaftActor itself. This could be used to send messages
57 * @return the ElectionTerm information
59 ElectionTerm getTermInformation();
62 * @return index of highest log entry known to be committed (initialized to 0, increases monotonically)
64 long getCommitIndex();
68 * @param commitIndex new commit index
70 void setCommitIndex(long commitIndex);
73 * @return index of highest log entry applied to state machine (initialized to 0, increases monotonically)
75 long getLastApplied();
79 * @param lastApplied the index of the last log entry that was applied to the state
81 void setLastApplied(long lastApplied);
85 * @param replicatedLog the replicated log of the current RaftActor
87 void setReplicatedLog(ReplicatedLog replicatedLog);
90 * @return A representation of the log
92 ReplicatedLog getReplicatedLog();
95 * @return The ActorSystem associated with this context
97 ActorSystem getActorSystem();
100 * @return the logger to be used for logging messages to a log file
105 * @return a mapping of peerId's to their addresses
108 Map<String, String> getPeerAddresses();
111 * Get the address of the peer as a String. This is the same format in
112 * which a consumer would provide the address
115 * @return The address of the peer or null if the address has not yet been
118 String getPeerAddress(String peerId);
126 void addToPeers(String name, String address);
132 void removePeer(String name);
135 * Given a peerId return the corresponding actor
140 * @return The actorSelection corresponding to the peer or null if the
141 * address has not yet been resolved
143 ActorSelection getPeerActorSelection(String peerId);
146 * Set Peer Address can be called at a later time to change the address of
150 * Throws an IllegalStateException if the peer is unknown
155 void setPeerAddress(String peerId, String peerAddress);
158 * @return ConfigParams
160 ConfigParams getConfigParams();
164 * @return the SnapshotManager for this RaftActor
166 SnapshotManager getSnapshotManager();
170 * @return the DataPersistenceProvider for this RaftActor
172 DataPersistenceProvider getPersistenceProvider();
176 * @return true if the RaftActor has followers else false
178 boolean hasFollowers();
182 * @return the total memory used by the ReplicatedLog
184 long getTotalMemory();
188 * @param retriever a supplier of the total memory metric
191 void setTotalMemoryRetriever(Supplier<Long> retriever);
195 * @return the payload version to be used when replicating data
197 short getPayloadVersion();