Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.store.flow; |
Yuta HIGUCHI | b25f4da | 2014-10-16 15:09:26 -0700 | [diff] [blame] | 17 | |
Sho SHIMIZU | 19af19d | 2016-08-12 16:08:04 -0700 | [diff] [blame] | 18 | import com.google.common.base.Objects; |
| 19 | import org.onosproject.cluster.NodeId; |
Yuta HIGUCHI | b25f4da | 2014-10-16 15:09:26 -0700 | [diff] [blame] | 20 | |
Yuta HIGUCHI | b25f4da | 2014-10-16 15:09:26 -0700 | [diff] [blame] | 21 | import java.util.Collections; |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 22 | import java.util.List; |
Sho SHIMIZU | 19af19d | 2016-08-12 16:08:04 -0700 | [diff] [blame] | 23 | import java.util.Optional; |
Yuta HIGUCHI | b25f4da | 2014-10-16 15:09:26 -0700 | [diff] [blame] | 24 | |
Sho SHIMIZU | 19af19d | 2016-08-12 16:08:04 -0700 | [diff] [blame] | 25 | import static com.google.common.base.Preconditions.checkNotNull; |
Yuta HIGUCHI | b25f4da | 2014-10-16 15:09:26 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Class to represent placement information about Master/Backup copy. |
| 29 | */ |
| 30 | public final class ReplicaInfo { |
| 31 | |
| 32 | private final Optional<NodeId> master; |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 33 | private final List<NodeId> backups; |
Yuta HIGUCHI | b25f4da | 2014-10-16 15:09:26 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Creates a ReplicaInfo instance. |
| 37 | * |
| 38 | * @param master NodeId of the node where the master copy should be |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 39 | * @param backups list of NodeId, where backup copies should be placed |
Yuta HIGUCHI | b25f4da | 2014-10-16 15:09:26 -0700 | [diff] [blame] | 40 | */ |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 41 | public ReplicaInfo(NodeId master, List<NodeId> backups) { |
Sho SHIMIZU | 19af19d | 2016-08-12 16:08:04 -0700 | [diff] [blame] | 42 | this.master = Optional.ofNullable(master); |
Yuta HIGUCHI | b25f4da | 2014-10-16 15:09:26 -0700 | [diff] [blame] | 43 | 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 Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 60 | public List<NodeId> backups() { |
Yuta HIGUCHI | b25f4da | 2014-10-16 15:09:26 -0700 | [diff] [blame] | 61 | return backups; |
| 62 | } |
| 63 | |
Madan Jampani | 0f6ad14 | 2015-05-13 17:10:04 -0700 | [diff] [blame] | 64 | @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 HIGUCHI | b25f4da | 2014-10-16 15:09:26 -0700 | [diff] [blame] | 79 | // for Serializer |
| 80 | private ReplicaInfo() { |
Sho SHIMIZU | 19af19d | 2016-08-12 16:08:04 -0700 | [diff] [blame] | 81 | this.master = Optional.empty(); |
Yuta HIGUCHI | b25f4da | 2014-10-16 15:09:26 -0700 | [diff] [blame] | 82 | this.backups = Collections.emptyList(); |
| 83 | } |
| 84 | } |