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