Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
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.cluster; |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 17 | |
Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 18 | import org.onlab.util.Identifier; |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 19 | |
Jordan Halterman | 0d89ea3 | 2017-06-13 10:42:36 -0700 | [diff] [blame] | 20 | import static com.google.common.base.Preconditions.checkArgument; |
| 21 | |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Controller cluster identity. |
| 24 | */ |
Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 25 | public final class NodeId extends Identifier<String> implements Comparable<NodeId> { |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 26 | |
Jordan Halterman | 0d89ea3 | 2017-06-13 10:42:36 -0700 | [diff] [blame] | 27 | private static final int ID_MAX_LENGTH = 1024; |
| 28 | |
Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 29 | /** |
| 30 | * Constructor for serialization. |
| 31 | */ |
| 32 | private NodeId() { |
| 33 | super(""); |
| 34 | } |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 35 | |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 36 | /** |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 37 | * Creates a new cluster node identifier from the specified string. |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 38 | * |
| 39 | * @param id string identifier |
| 40 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 41 | public NodeId(String id) { |
Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 42 | super(id); |
Jordan Halterman | 0d89ea3 | 2017-06-13 10:42:36 -0700 | [diff] [blame] | 43 | checkArgument(id.length() <= ID_MAX_LENGTH, "id exceeds maximum length " + ID_MAX_LENGTH); |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 46 | /** |
| 47 | * Creates a new cluster node identifier from the specified string. |
| 48 | * |
| 49 | * @param id string identifier |
| 50 | * @return node id |
| 51 | */ |
| 52 | public static NodeId nodeId(String id) { |
| 53 | return new NodeId(id); |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 54 | } |
| 55 | |
David K. Bainbridge | e676dab | 2015-10-23 16:13:07 -0700 | [diff] [blame] | 56 | @Override |
| 57 | public int compareTo(NodeId that) { |
Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 58 | return identifier.compareTo(that.identifier); |
David K. Bainbridge | e676dab | 2015-10-23 16:13:07 -0700 | [diff] [blame] | 59 | } |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 60 | } |