blob: 3e2905efa3f431c8b703e5ba17b4ff42f1f69105 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Ayaka Koshibeabedb092014-10-20 17:01:31 -070016package org.onlab.onos.cluster;
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070017
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070018import java.util.List;
19import java.util.Objects;
20
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070021import com.google.common.base.MoreObjects;
Yuta HIGUCHI40d01772014-10-21 00:08:44 -070022import com.google.common.collect.ImmutableList;
23
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070024/**
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070025 * An immutable container for role information for a device,
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070026 * within the current cluster. Role attributes include current
27 * master and a preference-ordered list of backup nodes.
28 */
29public class RoleInfo {
30 private final NodeId master;
31 private final List<NodeId> backups;
32
33 public RoleInfo(NodeId master, List<NodeId> backups) {
34 this.master = master;
Yuta HIGUCHI40d01772014-10-21 00:08:44 -070035 this.backups = ImmutableList.copyOf(backups);
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070036 }
37
Yuta HIGUCHI4b0ca2c2014-10-30 01:17:36 -070038 public RoleInfo() {
39 this.master = null;
40 this.backups = ImmutableList.of();
41 }
42
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070043 public NodeId master() {
44 return master;
45 }
46
47 public List<NodeId> backups() {
Ayaka Koshibeadb2d3c2014-10-20 23:39:51 -070048 return backups;
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070049 }
50
51 @Override
52 public boolean equals(Object other) {
53 if (other == null) {
54 return false;
55 }
56 if (!(other instanceof RoleInfo)) {
57 return false;
58 }
59 RoleInfo that = (RoleInfo) other;
60 if (!Objects.equals(this.master, that.master)) {
61 return false;
62 }
63 if (!Objects.equals(this.backups, that.backups)) {
64 return false;
65 }
66 return true;
67 }
68
69 @Override
70 public int hashCode() {
Yuta HIGUCHI4b0ca2c2014-10-30 01:17:36 -070071 return Objects.hash(master, backups);
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070072 }
73
74 @Override
75 public String toString() {
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070076 return MoreObjects.toStringHelper(this.getClass())
77 .add("master", master)
78 .add("backups", backups)
79 .toString();
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070080 }
81}