Avantika-Huawei | 73862d4 | 2016-05-12 18:58:06 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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.pce.pceservice; |
| 17 | |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 18 | import org.onlab.util.Identifier; |
Avantika-Huawei | 73862d4 | 2016-05-12 18:58:06 +0530 | [diff] [blame] | 19 | import org.onosproject.net.resource.ResourceConsumer; |
| 20 | |
| 21 | import com.google.common.annotations.Beta; |
Carmelo Cascone | f36a7ae | 2016-05-15 12:46:19 -0700 | [diff] [blame] | 22 | import org.onosproject.net.resource.ResourceConsumerId; |
Avantika-Huawei | 73862d4 | 2016-05-12 18:58:06 +0530 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Tunnel resource consumer identifier suitable to be used as a consumer id for |
| 26 | * resource allocations. |
| 27 | */ |
| 28 | @Beta |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 29 | public final class TunnelConsumerId extends Identifier<Long> implements ResourceConsumer { |
Avantika-Huawei | 73862d4 | 2016-05-12 18:58:06 +0530 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Creates a tunnel resource consumer identifier from the specified long value. |
| 33 | * |
| 34 | * @param value long value to be used as tunnel resource consumer id |
| 35 | * @return tunnel resource consumer identifier |
| 36 | */ |
| 37 | public static TunnelConsumerId valueOf(long value) { |
| 38 | return new TunnelConsumerId(value); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Initializes object for serializer. |
| 43 | */ |
| 44 | public TunnelConsumerId() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 45 | super(0L); |
Avantika-Huawei | 73862d4 | 2016-05-12 18:58:06 +0530 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Constructs the tunnel resource consumer id corresponding to a given long |
| 50 | * value. |
| 51 | * |
| 52 | * @param value the underlying value in long representation of this tunnel |
| 53 | * resource consumer id |
| 54 | */ |
| 55 | public TunnelConsumerId(long value) { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 56 | super(value); |
Avantika-Huawei | 73862d4 | 2016-05-12 18:58:06 +0530 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /** |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 60 | * Returns the backing identifier value. |
Avantika-Huawei | 73862d4 | 2016-05-12 18:58:06 +0530 | [diff] [blame] | 61 | * |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 62 | * @return value backing identifier value |
Avantika-Huawei | 73862d4 | 2016-05-12 18:58:06 +0530 | [diff] [blame] | 63 | */ |
| 64 | public long value() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 65 | return identifier; |
Avantika-Huawei | 73862d4 | 2016-05-12 18:58:06 +0530 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public String toString() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 70 | return "0x" + Long.toHexString(identifier); |
Avantika-Huawei | 73862d4 | 2016-05-12 18:58:06 +0530 | [diff] [blame] | 71 | } |
| 72 | |
Carmelo Cascone | f36a7ae | 2016-05-15 12:46:19 -0700 | [diff] [blame] | 73 | @Override |
| 74 | public ResourceConsumerId consumerId() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 75 | return ResourceConsumerId.of(this); |
Carmelo Cascone | f36a7ae | 2016-05-15 12:46:19 -0700 | [diff] [blame] | 76 | } |
Avantika-Huawei | 73862d4 | 2016-05-12 18:58:06 +0530 | [diff] [blame] | 77 | } |