Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 1 | /* |
Sho SHIMIZU | 7e6d18e | 2016-01-07 18:44:33 -0800 | [diff] [blame] | 2 | * Copyright 2015-2016 Open Networking Laboratory |
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 | */ |
| 16 | package org.onosproject.net.newresource; |
| 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.List; |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 21 | import java.util.Optional; |
| 22 | |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 23 | /** |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 24 | * An object that represent a resource in a network. |
| 25 | * A Resource can represents path-like hierarchical structure with its ID. An ID of resource is |
| 26 | * composed of a sequence of elementary resources that are not globally identifiable. A Resource |
| 27 | * can be globally identifiable by its ID. |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 28 | * |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 29 | * Two types of resource are considered. One is discrete type and the other is continuous type. |
| 30 | * Discrete type resource is a resource whose amount is measured as a discrete unit. VLAN ID and |
| 31 | * MPLS label are examples of discrete type resource. Continuous type resource is a resource whose |
| 32 | * amount is measured as a continuous value. Bandwidth is an example of continuous type resource. |
| 33 | * A double value is associated with a continuous type value. |
| 34 | * |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 35 | * 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] | 36 | * 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] | 37 | * 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] | 38 | */ |
| 39 | @Beta |
Sho SHIMIZU | 2a70451 | 2016-01-26 14:41:34 -0800 | [diff] [blame] | 40 | public interface Resource { |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 41 | |
Sho SHIMIZU | 2a70451 | 2016-01-26 14:41:34 -0800 | [diff] [blame] | 42 | DiscreteResource ROOT = new DiscreteResource(); |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 43 | |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 44 | /** |
Sho SHIMIZU | 19816f4 | 2016-01-29 11:32:02 -0800 | [diff] [blame] | 45 | * Returns the components of this resource. |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 46 | * |
Sho SHIMIZU | 19816f4 | 2016-01-29 11:32:02 -0800 | [diff] [blame] | 47 | * @return the components of this resource |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 48 | */ |
Sho SHIMIZU | 2a70451 | 2016-01-26 14:41:34 -0800 | [diff] [blame] | 49 | List<Object> components(); |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 50 | |
| 51 | /** |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame] | 52 | * Returns the volume of this resource. |
| 53 | * |
Sho SHIMIZU | f0fb361 | 2016-01-27 11:45:09 -0800 | [diff] [blame] | 54 | * @param <T> type of return value |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame] | 55 | * @return the volume of this resource |
| 56 | */ |
| 57 | // TODO: think about other naming possibilities. amount? quantity? |
Sho SHIMIZU | 2a70451 | 2016-01-26 14:41:34 -0800 | [diff] [blame] | 58 | <T> T volume(); |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame] | 59 | |
| 60 | /** |
Sho SHIMIZU | 19816f4 | 2016-01-29 11:32:02 -0800 | [diff] [blame] | 61 | * Returns the parent resource of this instance. |
| 62 | * 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] | 63 | * |
Sho SHIMIZU | 19816f4 | 2016-01-29 11:32:02 -0800 | [diff] [blame] | 64 | * @return the parent resource of this instance. |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 65 | * If there is no parent, empty instance will be returned. |
| 66 | */ |
Sho SHIMIZU | 2a70451 | 2016-01-26 14:41:34 -0800 | [diff] [blame] | 67 | Optional<DiscreteResource> parent(); |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 68 | |
Sho SHIMIZU | 9e1e9de | 2015-11-25 15:48:48 -0800 | [diff] [blame] | 69 | /** |
Sho SHIMIZU | 19816f4 | 2016-01-29 11:32:02 -0800 | [diff] [blame] | 70 | * Returns a child resource of this instance with specifying the child object. |
| 71 | * It is not allowed that a continuous type resource has a child. If the instance is |
| 72 | * ContinuousResource, {@link UnsupportedOperationException} is thrown. If the given |
| 73 | * object is a {@link Class} instance, {@link IllegalArgumentException} is thrown. |
Sho SHIMIZU | 9e1e9de | 2015-11-25 15:48:48 -0800 | [diff] [blame] | 74 | * |
| 75 | * @param child child object |
Sho SHIMIZU | 19816f4 | 2016-01-29 11:32:02 -0800 | [diff] [blame] | 76 | * @return a child resource |
| 77 | * @throws IllegalArgumentException if the given object is a {@link Class} instance. |
Sho SHIMIZU | 9e1e9de | 2015-11-25 15:48:48 -0800 | [diff] [blame] | 78 | */ |
Sho SHIMIZU | 2a70451 | 2016-01-26 14:41:34 -0800 | [diff] [blame] | 79 | DiscreteResource child(Object child); |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 80 | |
Sho SHIMIZU | 9e1e9de | 2015-11-25 15:48:48 -0800 | [diff] [blame] | 81 | /** |
Sho SHIMIZU | 19816f4 | 2016-01-29 11:32:02 -0800 | [diff] [blame] | 82 | * Returns a child resource of this instance with specifying a child object and |
| 83 | * value. It is not allowed that a continuous type resource has a child. If the instance is |
| 84 | * ContinuousResource, {@link UnsupportedOperationException} is thrown. |
Sho SHIMIZU | 9e1e9de | 2015-11-25 15:48:48 -0800 | [diff] [blame] | 85 | * |
| 86 | * @param child child object |
| 87 | * @param value value |
Sho SHIMIZU | 19816f4 | 2016-01-29 11:32:02 -0800 | [diff] [blame] | 88 | * @return a child resource |
Sho SHIMIZU | 9e1e9de | 2015-11-25 15:48:48 -0800 | [diff] [blame] | 89 | */ |
Sho SHIMIZU | 2a70451 | 2016-01-26 14:41:34 -0800 | [diff] [blame] | 90 | ContinuousResource child(Class<?> child, double value); |
Sho SHIMIZU | 0112078 | 2015-08-21 15:48:43 -0700 | [diff] [blame] | 91 | |
| 92 | /** |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 93 | * Returns the last component of this instance. |
| 94 | * |
| 95 | * @return the last component of this instance. |
| 96 | * The return value is equal to the last object of {@code components()}. |
| 97 | */ |
Sho SHIMIZU | 2a70451 | 2016-01-26 14:41:34 -0800 | [diff] [blame] | 98 | Object last(); |
Sho SHIMIZU | 7e6d18e | 2016-01-07 18:44:33 -0800 | [diff] [blame] | 99 | |
| 100 | /** |
Sho SHIMIZU | 19816f4 | 2016-01-29 11:32:02 -0800 | [diff] [blame] | 101 | * Returns the ID of this resource. |
Sho SHIMIZU | 7e6d18e | 2016-01-07 18:44:33 -0800 | [diff] [blame] | 102 | * |
Sho SHIMIZU | 19816f4 | 2016-01-29 11:32:02 -0800 | [diff] [blame] | 103 | * @return the ID of this resource |
Sho SHIMIZU | 7e6d18e | 2016-01-07 18:44:33 -0800 | [diff] [blame] | 104 | */ |
Sho SHIMIZU | 2a70451 | 2016-01-26 14:41:34 -0800 | [diff] [blame] | 105 | ResourceId id(); |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 106 | } |