aa49e1681348adb0b7a9b1de67d5acb32aef1172
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / RaftActorContext.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.raft;
10
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;
18 import org.opendaylight.controller.cluster.DataPersistenceProvider;
19 import org.opendaylight.controller.cluster.raft.policy.RaftPolicy;
20 import org.slf4j.Logger;
21
22 /**
23  * The RaftActorContext contains that portion of the RaftActors state that
24  * needs to be shared with it's behaviors. A RaftActorContext should NEVER be
25  * used in any actor context outside the RaftActor that constructed it.
26  */
27 public interface RaftActorContext {
28     /**
29      * Create a new local actor
30      * @param props
31      * @return a reference to the newly created actor
32      */
33     ActorRef actorOf(Props props);
34
35     /**
36      * Create a actor selection
37      * @param path
38      * @return an actor selection for the given actor path
39      */
40     ActorSelection actorSelection(String path);
41
42     /**
43      * Get the identifier for the RaftActor. This identifier represents the
44      * name of the actor whose common state is being shared. For example the
45      * id could be 'inventory'
46      *
47      * @return the identifier
48      */
49     String getId();
50
51     /**
52      * @return A reference to the RaftActor itself. This could be used to send messages
53      * to the RaftActor
54      */
55     ActorRef getActor();
56
57     /**
58      * @return the ElectionTerm information
59      */
60     ElectionTerm getTermInformation();
61
62     /**
63      * @return index of highest log entry known to be committed (initialized to 0, increases monotonically)
64      */
65     long getCommitIndex();
66
67
68     /**
69      * @param commitIndex new commit index
70      */
71     void setCommitIndex(long commitIndex);
72
73     /**
74      * @return index of highest log entry applied to state machine (initialized to 0, increases monotonically)
75      */
76     long getLastApplied();
77
78
79     /**
80      * @param lastApplied the index of the last log entry that was applied to the state
81      */
82     void setLastApplied(long lastApplied);
83
84     /**
85      *
86      * @param replicatedLog the replicated log of the current RaftActor
87      */
88     void setReplicatedLog(ReplicatedLog replicatedLog);
89
90     /**
91      * @return A representation of the log
92      */
93     ReplicatedLog getReplicatedLog();
94
95     /**
96      * @return The ActorSystem associated with this context
97      */
98     ActorSystem getActorSystem();
99
100     /**
101      * @return the logger to be used for logging messages to a log file
102      */
103     Logger getLogger();
104
105     /**
106      * Get the address of the peer as a String. This is the same format in
107      * which a consumer would provide the address
108      *
109      * @param peerId
110      * @return The address of the peer or null if the address has not yet been
111      *         resolved
112      */
113     String getPeerAddress(String peerId);
114
115     /**
116      * @param serverCfgPayload
117      */
118     void updatePeerIds(ServerConfigurationPayload serverCfgPayload);
119
120     /**
121      * @return list of PeerInfo
122      */
123     Collection<PeerInfo> getPeers();
124
125     /**
126      * @return the list of peer IDs.
127      */
128     Collection<String> getPeerIds();
129
130     /**
131      * Get the PeerInfo for the given peer.
132      *
133      * @param peerId
134      * @return the PeerInfo
135      */
136     PeerInfo getPeerInfo(String peerId);
137
138     /**
139      * Add to actor peers
140      *
141      * @param name
142      * @param address
143      */
144     void addToPeers(String name, String address, VotingState votingState);
145
146     /**
147      *
148      * @param name
149      */
150     void removePeer(String name);
151
152     /**
153      * Given a peerId return the corresponding actor
154      * <p>
155      *
156      *
157      * @param peerId
158      * @return The actorSelection corresponding to the peer or null if the
159      *         address has not yet been resolved
160      */
161     ActorSelection getPeerActorSelection(String peerId);
162
163     /**
164      * Set Peer Address can be called at a later time to change the address of
165      * a known peer.
166      *
167      * <p>
168      * Throws an IllegalStateException if the peer is unknown
169      *
170      * @param peerId
171      * @param peerAddress
172      */
173     void setPeerAddress(String peerId, String peerAddress);
174
175     /**
176      * @return ConfigParams
177      */
178     ConfigParams getConfigParams();
179
180     /**
181      *
182      * @return the SnapshotManager for this RaftActor
183      */
184     SnapshotManager getSnapshotManager();
185
186     /**
187      *
188      * @return the DataPersistenceProvider for this RaftActor
189      */
190     DataPersistenceProvider getPersistenceProvider();
191
192     /**
193      *
194      * @return true if the RaftActor has followers else false
195      */
196     boolean hasFollowers();
197
198     /**
199      *
200      * @return the total memory used by the ReplicatedLog
201      */
202     long getTotalMemory();
203
204     /**
205      *
206      * @param retriever a supplier of the total memory metric
207      */
208     @VisibleForTesting
209     void setTotalMemoryRetriever(Supplier<Long> retriever);
210
211     /**
212      *
213      * @return the payload version to be used when replicating data
214      */
215     short getPayloadVersion();
216
217     /**
218      * @return an implementation of the RaftPolicy so that the Raft code can be adapted
219      */
220     RaftPolicy getRaftPolicy();
221 }