Yuta HIGUCHI | b25f4da | 2014-10-16 15:09:26 -0700 | [diff] [blame] | 1 | package org.onlab.onos.store.flow; |
| 2 | |
| 3 | import static com.google.common.base.Preconditions.checkNotNull; |
| 4 | |
| 5 | import java.util.Collection; |
| 6 | import java.util.Collections; |
| 7 | |
| 8 | import org.onlab.onos.cluster.NodeId; |
| 9 | |
| 10 | import com.google.common.base.Optional; |
| 11 | |
| 12 | /** |
| 13 | * Class to represent placement information about Master/Backup copy. |
| 14 | */ |
| 15 | public final class ReplicaInfo { |
| 16 | |
| 17 | private final Optional<NodeId> master; |
| 18 | private final Collection<NodeId> backups; |
| 19 | |
| 20 | /** |
| 21 | * Creates a ReplicaInfo instance. |
| 22 | * |
| 23 | * @param master NodeId of the node where the master copy should be |
| 24 | * @param backups collection of NodeId, where backup copies should be placed |
| 25 | */ |
| 26 | public ReplicaInfo(NodeId master, Collection<NodeId> backups) { |
| 27 | this.master = Optional.fromNullable(master); |
| 28 | this.backups = checkNotNull(backups); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Returns the NodeId, if there is a Node where the master copy should be. |
| 33 | * |
| 34 | * @return NodeId, where the master copy should be placed |
| 35 | */ |
| 36 | public Optional<NodeId> master() { |
| 37 | return master; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Returns the collection of NodeId, where backup copies should be placed. |
| 42 | * |
| 43 | * @return collection of NodeId, where backup copies should be placed |
| 44 | */ |
| 45 | public Collection<NodeId> backups() { |
| 46 | return backups; |
| 47 | } |
| 48 | |
| 49 | // for Serializer |
| 50 | private ReplicaInfo() { |
| 51 | this.master = Optional.absent(); |
| 52 | this.backups = Collections.emptyList(); |
| 53 | } |
| 54 | } |