2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.cluster.raft;
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;
20 public class RaftActorContextImpl implements RaftActorContext{
22 private final ActorRef actor;
24 private final UntypedActorContext context;
26 private final String id;
28 private final ElectionTerm termInformation;
30 private long commitIndex;
32 private long lastApplied;
34 private final ReplicatedLog replicatedLog;
36 private final Map<String, String> peerAddresses;
38 private final LoggingAdapter LOG;
41 public RaftActorContextImpl(ActorRef actor, UntypedActorContext context,
43 ElectionTerm termInformation, long commitIndex,
44 long lastApplied, ReplicatedLog replicatedLog, Map<String, String> peerAddresses, LoggingAdapter logger) {
46 this.context = context;
48 this.termInformation = termInformation;
49 this.commitIndex = commitIndex;
50 this.lastApplied = lastApplied;
51 this.replicatedLog = replicatedLog;
52 this.peerAddresses = peerAddresses;
56 public ActorRef actorOf(Props props){
57 return context.actorOf(props);
60 public ActorSelection actorSelection(String path){
61 return context.actorSelection(path);
64 public String getId() {
68 public ActorRef getActor() {
72 public ElectionTerm getTermInformation() {
73 return termInformation;
76 public long getCommitIndex() {
80 @Override public void setCommitIndex(long commitIndex) {
81 this.commitIndex = commitIndex;
84 public long getLastApplied() {
88 @Override public void setLastApplied(long lastApplied) {
89 this.lastApplied = lastApplied;
92 @Override public ReplicatedLog getReplicatedLog() {
96 @Override public ActorSystem getActorSystem() {
97 return context.system();
100 @Override public LoggingAdapter getLogger() {
104 @Override public Map<String, String> getPeerAddresses() {
105 return peerAddresses;
108 @Override public String getPeerAddress(String peerId) {
109 return peerAddresses.get(peerId);
112 @Override public void addToPeers(String name, String address) {
113 LOG.debug("Kamal--> addToPeer for:"+name);
114 peerAddresses.put(name, address);
117 @Override public void removePeer(String name) {
118 LOG.debug("Kamal--> removePeer for:"+name);
119 peerAddresses.remove(name);