X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FElectionTermImpl.java;h=8e2e3d507d1752fe470d0da778e4d62c11ba2fa5;hb=8882e6077db69d22bcc57fcf12dd4a02a81a4967;hp=6a598be680b3607e96952a47edf7d03db7226fa0;hpb=7be62e955c32ff7fa10753c4307199b287b1904c;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ElectionTermImpl.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ElectionTermImpl.java index 6a598be680..8e2e3d507d 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ElectionTermImpl.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ElectionTermImpl.java @@ -1,45 +1,59 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.cluster.raft; -public class ElectionTermImpl implements ElectionTerm{ +import org.opendaylight.controller.cluster.DataPersistenceProvider; +import org.opendaylight.controller.cluster.raft.base.messages.UpdateElectionTerm; +import org.slf4j.Logger; + +/** + * Implementation of ElectionTerm for the RaftActor. + */ +class ElectionTermImpl implements ElectionTerm { /** * Identifier of the actor whose election term information this is */ - private final String id; + private long currentTerm = 0; + private String votedFor = null; - private long currentTerm; + private final DataPersistenceProvider persistence; - private String votedFor; + private final Logger log; + private final String logId; - public ElectionTermImpl(String id) { - this.id = id; - - // TODO: Read currentTerm from some persistent state - currentTerm = 0; - - // TODO: Read votedFor from some file - votedFor = ""; + ElectionTermImpl(DataPersistenceProvider persistence, String logId, Logger log) { + this.persistence = persistence; + this.logId = logId; + this.log = log; } + @Override public long getCurrentTerm() { return currentTerm; } + @Override public String getVotedFor() { return votedFor; } - public void update(long currentTerm, String votedFor){ + @Override public void update(long currentTerm, String votedFor) { + if(log.isDebugEnabled()) { + log.debug("{}: Set currentTerm={}, votedFor={}", logId, currentTerm, votedFor); + } this.currentTerm = currentTerm; this.votedFor = votedFor; + } - // TODO : Write to some persistent state + @Override + public void updateAndPersist(long currentTerm, String votedFor){ + update(currentTerm, votedFor); + // FIXME : Maybe first persist then update the state + persistence.persist(new UpdateElectionTerm(this.currentTerm, this.votedFor), NoopProcedure.instance()); } -} +} \ No newline at end of file