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.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 | |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 20 | /** |
| 21 | * Controller cluster identity. |
| 22 | */ |
Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 23 | public final class NodeId extends Identifier<String> implements Comparable<NodeId> { |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 24 | |
Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 25 | /** |
| 26 | * Constructor for serialization. |
| 27 | */ |
| 28 | private NodeId() { |
| 29 | super(""); |
| 30 | } |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 31 | |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 32 | /** |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 33 | * Creates a new cluster node identifier from the specified string. |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 34 | * |
| 35 | * @param id string identifier |
| 36 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 37 | public NodeId(String id) { |
Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 38 | super(id); |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 41 | /** |
| 42 | * Creates a new cluster node identifier from the specified string. |
| 43 | * |
| 44 | * @param id string identifier |
| 45 | * @return node id |
| 46 | */ |
| 47 | public static NodeId nodeId(String id) { |
| 48 | return new NodeId(id); |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 49 | } |
| 50 | |
David K. Bainbridge | e676dab | 2015-10-23 16:13:07 -0700 | [diff] [blame] | 51 | @Override |
| 52 | public int compareTo(NodeId that) { |
Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 53 | return identifier.compareTo(that.identifier); |
David K. Bainbridge | e676dab | 2015-10-23 16:13:07 -0700 | [diff] [blame] | 54 | } |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 55 | } |