Take snapshot after recovery on migrated messages
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / ImmutableElectionTerm.java
1 /*
2  * Copyright (c) 2015 Brocade Communications 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 package org.opendaylight.controller.cluster.raft;
9
10 /**
11  * Immutable implementation of ElectionTerm.
12  *
13  * @author Thomas Pantelis
14  */
15 public class ImmutableElectionTerm implements ElectionTerm {
16     private final long currentTerm;
17     private final String votedFor;
18
19     private ImmutableElectionTerm(long currentTerm, String votedFor) {
20         this.currentTerm = currentTerm;
21         this.votedFor = votedFor;
22     }
23
24     @Override
25     public long getCurrentTerm() {
26         return currentTerm;
27     }
28
29     @Override
30     public String getVotedFor() {
31         return votedFor;
32     }
33
34     @Override
35     public void update(long currentTerm, String votedFor) {
36         throw new UnsupportedOperationException();
37     }
38
39     @Override
40     public void updateAndPersist(long currentTerm, String votedFor) {
41         throw new UnsupportedOperationException();
42     }
43
44     @Override
45     public String toString() {
46         return "ImmutableElectionTerm [currentTerm=" + currentTerm + ", votedFor=" + votedFor + "]";
47     }
48
49     public static ElectionTerm copyOf(ElectionTerm from) {
50         return new ImmutableElectionTerm(from.getCurrentTerm(), from.getVotedFor());
51     }
52 }