Derive MockRaftActorContext from RaftActorContextImpl
[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      * @return list of PeerInfo
117      */
118     Collection<PeerInfo> getPeers();
119
120     /**
121      * @return the list of peer IDs.
122      */
123     Collection<String> getPeerIds();
124
125     /**
126      * Get the PeerInfo for the given peer.
127      *
128      * @param peerId
129      * @return the PeerInfo
130      */
131     PeerInfo getPeerInfo(String peerId);
132
133     /**
134      * Add to actor peers
135      *
136      * @param name
137      * @param address
138      */
139     void addToPeers(String name, String address, VotingState votingState);
140
141     /**
142      *
143      * @param name
144      */
145     void removePeer(String name);
146
147     /**
148      * Given a peerId return the corresponding actor
149      * <p>
150      *
151      *
152      * @param peerId
153      * @return The actorSelection corresponding to the peer or null if the
154      *         address has not yet been resolved
155      */
156     ActorSelection getPeerActorSelection(String peerId);
157
158     /**
159      * Set Peer Address can be called at a later time to change the address of
160      * a known peer.
161      *
162      * <p>
163      * Throws an IllegalStateException if the peer is unknown
164      *
165      * @param peerId
166      * @param peerAddress
167      */
168     void setPeerAddress(String peerId, String peerAddress);
169
170     /**
171      * @return ConfigParams
172      */
173     ConfigParams getConfigParams();
174
175     /**
176      *
177      * @return the SnapshotManager for this RaftActor
178      */
179     SnapshotManager getSnapshotManager();
180
181     /**
182      *
183      * @return the DataPersistenceProvider for this RaftActor
184      */
185     DataPersistenceProvider getPersistenceProvider();
186
187     /**
188      *
189      * @return true if the RaftActor has followers else false
190      */
191     boolean hasFollowers();
192
193     /**
194      *
195      * @return the total memory used by the ReplicatedLog
196      */
197     long getTotalMemory();
198
199     /**
200      *
201      * @param retriever a supplier of the total memory metric
202      */
203     @VisibleForTesting
204     void setTotalMemoryRetriever(Supplier<Long> retriever);
205
206     /**
207      *
208      * @return the payload version to be used when replicating data
209      */
210     short getPayloadVersion();
211
212     /**
213      * @return an implementation of the RaftPolicy so that the Raft code can be adapted
214      */
215     RaftPolicy getRaftPolicy();
216 }