blob: f2a0c734341b7a455ad86e29f69636b622031892 [file] [log] [blame]
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -07001/*
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -08002 * Copyright 2015-2016 Open Networking Laboratory
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -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 */
16package org.onosproject.net.newresource;
17
18import com.google.common.annotations.Beta;
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070019
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070020import java.util.Optional;
21
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070022/**
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -080023 * 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 SHIMIZU1f5e5912015-08-10 17:00:00 -070027 *
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080028 * 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 SHIMIZU1f5e5912015-08-10 17:00:00 -070034 * Users of this class must keep the semantics of resources regarding the hierarchical structure.
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -080035 * For example, resource, Device:1/Port:1/VLAN ID:100, is valid, but resource,
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080036 * VLAN ID:100/Device:1/Port:1 is not valid because a link is not a sub-component of a VLAN ID.
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070037 */
38@Beta
Sho SHIMIZU2a704512016-01-26 14:41:34 -080039public interface Resource {
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070040
Sho SHIMIZU2a704512016-01-26 14:41:34 -080041 DiscreteResource ROOT = new DiscreteResource();
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070042
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070043 /**
Sho SHIMIZU446fdf02016-02-11 12:31:11 -080044 * Returns the ID of this resource.
45 *
46 * @return the ID of this resource
47 */
48 ResourceId id();
49
50 /**
Sho SHIMIZU003ed322016-02-11 12:58:42 -080051 * Checks if the type of this instance is the specified type.
52 *
53 * @param type type of resource to be checked
54 * @return true if this resource is the type of the specified type. Otherwise, false.
55 */
56 boolean isTypeOf(Class<?> type);
57
58 /**
Sho SHIMIZUb08d5862016-02-11 12:37:28 -080059 * Checks if the type of this instance is the sub-type of the specified type.
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070060 *
Sho SHIMIZUb08d5862016-02-11 12:37:28 -080061 * @param ancestor type of resource to be checked.
Sho SHIMIZU9c02f3a2016-01-29 15:11:59 -080062 * @return true if this resource is under the resource whose type is the given type.
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070063 */
Sho SHIMIZUb08d5862016-02-11 12:37:28 -080064 boolean isSubTypeOf(Class<?> ancestor);
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070065
66 /**
Sho SHIMIZU2d310222016-01-22 11:45:11 -080067 * Returns the volume of this resource.
68 *
Sho SHIMIZUf0fb3612016-01-27 11:45:09 -080069 * @param <T> type of return value
Sho SHIMIZU2d310222016-01-22 11:45:11 -080070 * @return the volume of this resource
71 */
72 // TODO: think about other naming possibilities. amount? quantity?
Sho SHIMIZU2a704512016-01-26 14:41:34 -080073 <T> T volume();
Sho SHIMIZU2d310222016-01-22 11:45:11 -080074
75 /**
Sho SHIMIZU446fdf02016-02-11 12:31:11 -080076 * Returns the last component of this instance.
77 *
78 * @return the last component of this instance.
79 * The return value is equal to the last object of {@code components()}.
80 */
81 Object last();
82
83 /**
Sho SHIMIZU19816f42016-01-29 11:32:02 -080084 * Returns the parent resource of this instance.
85 * E.g. if this resource is Link:1/VLAN ID:100, the return value is the resource for Link:1.
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070086 *
Sho SHIMIZU19816f42016-01-29 11:32:02 -080087 * @return the parent resource of this instance.
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070088 * If there is no parent, empty instance will be returned.
89 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -080090 Optional<DiscreteResource> parent();
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070091
Sho SHIMIZU9e1e9de2015-11-25 15:48:48 -080092 /**
Sho SHIMIZU19816f42016-01-29 11:32:02 -080093 * Returns a child resource of this instance with specifying the child object.
94 * It is not allowed that a continuous type resource has a child. If the instance is
95 * ContinuousResource, {@link UnsupportedOperationException} is thrown. If the given
96 * object is a {@link Class} instance, {@link IllegalArgumentException} is thrown.
Sho SHIMIZU9e1e9de2015-11-25 15:48:48 -080097 *
98 * @param child child object
Sho SHIMIZU19816f42016-01-29 11:32:02 -080099 * @return a child resource
100 * @throws IllegalArgumentException if the given object is a {@link Class} instance.
Sho SHIMIZU9e1e9de2015-11-25 15:48:48 -0800101 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800102 DiscreteResource child(Object child);
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -0800103
Sho SHIMIZU9e1e9de2015-11-25 15:48:48 -0800104 /**
Sho SHIMIZU19816f42016-01-29 11:32:02 -0800105 * Returns a child resource of this instance with specifying a child object and
106 * value. It is not allowed that a continuous type resource has a child. If the instance is
107 * ContinuousResource, {@link UnsupportedOperationException} is thrown.
Sho SHIMIZU9e1e9de2015-11-25 15:48:48 -0800108 *
109 * @param child child object
110 * @param value value
Sho SHIMIZU19816f42016-01-29 11:32:02 -0800111 * @return a child resource
Sho SHIMIZU9e1e9de2015-11-25 15:48:48 -0800112 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800113 ContinuousResource child(Class<?> child, double value);
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700114}