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