blob: 13f42956b9d276b11a6b3c960294e2136102110e [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.store.flow;
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070017
Sho SHIMIZU19af19d2016-08-12 16:08:04 -070018import com.google.common.base.Objects;
19import org.onosproject.cluster.NodeId;
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070020
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070021import java.util.Collections;
Madan Jampani86940d92015-05-06 11:47:57 -070022import java.util.List;
Sho SHIMIZU19af19d2016-08-12 16:08:04 -070023import java.util.Optional;
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070024
Sho SHIMIZU19af19d2016-08-12 16:08:04 -070025import static com.google.common.base.Preconditions.checkNotNull;
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070026
27/**
28 * Class to represent placement information about Master/Backup copy.
29 */
30public final class ReplicaInfo {
31
32 private final Optional<NodeId> master;
Madan Jampani86940d92015-05-06 11:47:57 -070033 private final List<NodeId> backups;
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070034
35 /**
36 * Creates a ReplicaInfo instance.
37 *
38 * @param master NodeId of the node where the master copy should be
Madan Jampani86940d92015-05-06 11:47:57 -070039 * @param backups list of NodeId, where backup copies should be placed
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070040 */
Madan Jampani86940d92015-05-06 11:47:57 -070041 public ReplicaInfo(NodeId master, List<NodeId> backups) {
Sho SHIMIZU19af19d2016-08-12 16:08:04 -070042 this.master = Optional.ofNullable(master);
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070043 this.backups = checkNotNull(backups);
44 }
45
46 /**
47 * Returns the NodeId, if there is a Node where the master copy should be.
48 *
49 * @return NodeId, where the master copy should be placed
50 */
51 public Optional<NodeId> master() {
52 return master;
53 }
54
55 /**
56 * Returns the collection of NodeId, where backup copies should be placed.
57 *
58 * @return collection of NodeId, where backup copies should be placed
59 */
Madan Jampani86940d92015-05-06 11:47:57 -070060 public List<NodeId> backups() {
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070061 return backups;
62 }
63
Madan Jampani0f6ad142015-05-13 17:10:04 -070064 @Override
65 public int hashCode() {
66 return Objects.hashCode(master, backups);
67 }
68
69 @Override
70 public boolean equals(Object other) {
71 if (!(other instanceof ReplicaInfo)) {
72 return false;
73 }
74 ReplicaInfo that = (ReplicaInfo) other;
75 return Objects.equal(this.master, that.master) &&
76 Objects.equal(this.backups, that.backups);
77 }
78
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070079 // for Serializer
80 private ReplicaInfo() {
Sho SHIMIZU19af19d2016-08-12 16:08:04 -070081 this.master = Optional.empty();
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070082 this.backups = Collections.emptyList();
83 }
84}