Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -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 | */ |
Sho SHIMIZU | e18cb12 | 2016-02-22 21:04:56 -0800 | [diff] [blame] | 16 | package org.onosproject.net.resource; |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 17 | |
| 18 | import com.google.common.annotations.Beta; |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 19 | |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 20 | import java.util.Optional; |
| 21 | |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 22 | /** |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 23 | * An object that represent a resource in a network. |
| 24 | * A Resource can represents path-like hierarchical structure with its ID. An ID of resource is |
| 25 | * composed of a sequence of elementary resources that are not globally identifiable. A Resource |
| 26 | * can be globally identifiable by its ID. |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 27 | * |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 28 | * Two types of resource are considered. One is discrete type and the other is continuous type. |
| 29 | * Discrete type resource is a resource whose amount is measured as a discrete unit. VLAN ID and |
| 30 | * MPLS label are examples of discrete type resource. Continuous type resource is a resource whose |
| 31 | * amount is measured as a continuous value. Bandwidth is an example of continuous type resource. |
| 32 | * A double value is associated with a continuous type value. |
| 33 | * |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 34 | * Users of this class must keep the semantics of resources regarding the hierarchical structure. |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 35 | * For example, resource, Device:1/Port:1/VLAN ID:100, is valid, but resource, |
Sho SHIMIZU | b1f1625 | 2015-11-25 23:03:16 -0800 | [diff] [blame] | 36 | * VLAN ID:100/Device:1/Port:1 is not valid because a link is not a sub-component of a VLAN ID. |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 37 | */ |
| 38 | @Beta |
Sho SHIMIZU | 2a70451 | 2016-01-26 14:41:34 -0800 | [diff] [blame] | 39 | public interface Resource { |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 40 | |
Sho SHIMIZU | 2a70451 | 2016-01-26 14:41:34 -0800 | [diff] [blame] | 41 | DiscreteResource ROOT = new DiscreteResource(); |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 42 | |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 43 | /** |
Sho SHIMIZU | 446fdf0 | 2016-02-11 12:31:11 -0800 | [diff] [blame] | 44 | * Returns the ID of this resource. |
| 45 | * |
| 46 | * @return the ID of this resource |
| 47 | */ |
| 48 | ResourceId id(); |
| 49 | |
| 50 | /** |
Sho SHIMIZU | 74ac901 | 2016-02-12 10:03:21 -0800 | [diff] [blame] | 51 | * Returns the simple type name of this resource. |
| 52 | * |
| 53 | * Example:<br> |
| 54 | * Resource: DeviceId:1/PortNumber:1/VlanId:200<br> |
| 55 | * Simple type name: VlanId<br> |
| 56 | * |
| 57 | * @return the simple type name of this resource |
| 58 | */ |
| 59 | String simpleTypeName(); |
| 60 | |
| 61 | /** |
Sho SHIMIZU | 003ed32 | 2016-02-11 12:58:42 -0800 | [diff] [blame] | 62 | * Checks if the type of this instance is the specified type. |
| 63 | * |
| 64 | * @param type type of resource to be checked |
| 65 | * @return true if this resource is the type of the specified type. Otherwise, false. |
| 66 | */ |
| 67 | boolean isTypeOf(Class<?> type); |
| 68 | |
| 69 | /** |
Sho SHIMIZU | b08d586 | 2016-02-11 12:37:28 -0800 | [diff] [blame] | 70 | * Checks if the type of this instance is the sub-type of the specified type. |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 71 | * |
Sho SHIMIZU | b08d586 | 2016-02-11 12:37:28 -0800 | [diff] [blame] | 72 | * @param ancestor type of resource to be checked. |
Sho SHIMIZU | 9c02f3a | 2016-01-29 15:11:59 -0800 | [diff] [blame] | 73 | * @return true if this resource is under the resource whose type is the given type. |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 74 | */ |
Sho SHIMIZU | b08d586 | 2016-02-11 12:37:28 -0800 | [diff] [blame] | 75 | boolean isSubTypeOf(Class<?> ancestor); |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 76 | |
| 77 | /** |
Sho SHIMIZU | f08cb4c | 2016-02-11 18:35:59 -0800 | [diff] [blame] | 78 | * Returns value interpreted as the specified type. If the specified type is |
| 79 | * incompatible with the underlying value, an empty instance is returned. |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame] | 80 | * |
Sho SHIMIZU | f08cb4c | 2016-02-11 18:35:59 -0800 | [diff] [blame] | 81 | * @param type class instance specifying the type of return value |
| 82 | * @param <T> type of the return value |
| 83 | * @return the value of this resource as the specified type. If type mismatches, |
| 84 | * returns an empty instance. |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame] | 85 | */ |
Sho SHIMIZU | f08cb4c | 2016-02-11 18:35:59 -0800 | [diff] [blame] | 86 | <T> Optional<T> valueAs(Class<T> type); |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame] | 87 | |
| 88 | /** |
Sho SHIMIZU | 19816f4 | 2016-01-29 11:32:02 -0800 | [diff] [blame] | 89 | * Returns the parent resource of this instance. |
| 90 | * E.g. if this resource is Link:1/VLAN ID:100, the return value is the resource for Link:1. |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 91 | * |
Sho SHIMIZU | 19816f4 | 2016-01-29 11:32:02 -0800 | [diff] [blame] | 92 | * @return the parent resource of this instance. |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 93 | * If there is no parent, empty instance will be returned. |
| 94 | */ |
Sho SHIMIZU | 2a70451 | 2016-01-26 14:41:34 -0800 | [diff] [blame] | 95 | Optional<DiscreteResource> parent(); |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 96 | |
Sho SHIMIZU | 9e1e9de | 2015-11-25 15:48:48 -0800 | [diff] [blame] | 97 | /** |
Sho SHIMIZU | 19816f4 | 2016-01-29 11:32:02 -0800 | [diff] [blame] | 98 | * Returns a child resource of this instance with specifying the child object. |
| 99 | * It is not allowed that a continuous type resource has a child. If the instance is |
| 100 | * ContinuousResource, {@link UnsupportedOperationException} is thrown. If the given |
| 101 | * object is a {@link Class} instance, {@link IllegalArgumentException} is thrown. |
Sho SHIMIZU | 9e1e9de | 2015-11-25 15:48:48 -0800 | [diff] [blame] | 102 | * |
| 103 | * @param child child object |
Sho SHIMIZU | 19816f4 | 2016-01-29 11:32:02 -0800 | [diff] [blame] | 104 | * @return a child resource |
| 105 | * @throws IllegalArgumentException if the given object is a {@link Class} instance. |
Sho SHIMIZU | 9e1e9de | 2015-11-25 15:48:48 -0800 | [diff] [blame] | 106 | */ |
Sho SHIMIZU | 2a70451 | 2016-01-26 14:41:34 -0800 | [diff] [blame] | 107 | DiscreteResource child(Object child); |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 108 | |
Sho SHIMIZU | 9e1e9de | 2015-11-25 15:48:48 -0800 | [diff] [blame] | 109 | /** |
Sho SHIMIZU | 19816f4 | 2016-01-29 11:32:02 -0800 | [diff] [blame] | 110 | * Returns a child resource of this instance with specifying a child object and |
| 111 | * value. It is not allowed that a continuous type resource has a child. If the instance is |
| 112 | * ContinuousResource, {@link UnsupportedOperationException} is thrown. |
Sho SHIMIZU | 9e1e9de | 2015-11-25 15:48:48 -0800 | [diff] [blame] | 113 | * |
| 114 | * @param child child object |
| 115 | * @param value value |
Sho SHIMIZU | 19816f4 | 2016-01-29 11:32:02 -0800 | [diff] [blame] | 116 | * @return a child resource |
Sho SHIMIZU | 9e1e9de | 2015-11-25 15:48:48 -0800 | [diff] [blame] | 117 | */ |
Sho SHIMIZU | 2a70451 | 2016-01-26 14:41:34 -0800 | [diff] [blame] | 118 | ContinuousResource child(Class<?> child, double value); |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 119 | } |