Merge "Bug 2358: Fixed warnings in Restconf"
[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.Map;
18 import org.opendaylight.controller.cluster.DataPersistenceProvider;
19 import org.slf4j.Logger;
20
21 /**
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.
25  */
26 public interface RaftActorContext {
27     /**
28      * Create a new local actor
29       * @param props
30      * @return
31      */
32     ActorRef actorOf(Props props);
33
34     /**
35      * Create a actor selection
36      * @param path
37      * @return
38      */
39     ActorSelection actorSelection(String path);
40
41     /**
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'
45      * @return the identifier
46      */
47     String getId();
48
49     /**
50      * A reference to the RaftActor itself. This could be used to send messages
51      * to the RaftActor
52      * @return
53      */
54     ActorRef getActor();
55
56     /**
57      * Get the ElectionTerm information
58      * @return
59      */
60     ElectionTerm getTermInformation();
61
62     /**
63      * index of highest log entry known to be
64      * committed (initialized to 0, increases
65      *    monotonically)
66      * @return
67      */
68     long getCommitIndex();
69
70
71     /**
72      *
73      */
74     void setCommitIndex(long commitIndex);
75
76     /**
77      * index of highest log entry applied to state
78      * machine (initialized to 0, increases
79      *    monotonically)
80      * @return
81      */
82     long getLastApplied();
83
84
85     /**
86      *
87      */
88     void setLastApplied(long lastApplied);
89
90     /**
91      *
92      * @param replicatedLog
93      */
94     void setReplicatedLog(ReplicatedLog replicatedLog);
95
96     /**
97      * @return A representation of the log
98      */
99     ReplicatedLog getReplicatedLog();
100
101     /**
102      * @return The ActorSystem associated with this context
103      */
104     ActorSystem getActorSystem();
105
106     /**
107      * Get the logger to be used for logging messages
108      *
109      * @return
110      */
111     Logger getLogger();
112
113     /**
114      * Get a mapping of peerId's to their addresses
115      *
116      * @return
117      *
118      */
119     Map<String, String> getPeerAddresses();
120
121     /**
122      * Get the address of the peer as a String. This is the same format in
123      * which a consumer would provide the address
124      *
125      * @param peerId
126      * @return The address of the peer or null if the address has not yet been
127      *         resolved
128      */
129     String getPeerAddress(String peerId);
130
131     /**
132      * Add to actor peers
133      * @param name
134      * @param address
135      */
136     void addToPeers(String name, String address);
137
138     /**
139      *
140      * @param name
141      */
142     void removePeer(String name);
143
144     /**
145      * Given a peerId return the corresponding actor
146      * <p>
147      *
148      *
149      * @param peerId
150      * @return The actorSelection corresponding to the peer or null if the
151      *         address has not yet been resolved
152      */
153     ActorSelection getPeerActorSelection(String peerId);
154
155     /**
156      * Set Peer Address can be called at a later time to change the address of
157      * a known peer.
158      *
159      * <p>
160      * Throws an IllegalStateException if the peer is unknown
161      *
162      * @param peerId
163      * @param peerAddress
164      */
165     void setPeerAddress(String peerId, String peerAddress);
166
167     /**
168      * @return ConfigParams
169      */
170     ConfigParams getConfigParams();
171
172     SnapshotManager getSnapshotManager();
173
174     DataPersistenceProvider getPersistenceProvider();
175
176     boolean hasFollowers();
177
178     long getTotalMemory();
179
180     @VisibleForTesting
181     void setTotalMemoryRetriever(Supplier<Long> retriever);
182
183 }