blob: f45f3dff1cd3a4a81b78a7943db19aa78b82ecdd [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cluster;
tom73d6d1e2014-09-17 20:08:01 -070017
Thomas Vachuska48448082016-02-19 22:14:54 -080018import org.onlab.util.Identifier;
tomfc9a4ff2014-09-22 18:22:47 -070019
Jordan Halterman0d89ea32017-06-13 10:42:36 -070020import static com.google.common.base.Preconditions.checkArgument;
21
tom73d6d1e2014-09-17 20:08:01 -070022/**
23 * Controller cluster identity.
24 */
Thomas Vachuska48448082016-02-19 22:14:54 -080025public final class NodeId extends Identifier<String> implements Comparable<NodeId> {
tomfc9a4ff2014-09-22 18:22:47 -070026
Jordan Halterman0d89ea32017-06-13 10:42:36 -070027 private static final int ID_MAX_LENGTH = 1024;
28
Thomas Vachuska48448082016-02-19 22:14:54 -080029 /**
30 * Constructor for serialization.
31 */
32 private NodeId() {
33 super("");
34 }
tomfc9a4ff2014-09-22 18:22:47 -070035
tomfc9a4ff2014-09-22 18:22:47 -070036 /**
tome4729872014-09-23 00:37:37 -070037 * Creates a new cluster node identifier from the specified string.
tomfc9a4ff2014-09-22 18:22:47 -070038 *
39 * @param id string identifier
40 */
tome4729872014-09-23 00:37:37 -070041 public NodeId(String id) {
Thomas Vachuska48448082016-02-19 22:14:54 -080042 super(id);
Jordan Halterman0d89ea32017-06-13 10:42:36 -070043 checkArgument(id.length() <= ID_MAX_LENGTH, "id exceeds maximum length " + ID_MAX_LENGTH);
tomfc9a4ff2014-09-22 18:22:47 -070044 }
45
Thomas Vachuska48448082016-02-19 22:14:54 -080046 /**
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);
tomfc9a4ff2014-09-22 18:22:47 -070054 }
55
David K. Bainbridgee676dab2015-10-23 16:13:07 -070056 @Override
57 public int compareTo(NodeId that) {
Thomas Vachuska48448082016-02-19 22:14:54 -080058 return identifier.compareTo(that.identifier);
David K. Bainbridgee676dab2015-10-23 16:13:07 -070059 }
tom73d6d1e2014-09-17 20:08:01 -070060}