blob: 332236295953c3a0d34302c90f0c701a3f2ba5f4 [file] [log] [blame]
Sho SHIMIZUabd849c2015-07-14 09:14:12 -07001/*
2 * Copyright 2015 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 */
16package org.onosproject.net.newresource;
17
18import com.google.common.annotations.Beta;
19
20import java.util.Collection;
21import java.util.List;
22import java.util.Optional;
23
24/**
25 * Service for allocating/releasing resource(s) and retrieving allocation(s) and availability.
26 */
27@Beta
28public interface ResourceService {
29 /**
30 * Allocates the specified resource to the specified user.
31 *
32 * @param consumer resource user which the resource is allocated to
33 * @param resource resource to be allocated
34 * @param <S> type of the subject which this resource belongs to
35 * @param <T> type of the resource
36 * @return allocation information enclosed by Optional. If the allocation fails, the return value is empty
37 */
38 <S, T> Optional<ResourceAllocation<S, T>> allocate(ResourceConsumer consumer, Resource<S, T> resource);
39
40 /**
41 * Transactionally allocates the specified resources to the specified user.
42 * All allocations are made when this method succeeds, or no allocation is made when this method fails.
43 *
44 * @param consumer resource user which the resources are allocated to
45 * @param resources resources to be allocated
46 * @return non-empty list of allocation information if succeeded, otherwise empty list
47 */
48 List<ResourceAllocation<?, ?>> allocate(ResourceConsumer consumer, List<? extends Resource<?, ?>> resources);
49
50 /**
51 * Transactionally allocates the specified resources to the specified user.
52 * All allocations are made when this method succeeds, or no allocation is made when this method fails.
53 *
54 * @param consumer resource user which the resources are allocated to
55 * @param resources resources to be allocated
56 * @return non-empty list of allocation information if succeeded, otherwise empty list
57 */
58 List<ResourceAllocation<?, ?>> allocate(ResourceConsumer consumer, Resource<?, ?>... resources);
59
60 /**
61 * Releases the specified resource allocation.
62 *
63 * @param allocation resource allocation to be released
64 * @param <S> type of the subject which this resource belongs to
65 * @param <T> type of the device resource
66 * @return true if succeeded, otherwise false
67 */
68 <S, T> boolean release(ResourceAllocation<S, T> allocation);
69
70 /**
71 * Transactionally releases the specified resource allocations.
72 * All allocations are released when this method succeeded, or no allocation is released when this method fails.
73 *
74 * @param allocations resource allocations to be released
75 * @return true if succeeded, otherwise false
76 */
77 boolean release(List<? extends ResourceAllocation<?, ?>> allocations);
78
79 /**
80 * Transactionally releases the specified resource allocations.
81 * All allocations are released when this method succeeded, or no allocation is released when this method fails.
82 *
83 * @param allocations resource allocations to be released
84 * @return true if succeeded, otherwise false
85 */
86 boolean release(ResourceAllocation<?, ?>... allocations);
87
88 /**
89 * Transactionally releases the resources allocated to the specified consumer.
90 * All allocations are released when this method succeeded, or no allocation is released when this method fails.
91 *
92 * @param consumer consumer whose allocated resources are to be released
93 * @return true if succeeded, otherwise false
94 */
95 boolean release(ResourceConsumer consumer);
96
97 /**
98 * Returns allocated resources in the specified subject regarding the specified resource type.
99 *
100 * @param subject subject where resource allocations are obtained
101 * @param cls class to specify a type of resource
102 * @param <S> type of the subject
103 * @param <T> type of the resource
104 * @return non-empty collection of resource allocations if resources are allocated with the subject and type,
105 * empty collection if no resource is allocated with the subject and type
106 */
107 <S, T> Collection<ResourceAllocation<S, T>> getResourceAllocations(S subject, Class<T> cls);
108
109 /**
110 * Returns resources allocated to the specified consumer.
111 *
112 * @param consumer consumer whose allocated resources are to be returned
113 * @return resources allocated to the consumer
114 */
115 Collection<ResourceAllocation<?, ?>> getResourceAllocations(ResourceConsumer consumer);
116
117 /**
118 * Returns the availability of the specified device resource.
119 *
120 * @param resource resource to check the availability
121 * @param <S> type of the subject
122 * @param <T> type of the resource
123 * @return true if available, otherwise false
124 */
125 <S, T> boolean isAvailable(Resource<S, T> resource);
126
127 // TODO: listener and event mechanism need to be considered
128}