blob: 1d07c39f908ed9ffa0db6cf7167ec8da1f064f77 [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
18import static com.google.common.base.Preconditions.checkNotNull;
19
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070020import java.util.Collections;
Madan Jampani86940d92015-05-06 11:47:57 -070021import java.util.List;
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070022
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.cluster.NodeId;
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070024
Madan Jampani0f6ad142015-05-13 17:10:04 -070025import com.google.common.base.Objects;
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070026import com.google.common.base.Optional;
27
28/**
29 * Class to represent placement information about Master/Backup copy.
30 */
31public final class ReplicaInfo {
32
33 private final Optional<NodeId> master;
Madan Jampani86940d92015-05-06 11:47:57 -070034 private final List<NodeId> backups;
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070035
36 /**
37 * Creates a ReplicaInfo instance.
38 *
39 * @param master NodeId of the node where the master copy should be
Madan Jampani86940d92015-05-06 11:47:57 -070040 * @param backups list of NodeId, where backup copies should be placed
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070041 */
Madan Jampani86940d92015-05-06 11:47:57 -070042 public ReplicaInfo(NodeId master, List<NodeId> backups) {
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070043 this.master = Optional.fromNullable(master);
44 this.backups = checkNotNull(backups);
45 }
46
47 /**
48 * Returns the NodeId, if there is a Node where the master copy should be.
49 *
50 * @return NodeId, where the master copy should be placed
51 */
52 public Optional<NodeId> master() {
53 return master;
54 }
55
56 /**
57 * Returns the collection of NodeId, where backup copies should be placed.
58 *
59 * @return collection of NodeId, where backup copies should be placed
60 */
Madan Jampani86940d92015-05-06 11:47:57 -070061 public List<NodeId> backups() {
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070062 return backups;
63 }
64
Madan Jampani0f6ad142015-05-13 17:10:04 -070065 @Override
66 public int hashCode() {
67 return Objects.hashCode(master, backups);
68 }
69
70 @Override
71 public boolean equals(Object other) {
72 if (!(other instanceof ReplicaInfo)) {
73 return false;
74 }
75 ReplicaInfo that = (ReplicaInfo) other;
76 return Objects.equal(this.master, that.master) &&
77 Objects.equal(this.backups, that.backups);
78 }
79
Yuta HIGUCHIb25f4da2014-10-16 15:09:26 -070080 // for Serializer
81 private ReplicaInfo() {
82 this.master = Optional.absent();
83 this.backups = Collections.emptyList();
84 }
85}