Madan Jampani | ec1df02 | 2015-10-13 21:23:03 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2015 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 | */ |
| 16 | package org.onosproject.cluster; |
| 17 | |
| 18 | import java.util.Collection; |
| 19 | import java.util.Set; |
| 20 | |
| 21 | import com.google.common.collect.ImmutableSet; |
| 22 | |
| 23 | import static com.google.common.base.Preconditions.checkNotNull; |
| 24 | |
| 25 | /** |
| 26 | * A data partition. |
| 27 | * <p> |
| 28 | * Partition represents a slice of the data space and is made up of a collection |
| 29 | * of {@link org.onosproject.cluster.ControllerNode nodes} |
| 30 | * that all maintain copies of this data. |
| 31 | */ |
| 32 | public class Partition { |
| 33 | |
| 34 | private final String name; |
| 35 | private final Set<NodeId> members; |
| 36 | |
| 37 | private Partition() { |
| 38 | name = null; |
| 39 | members = null; |
| 40 | } |
| 41 | |
| 42 | public Partition(String name, Collection<NodeId> members) { |
| 43 | this.name = checkNotNull(name); |
| 44 | this.members = ImmutableSet.copyOf(checkNotNull(members)); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns the partition name. |
| 49 | * <p> |
| 50 | * Each partition is identified by a unique name. |
| 51 | * @return partition name |
| 52 | */ |
| 53 | public String getName() { |
| 54 | return this.name; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Returns the collection of controller node identifiers that make up this partition. |
| 59 | * @return collection of controller node identifiers |
| 60 | */ |
| 61 | public Collection<NodeId> getMembers() { |
| 62 | return this.members; |
| 63 | } |
| 64 | } |