Added hosttracker shell for karaf (rebased)
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / RaftActorContextImpl.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.actor.UntypedActorContext;
16 import akka.event.LoggingAdapter;
17
18 import java.util.Map;
19
20 public class RaftActorContextImpl implements RaftActorContext{
21
22     private final ActorRef actor;
23
24     private final UntypedActorContext context;
25
26     private final String id;
27
28     private final ElectionTerm termInformation;
29
30     private long commitIndex;
31
32     private long lastApplied;
33
34     private final ReplicatedLog replicatedLog;
35
36     private final Map<String, String> peerAddresses;
37
38     private final LoggingAdapter LOG;
39
40
41     public RaftActorContextImpl(ActorRef actor, UntypedActorContext context,
42         String id,
43         ElectionTerm termInformation, long commitIndex,
44         long lastApplied, ReplicatedLog replicatedLog, Map<String, String> peerAddresses, LoggingAdapter logger) {
45         this.actor = actor;
46         this.context = context;
47         this.id = id;
48         this.termInformation = termInformation;
49         this.commitIndex = commitIndex;
50         this.lastApplied = lastApplied;
51         this.replicatedLog = replicatedLog;
52         this.peerAddresses = peerAddresses;
53         this.LOG = logger;
54     }
55
56     public ActorRef actorOf(Props props){
57         return context.actorOf(props);
58     }
59
60     public ActorSelection actorSelection(String path){
61         return context.actorSelection(path);
62     }
63
64     public String getId() {
65         return id;
66     }
67
68     public ActorRef getActor() {
69         return actor;
70     }
71
72     public ElectionTerm getTermInformation() {
73         return termInformation;
74     }
75
76     public long getCommitIndex() {
77         return commitIndex;
78     }
79
80     @Override public void setCommitIndex(long commitIndex) {
81         this.commitIndex = commitIndex;
82     }
83
84     public long getLastApplied() {
85         return lastApplied;
86     }
87
88     @Override public void setLastApplied(long lastApplied) {
89         this.lastApplied = lastApplied;
90     }
91
92     @Override public ReplicatedLog getReplicatedLog() {
93         return replicatedLog;
94     }
95
96     @Override public ActorSystem getActorSystem() {
97         return context.system();
98     }
99
100     @Override public LoggingAdapter getLogger() {
101         return this.LOG;
102     }
103
104     @Override public Map<String, String> getPeerAddresses() {
105         return peerAddresses;
106     }
107
108     @Override public String getPeerAddress(String peerId) {
109         return peerAddresses.get(peerId);
110     }
111
112     @Override public void addToPeers(String name, String address) {
113         LOG.debug("Kamal--> addToPeer for:"+name);
114         peerAddresses.put(name, address);
115     }
116
117     @Override public void removePeer(String name) {
118         LOG.debug("Kamal--> removePeer for:"+name);
119         peerAddresses.remove(name);
120     }
121 }