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