Implement change to voting with no leader
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / messages / ChangeServersVotingStatus.java
1 /*
2  * Copyright (c) 2016 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.messages;
9
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.ImmutableSet;
12 import java.io.Serializable;
13 import java.util.Collection;
14 import java.util.Collections;
15 import java.util.HashMap;
16 import java.util.Map;
17 import javax.annotation.Nonnull;
18
19 /**
20  * Message sent to change the raft voting status for servers.
21  *
22  * @author Thomas Pantelis
23  */
24 public class ChangeServersVotingStatus implements Serializable {
25     private static final long serialVersionUID = 1L;
26
27     private final Map<String, Boolean> serverVotingStatusMap;
28     private final Collection<String> serversVisited;
29
30     public ChangeServersVotingStatus(@Nonnull Map<String, Boolean> serverVotingStatusMap) {
31         this(serverVotingStatusMap, Collections.emptySet());
32     }
33
34     public ChangeServersVotingStatus(@Nonnull Map<String, Boolean> serverVotingStatusMap,
35             @Nonnull Collection<String> serversVisited) {
36         this.serverVotingStatusMap = new HashMap<>(Preconditions.checkNotNull(serverVotingStatusMap));
37         this.serversVisited = ImmutableSet.copyOf(Preconditions.checkNotNull(serversVisited));
38     }
39
40     @Nonnull
41     public Map<String, Boolean> getServerVotingStatusMap() {
42         return serverVotingStatusMap;
43     }
44
45     @Nonnull
46     public Collection<String> getServersVisited() {
47         return serversVisited;
48     }
49
50     @Override
51     public String toString() {
52         return "ChangeServersVotingStatus [serverVotingStatusMap=" + serverVotingStatusMap
53                 + (serversVisited != null ? ", serversVisited=" + serversVisited : "") + "]";
54     }
55 }