Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
Yuta HIGUCHI | b25f4da | 2014-10-16 15:09:26 -0700 | [diff] [blame] | 16 | package org.onlab.onos.store.flow; |
| 17 | |
| 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | |
| 20 | import java.util.Collection; |
| 21 | import java.util.Collections; |
| 22 | |
| 23 | import org.onlab.onos.cluster.NodeId; |
| 24 | |
| 25 | import com.google.common.base.Optional; |
| 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; |
| 33 | private final Collection<NodeId> backups; |
| 34 | |
| 35 | /** |
| 36 | * Creates a ReplicaInfo instance. |
| 37 | * |
| 38 | * @param master NodeId of the node where the master copy should be |
| 39 | * @param backups collection of NodeId, where backup copies should be placed |
| 40 | */ |
| 41 | public ReplicaInfo(NodeId master, Collection<NodeId> backups) { |
| 42 | this.master = Optional.fromNullable(master); |
| 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 | */ |
| 60 | public Collection<NodeId> backups() { |
| 61 | return backups; |
| 62 | } |
| 63 | |
| 64 | // for Serializer |
| 65 | private ReplicaInfo() { |
| 66 | this.master = Optional.absent(); |
| 67 | this.backups = Collections.emptyList(); |
| 68 | } |
| 69 | } |