Michele Santuari | 38dd82e | 2017-01-04 09:23:49 +0100 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Michele Santuari | 38dd82e | 2017-01-04 09:23:49 +0100 | [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 | */ |
| 16 | |
| 17 | package org.onosproject.net.domain; |
| 18 | |
| 19 | import org.onlab.util.Identifier; |
| 20 | |
Jordan Halterman | 0d89ea3 | 2017-06-13 10:42:36 -0700 | [diff] [blame] | 21 | import static com.google.common.base.Preconditions.checkArgument; |
| 22 | import static com.google.common.base.Preconditions.checkNotNull; |
| 23 | |
Michele Santuari | 38dd82e | 2017-01-04 09:23:49 +0100 | [diff] [blame] | 24 | /** |
| 25 | * Representation of a domain identity. |
| 26 | */ |
| 27 | public class DomainId extends Identifier<String> { |
| 28 | |
Jordan Halterman | 0d89ea3 | 2017-06-13 10:42:36 -0700 | [diff] [blame] | 29 | private static final int DOMAIN_ID_MAX_LENGTH = 1024; |
| 30 | |
Michele Santuari | 38dd82e | 2017-01-04 09:23:49 +0100 | [diff] [blame] | 31 | /** |
| 32 | * Represents the domain directly managed by ONOS. |
| 33 | */ |
| 34 | public static final DomainId LOCAL = domainId("local"); |
| 35 | |
| 36 | /** |
| 37 | * Constructor of the peer id. |
| 38 | * |
| 39 | * @param identifier of the peer |
| 40 | */ |
| 41 | public DomainId(String identifier) { |
| 42 | super(identifier); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Creates a peer id from the string identifier. |
| 47 | * |
| 48 | * @param identifier string identifier |
| 49 | * @return instance of the class DomainId |
| 50 | */ |
| 51 | public static DomainId domainId(String identifier) { |
Jordan Halterman | 0d89ea3 | 2017-06-13 10:42:36 -0700 | [diff] [blame] | 52 | checkNotNull(identifier, "identifier cannot be null"); |
| 53 | checkArgument(identifier.length() <= DOMAIN_ID_MAX_LENGTH, |
| 54 | "identifier exceeds maximum length " + DOMAIN_ID_MAX_LENGTH); |
Michele Santuari | 38dd82e | 2017-01-04 09:23:49 +0100 | [diff] [blame] | 55 | return new DomainId(identifier); |
| 56 | } |
| 57 | } |