Sho SHIMIZU
Committed by Sho Shimizu

Move inner classes to upper level

Rename as follows.
- ResourceId.Discrete -> DiscreteResourceId
- ResourceId.Continuous -> ContinuousResourceId
- Resource.Discrete -> DiscreteResource
- Resource.Continuous -> ContinuousResource

Change-Id: I80e59d1eec07128743bacc582a8725bd4d5489b4
...@@ -34,6 +34,7 @@ import org.onosproject.cli.AbstractShellCommand; ...@@ -34,6 +34,7 @@ import org.onosproject.cli.AbstractShellCommand;
34 import org.onosproject.net.DeviceId; 34 import org.onosproject.net.DeviceId;
35 import org.onosproject.net.PortNumber; 35 import org.onosproject.net.PortNumber;
36 import org.onosproject.net.TributarySlot; 36 import org.onosproject.net.TributarySlot;
37 +import org.onosproject.net.newresource.ContinuousResource;
37 import org.onosproject.net.newresource.Resource; 38 import org.onosproject.net.newresource.Resource;
38 import org.onosproject.net.newresource.ResourceService; 39 import org.onosproject.net.newresource.ResourceService;
39 40
...@@ -112,10 +113,10 @@ public class ResourcesCommand extends AbstractShellCommand { ...@@ -112,10 +113,10 @@ public class ResourcesCommand extends AbstractShellCommand {
112 return; 113 return;
113 } 114 }
114 115
115 - if (resource instanceof Resource.Continuous) { 116 + if (resource instanceof ContinuousResource) {
116 print("%s%s: %f", Strings.repeat(" ", level), 117 print("%s%s: %f", Strings.repeat(" ", level),
117 resource.last(), 118 resource.last(),
118 - ((Resource.Continuous) resource).value()); 119 + ((ContinuousResource) resource).value());
119 // Continuous resource is terminal node, stop here 120 // Continuous resource is terminal node, stop here
120 return; 121 return;
121 } else { 122 } else {
...@@ -144,7 +145,7 @@ public class ResourcesCommand extends AbstractShellCommand { ...@@ -144,7 +145,7 @@ public class ResourcesCommand extends AbstractShellCommand {
144 List<Resource> nonAggregatable = new ArrayList<>(); 145 List<Resource> nonAggregatable = new ArrayList<>();
145 146
146 for (Resource r : children) { 147 for (Resource r : children) {
147 - if (r instanceof Resource.Continuous) { 148 + if (r instanceof ContinuousResource) {
148 // non-aggregatable terminal node 149 // non-aggregatable terminal node
149 nonAggregatable.add(r); 150 nonAggregatable.add(r);
150 } else if (aggregatableTypes.contains(r.last().getClass())) { 151 } else if (aggregatableTypes.contains(r.last().getClass())) {
......
1 +/*
2 + * Copyright 2016 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.net.newresource;
17 +
18 +import com.google.common.annotations.Beta;
19 +
20 +import java.util.Objects;
21 +
22 +/**
23 + * Represents a resource path which specifies a resource which can be measured
24 + * as continuous value. Bandwidth of a link is an example of the resource.
25 + * <p>
26 + * Note: This class is exposed to the public, but intended to be used in the resource API
27 + * implementation only. It is not for resource API user.
28 + */
29 +@Beta
30 +// TODO: consider how to restrict the visibility
31 +public final class ContinuousResource extends Resource {
32 + private final double value;
33 +
34 + ContinuousResource(ResourceId id, double value) {
35 + super(id);
36 + this.value = value;
37 + }
38 +
39 + /**
40 + * The user of this methods must receive the return value as Double or double.
41 + * Otherwise, this methods throws an exception.
42 + *
43 + * @param <T> type of the return value
44 + * @return the volume of this resource
45 + */
46 + @SuppressWarnings("unchecked")
47 + @Override
48 + public <T> T volume() {
49 + return (T) Double.valueOf(value);
50 + }
51 +
52 + @Override
53 + public int hashCode() {
54 + return Objects.hash(id(), value);
55 + }
56 +
57 + @Override
58 + public boolean equals(Object obj) {
59 + if (this == obj) {
60 + return true;
61 + }
62 + if (obj == null || getClass() != obj.getClass()) {
63 + return false;
64 + }
65 + final ContinuousResource other = (ContinuousResource) obj;
66 + return Objects.equals(this.id(), other.id())
67 + && Objects.equals(this.value, other.value);
68 + }
69 +
70 + /**
71 + * Returns the value of the resource amount.
72 + *
73 + * @return the value of the resource amount
74 + */
75 + // FIXME: overlapping a purpose with volume()
76 + public double value() {
77 + return value;
78 + }
79 +}
1 +/*
2 + * Copyright 2016 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.net.newresource;
17 +
18 +import com.google.common.annotations.Beta;
19 +import com.google.common.collect.ImmutableList;
20 +
21 +import static com.google.common.base.Preconditions.checkNotNull;
22 +
23 +/**
24 + * ResourceId for {@link ContinuousResource}
25 + *
26 + * Note: This class is exposed to the public, but intended to be used in the resource API
27 + * implementation only. It is not for resource API user.
28 + */
29 +@Beta
30 +// TODO: consider how to restrict the visibility
31 +public final class ContinuousResourceId extends ResourceId {
32 + // for printing purpose only (used in toString() implementation)
33 + private final String name;
34 +
35 + ContinuousResourceId(ImmutableList<Object> components, String name) {
36 + super(components);
37 + this.name = checkNotNull(name);
38 + }
39 +
40 + @Override
41 + public String toString() {
42 + // due to performance consideration, the value might need to be stored in a field
43 + return ImmutableList.builder()
44 + .addAll(components.subList(0, components.size() - 1))
45 + .add(name)
46 + .build().toString();
47 + }
48 +}
1 +/*
2 + * Copyright 2016 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.net.newresource;
17 +
18 +import com.google.common.annotations.Beta;
19 +
20 +import java.util.Objects;
21 +
22 +/**
23 + * Represents a resource path which specifies a resource which can be measured
24 + * as a discrete unit. A VLAN ID and a MPLS label of a link are examples of the resource.
25 + * <p>
26 + * Note: This class is exposed to the public, but intended to be used in the resource API
27 + * implementation only. It is not for resource API user.
28 + * </p>
29 + */
30 +@Beta
31 +// TODO: consider how to restrict the visibility
32 +public final class DiscreteResource extends Resource {
33 + protected DiscreteResource() {
34 + super();
35 + }
36 +
37 + DiscreteResource(ResourceId id) {
38 + super(id);
39 + }
40 +
41 + /**
42 + * The user of this methods must receive the return value as the correct type.
43 + * Otherwise, this methods throws an exception.
44 + *
45 + * @param <T> type of the return value
46 + * @return the volume of this resource
47 + */
48 + @SuppressWarnings("unchecked")
49 + @Override
50 + // TODO: consider receiving Class<T> as an argument. Which approach is convenient?
51 + public <T> T volume() {
52 + return (T) last();
53 + }
54 +
55 + @Override
56 + public int hashCode() {
57 + // the value returing from volume() is excluded due to optimization
58 + return id().hashCode();
59 + }
60 +
61 + @Override
62 + public boolean equals(Object obj) {
63 + if (this == obj) {
64 + return true;
65 + }
66 + if (obj == null || getClass() != obj.getClass()) {
67 + return false;
68 + }
69 + final DiscreteResource other = (DiscreteResource) obj;
70 + // the value returing from volume() is excluded due to optimization
71 + return Objects.equals(this.id(), other.id());
72 + }
73 +}
1 +/*
2 + * Copyright 2016 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.net.newresource;
17 +
18 +import com.google.common.annotations.Beta;
19 +import com.google.common.collect.ImmutableList;
20 +
21 +/**
22 + * ResourceId for {@link DiscreteResource}.
23 + *
24 + * Note: This class is exposed to the public, but intended to be used in the resource API
25 + * implementation only. It is not for resource API user.
26 + */
27 +@Beta
28 +// TODO: consider how to restrict the visibility
29 +public final class DiscreteResourceId extends ResourceId {
30 + DiscreteResourceId(ImmutableList<Object> components) {
31 + super(components);
32 + }
33 +
34 + DiscreteResourceId() {
35 + super();
36 + }
37 +}
...@@ -21,7 +21,6 @@ import org.onosproject.net.DeviceId; ...@@ -21,7 +21,6 @@ import org.onosproject.net.DeviceId;
21 import org.onosproject.net.PortNumber; 21 import org.onosproject.net.PortNumber;
22 22
23 import java.util.List; 23 import java.util.List;
24 -import java.util.Objects;
25 import java.util.Optional; 24 import java.util.Optional;
26 25
27 import static com.google.common.base.Preconditions.checkArgument; 26 import static com.google.common.base.Preconditions.checkArgument;
...@@ -47,13 +46,13 @@ import static com.google.common.base.Preconditions.checkState; ...@@ -47,13 +46,13 @@ import static com.google.common.base.Preconditions.checkState;
47 @Beta 46 @Beta
48 public abstract class Resource { 47 public abstract class Resource {
49 48
50 - private final Discrete parent; 49 + private final DiscreteResource parent;
51 private final ResourceId id; 50 private final ResourceId id;
52 51
53 - public static final Discrete ROOT = new Discrete(); 52 + public static final DiscreteResource ROOT = new DiscreteResource();
54 53
55 public static Resource discrete(DeviceId device) { 54 public static Resource discrete(DeviceId device) {
56 - return new Discrete(ResourceId.discrete(device)); 55 + return new DiscreteResource(ResourceId.discrete(device));
57 } 56 }
58 57
59 /** 58 /**
...@@ -64,7 +63,7 @@ public abstract class Resource { ...@@ -64,7 +63,7 @@ public abstract class Resource {
64 * @return resource path instance 63 * @return resource path instance
65 */ 64 */
66 public static Resource discrete(DeviceId device, Object... components) { 65 public static Resource discrete(DeviceId device, Object... components) {
67 - return new Discrete(ResourceId.discrete(device, components)); 66 + return new DiscreteResource(ResourceId.discrete(device, components));
68 } 67 }
69 68
70 /** 69 /**
...@@ -76,7 +75,7 @@ public abstract class Resource { ...@@ -76,7 +75,7 @@ public abstract class Resource {
76 * @return resource path instance 75 * @return resource path instance
77 */ 76 */
78 public static Resource discrete(DeviceId device, PortNumber port, Object... components) { 77 public static Resource discrete(DeviceId device, PortNumber port, Object... components) {
79 - return new Discrete(ResourceId.discrete(device, port, components)); 78 + return new DiscreteResource(ResourceId.discrete(device, port, components));
80 } 79 }
81 80
82 /** 81 /**
...@@ -93,7 +92,7 @@ public abstract class Resource { ...@@ -93,7 +92,7 @@ public abstract class Resource {
93 checkArgument(components.length > 0, 92 checkArgument(components.length > 0,
94 "Length of components must be greater thant 0, but " + components.length); 93 "Length of components must be greater thant 0, but " + components.length);
95 94
96 - return new Continuous(ResourceId.continuous(device, components), value); 95 + return new ContinuousResource(ResourceId.continuous(device, components), value);
97 } 96 }
98 97
99 /** 98 /**
...@@ -108,7 +107,7 @@ public abstract class Resource { ...@@ -108,7 +107,7 @@ public abstract class Resource {
108 * @return resource path instance 107 * @return resource path instance
109 */ 108 */
110 public static Resource continuous(double value, DeviceId device, PortNumber port, Object... components) { 109 public static Resource continuous(double value, DeviceId device, PortNumber port, Object... components) {
111 - return new Continuous(ResourceId.continuous(device, port, components), value); 110 + return new ContinuousResource(ResourceId.continuous(device, port, components), value);
112 } 111 }
113 112
114 /** 113 /**
...@@ -123,12 +122,12 @@ public abstract class Resource { ...@@ -123,12 +122,12 @@ public abstract class Resource {
123 if (id.components.size() == 1) { 122 if (id.components.size() == 1) {
124 this.parent = ROOT; 123 this.parent = ROOT;
125 } else { 124 } else {
126 - this.parent = new Discrete(id.parent()); 125 + this.parent = new DiscreteResource(id.parent());
127 } 126 }
128 } 127 }
129 128
130 // for serialization 129 // for serialization
131 - private Resource() { 130 + protected Resource() {
132 this.parent = null; 131 this.parent = null;
133 this.id = ResourceId.ROOT; 132 this.id = ResourceId.ROOT;
134 } 133 }
...@@ -157,7 +156,7 @@ public abstract class Resource { ...@@ -157,7 +156,7 @@ public abstract class Resource {
157 * @return the parent resource path of this instance. 156 * @return the parent resource path of this instance.
158 * If there is no parent, empty instance will be returned. 157 * If there is no parent, empty instance will be returned.
159 */ 158 */
160 - public Optional<Discrete> parent() { 159 + public Optional<DiscreteResource> parent() {
161 return Optional.ofNullable(parent); 160 return Optional.ofNullable(parent);
162 } 161 }
163 162
...@@ -169,9 +168,9 @@ public abstract class Resource { ...@@ -169,9 +168,9 @@ public abstract class Resource {
169 * @return a child resource path 168 * @return a child resource path
170 */ 169 */
171 public Resource child(Object child) { 170 public Resource child(Object child) {
172 - checkState(this instanceof Discrete); 171 + checkState(this instanceof DiscreteResource);
173 172
174 - return new Discrete(id().child(child)); 173 + return new DiscreteResource(id().child(child));
175 } 174 }
176 175
177 /** 176 /**
...@@ -183,9 +182,9 @@ public abstract class Resource { ...@@ -183,9 +182,9 @@ public abstract class Resource {
183 * @return a child resource path 182 * @return a child resource path
184 */ 183 */
185 public Resource child(Object child, double value) { 184 public Resource child(Object child, double value) {
186 - checkState(this instanceof Discrete); 185 + checkState(this instanceof DiscreteResource);
187 186
188 - return new Continuous(id.child(child), value); 187 + return new ContinuousResource(id.child(child), value);
189 } 188 }
190 189
191 /** 190 /**
...@@ -218,114 +217,4 @@ public abstract class Resource { ...@@ -218,114 +217,4 @@ public abstract class Resource {
218 .toString(); 217 .toString();
219 } 218 }
220 219
221 - /**
222 - * Represents a resource path which specifies a resource which can be measured
223 - * as a discrete unit. A VLAN ID and a MPLS label of a link are examples of the resource.
224 - * <p>
225 - * Note: This class is exposed to the public, but intended to be used in the resource API
226 - * implementation only. It is not for resource API user.
227 - * </p>
228 - */
229 - @Beta
230 - public static final class Discrete extends Resource {
231 - private Discrete() {
232 - super();
233 - }
234 -
235 - private Discrete(ResourceId id) {
236 - super(id);
237 - }
238 -
239 - /**
240 - * The user of this methods must receive the return value as the correct type.
241 - * Otherwise, this methods throws an exception.
242 - *
243 - * @param <T> type of the return value
244 - * @return the volume of this resource
245 - */
246 - @SuppressWarnings("unchecked")
247 - @Override
248 - // TODO: consider receiving Class<T> as an argument. Which approach is convenient?
249 - public <T> T volume() {
250 - return (T) last();
251 - }
252 -
253 - @Override
254 - public int hashCode() {
255 - // the value returing from volume() is excluded due to optimization
256 - return id().hashCode();
257 - }
258 -
259 - @Override
260 - public boolean equals(Object obj) {
261 - if (this == obj) {
262 - return true;
263 - }
264 - if (obj == null || getClass() != obj.getClass()) {
265 - return false;
266 - }
267 - final Discrete other = (Discrete) obj;
268 - // the value returing from volume() is excluded due to optimization
269 - return Objects.equals(this.id(), other.id());
270 - }
271 - }
272 -
273 - /**
274 - * Represents a resource path which specifies a resource which can be measured
275 - * as continuous value. Bandwidth of a link is an example of the resource.
276 - * <p>
277 - * Note: This class is exposed to the public, but intended to be used in the resource API
278 - * implementation only. It is not for resource API user.
279 - */
280 - @Beta
281 - public static final class Continuous extends Resource {
282 - private final double value;
283 -
284 - private Continuous(ResourceId id, double value) {
285 - super(id);
286 - this.value = value;
287 - }
288 -
289 - /**
290 - * The user of this methods must receive the return value as Double or double.
291 - * Otherwise, this methods throws an exception.
292 - *
293 - * @param <T> type of the return value
294 - * @return the volume of this resource
295 - */
296 - @SuppressWarnings("unchecked")
297 - @Override
298 - public <T> T volume() {
299 - return (T) Double.valueOf(value);
300 - }
301 -
302 - @Override
303 - public int hashCode() {
304 - return Objects.hash(id(), value);
305 - }
306 -
307 - @Override
308 - public boolean equals(Object obj) {
309 - if (this == obj) {
310 - return true;
311 - }
312 - if (obj == null || getClass() != obj.getClass()) {
313 - return false;
314 - }
315 - final Continuous other = (Continuous) obj;
316 - return Objects.equals(this.id(), other.id())
317 - && Objects.equals(this.value, other.value);
318 - }
319 -
320 - /**
321 - * Returns the value of the resource amount.
322 - *
323 - * @return the value of the resource amount
324 - */
325 - // FIXME: overlapping a purpose with volume()
326 - public double value() {
327 - return value;
328 - }
329 - }
330 -
331 } 220 }
......
...@@ -33,19 +33,19 @@ import static com.google.common.base.Preconditions.checkState; ...@@ -33,19 +33,19 @@ import static com.google.common.base.Preconditions.checkState;
33 */ 33 */
34 @Beta 34 @Beta
35 public abstract class ResourceId { 35 public abstract class ResourceId {
36 - static final ResourceId ROOT = new Discrete(); 36 + static final ResourceId ROOT = new DiscreteResourceId();
37 37
38 final ImmutableList<Object> components; 38 final ImmutableList<Object> components;
39 39
40 static ResourceId discrete(DeviceId device, Object... components) { 40 static ResourceId discrete(DeviceId device, Object... components) {
41 - return new Discrete(ImmutableList.builder() 41 + return new DiscreteResourceId(ImmutableList.builder()
42 .add(device) 42 .add(device)
43 .add(components) 43 .add(components)
44 .build()); 44 .build());
45 } 45 }
46 46
47 static ResourceId discrete(DeviceId device, PortNumber port, Object... components) { 47 static ResourceId discrete(DeviceId device, PortNumber port, Object... components) {
48 - return new Discrete(ImmutableList.builder() 48 + return new DiscreteResourceId(ImmutableList.builder()
49 .add(device) 49 .add(device)
50 .add(port) 50 .add(port)
51 .add(components) 51 .add(components)
...@@ -72,17 +72,17 @@ public abstract class ResourceId { ...@@ -72,17 +72,17 @@ public abstract class ResourceId {
72 } 72 }
73 73
74 private static ResourceId continuous(ImmutableList.Builder<Object> parentComponents, Class<?> last) { 74 private static ResourceId continuous(ImmutableList.Builder<Object> parentComponents, Class<?> last) {
75 - return new Continuous(parentComponents 75 + return new ContinuousResourceId(parentComponents
76 .add(last.getCanonicalName()) 76 .add(last.getCanonicalName())
77 .build(), last.getSimpleName()); 77 .build(), last.getSimpleName());
78 } 78 }
79 79
80 - private ResourceId(ImmutableList<Object> components) { 80 + protected ResourceId(ImmutableList<Object> components) {
81 this.components = checkNotNull(components); 81 this.components = checkNotNull(components);
82 } 82 }
83 83
84 // for serializer 84 // for serializer
85 - private ResourceId() { 85 + protected ResourceId() {
86 this.components = ImmutableList.of(); 86 this.components = ImmutableList.of();
87 } 87 }
88 88
...@@ -91,27 +91,27 @@ public abstract class ResourceId { ...@@ -91,27 +91,27 @@ public abstract class ResourceId {
91 if (components.size() == 1) { 91 if (components.size() == 1) {
92 return ROOT; 92 return ROOT;
93 } else { 93 } else {
94 - return new Discrete(components.subList(0, components.size() - 1)); 94 + return new DiscreteResourceId(components.subList(0, components.size() - 1));
95 } 95 }
96 } 96 }
97 97
98 /** 98 /**
99 * Returns a resource ID of a child of this resource based on the specified object. 99 * Returns a resource ID of a child of this resource based on the specified object.
100 * If the argument is an instance of {@link Class}, this method returns an instance of 100 * If the argument is an instance of {@link Class}, this method returns an instance of
101 - * {@link Continuous}. Otherwise, it returns an instance of {@link Discrete} 101 + * {@link ContinuousResourceId}. Otherwise, it returns an instance of {@link DiscreteResourceId}
102 - * This method only work when the receiver is {@link Discrete}. Otherwise, 102 + * This method only work when the receiver is {@link DiscreteResourceId}. Otherwise,
103 * this method throws an exception. 103 * this method throws an exception.
104 * 104 *
105 * @param child the last component of the child 105 * @param child the last component of the child
106 * @return a child resource ID 106 * @return a child resource ID
107 */ 107 */
108 public ResourceId child(Object child) { 108 public ResourceId child(Object child) {
109 - checkState(this instanceof Discrete); 109 + checkState(this instanceof DiscreteResourceId);
110 110
111 if (child instanceof Class<?>) { 111 if (child instanceof Class<?>) {
112 return continuous(ImmutableList.builder().addAll(components), (Class<?>) child); 112 return continuous(ImmutableList.builder().addAll(components), (Class<?>) child);
113 } else { 113 } else {
114 - return new Discrete(ImmutableList.builder() 114 + return new DiscreteResourceId(ImmutableList.builder()
115 .addAll(components) 115 .addAll(components)
116 .add(child) 116 .add(child)
117 .build()); 117 .build());
...@@ -140,44 +140,4 @@ public abstract class ResourceId { ...@@ -140,44 +140,4 @@ public abstract class ResourceId {
140 return components.toString(); 140 return components.toString();
141 } 141 }
142 142
143 - /**
144 - * ResourceId for {@link Resource.Discrete}.
145 - *
146 - * Note: This class is exposed to the public, but intended to be used in the resource API
147 - * implementation only. It is not for resource API user.
148 - */
149 - public static final class Discrete extends ResourceId {
150 - private Discrete(ImmutableList<Object> components) {
151 - super(components);
152 - }
153 -
154 - private Discrete() {
155 - super();
156 - }
157 - }
158 -
159 - /**
160 - * ResourceId for {@link Resource.Continuous}
161 - *
162 - * Note: This class is exposed to the public, but intended to be used in the resource API
163 - * implementation only. It is not for resource API user.
164 - */
165 - public static final class Continuous extends ResourceId {
166 - // for printing purpose only (used in toString() implementation)
167 - private final String name;
168 -
169 - private Continuous(ImmutableList<Object> components, String name) {
170 - super(components);
171 - this.name = checkNotNull(name);
172 - }
173 -
174 - @Override
175 - public String toString() {
176 - // due to performance consideration, the value might need to be stored in a field
177 - return ImmutableList.builder()
178 - .addAll(components.subList(0, components.size() - 1))
179 - .add(name)
180 - .build().toString();
181 - }
182 - }
183 } 143 }
......
...@@ -25,6 +25,8 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -25,6 +25,8 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
25 import org.apache.felix.scr.annotations.Service; 25 import org.apache.felix.scr.annotations.Service;
26 import org.onlab.util.GuavaCollectors; 26 import org.onlab.util.GuavaCollectors;
27 import org.onlab.util.Tools; 27 import org.onlab.util.Tools;
28 +import org.onosproject.net.newresource.ContinuousResource;
29 +import org.onosproject.net.newresource.DiscreteResource;
28 import org.onosproject.net.newresource.ResourceAllocation; 30 import org.onosproject.net.newresource.ResourceAllocation;
29 import org.onosproject.net.newresource.ResourceConsumer; 31 import org.onosproject.net.newresource.ResourceConsumer;
30 import org.onosproject.net.newresource.ResourceEvent; 32 import org.onosproject.net.newresource.ResourceEvent;
...@@ -83,13 +85,13 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -83,13 +85,13 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
83 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 85 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
84 protected StorageService service; 86 protected StorageService service;
85 87
86 - private ConsistentMap<Resource.Discrete, ResourceConsumer> discreteConsumers; 88 + private ConsistentMap<DiscreteResource, ResourceConsumer> discreteConsumers;
87 private ConsistentMap<ResourceId, ContinuousResourceAllocation> continuousConsumers; 89 private ConsistentMap<ResourceId, ContinuousResourceAllocation> continuousConsumers;
88 - private ConsistentMap<Resource.Discrete, Set<Resource>> childMap; 90 + private ConsistentMap<DiscreteResource, Set<Resource>> childMap;
89 91
90 @Activate 92 @Activate
91 public void activate() { 93 public void activate() {
92 - discreteConsumers = service.<Resource.Discrete, ResourceConsumer>consistentMapBuilder() 94 + discreteConsumers = service.<DiscreteResource, ResourceConsumer>consistentMapBuilder()
93 .withName(DISCRETE_CONSUMER_MAP) 95 .withName(DISCRETE_CONSUMER_MAP)
94 .withSerializer(SERIALIZER) 96 .withSerializer(SERIALIZER)
95 .build(); 97 .build();
...@@ -97,7 +99,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -97,7 +99,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
97 .withName(CONTINUOUS_CONSUMER_MAP) 99 .withName(CONTINUOUS_CONSUMER_MAP)
98 .withSerializer(SERIALIZER) 100 .withSerializer(SERIALIZER)
99 .build(); 101 .build();
100 - childMap = service.<Resource.Discrete, Set<Resource>>consistentMapBuilder() 102 + childMap = service.<DiscreteResource, Set<Resource>>consistentMapBuilder()
101 .withName(CHILD_MAP) 103 .withName(CHILD_MAP)
102 .withSerializer(SERIALIZER) 104 .withSerializer(SERIALIZER)
103 .build(); 105 .build();
...@@ -110,16 +112,16 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -110,16 +112,16 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
110 @Override 112 @Override
111 public List<ResourceConsumer> getConsumers(Resource resource) { 113 public List<ResourceConsumer> getConsumers(Resource resource) {
112 checkNotNull(resource); 114 checkNotNull(resource);
113 - checkArgument(resource instanceof Resource.Discrete || resource instanceof Resource.Continuous); 115 + checkArgument(resource instanceof DiscreteResource || resource instanceof ContinuousResource);
114 116
115 - if (resource instanceof Resource.Discrete) { 117 + if (resource instanceof DiscreteResource) {
116 - return getConsumer((Resource.Discrete) resource); 118 + return getConsumer((DiscreteResource) resource);
117 } else { 119 } else {
118 - return getConsumer((Resource.Continuous) resource); 120 + return getConsumer((ContinuousResource) resource);
119 } 121 }
120 } 122 }
121 123
122 - private List<ResourceConsumer> getConsumer(Resource.Discrete resource) { 124 + private List<ResourceConsumer> getConsumer(DiscreteResource resource) {
123 Versioned<ResourceConsumer> consumer = discreteConsumers.get(resource); 125 Versioned<ResourceConsumer> consumer = discreteConsumers.get(resource);
124 if (consumer == null) { 126 if (consumer == null) {
125 return ImmutableList.of(); 127 return ImmutableList.of();
...@@ -128,7 +130,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -128,7 +130,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
128 return ImmutableList.of(consumer.value()); 130 return ImmutableList.of(consumer.value());
129 } 131 }
130 132
131 - private List<ResourceConsumer> getConsumer(Resource.Continuous resource) { 133 + private List<ResourceConsumer> getConsumer(ContinuousResource resource) {
132 Versioned<ContinuousResourceAllocation> allocations = continuousConsumers.get(resource.id()); 134 Versioned<ContinuousResourceAllocation> allocations = continuousConsumers.get(resource.id());
133 if (allocations == null) { 135 if (allocations == null) {
134 return ImmutableList.of(); 136 return ImmutableList.of();
...@@ -150,15 +152,15 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -150,15 +152,15 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
150 TransactionContext tx = service.transactionContextBuilder().build(); 152 TransactionContext tx = service.transactionContextBuilder().build();
151 tx.begin(); 153 tx.begin();
152 154
153 - TransactionalMap<Resource.Discrete, Set<Resource>> childTxMap = 155 + TransactionalMap<DiscreteResource, Set<Resource>> childTxMap =
154 tx.getTransactionalMap(CHILD_MAP, SERIALIZER); 156 tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
155 157
156 - Map<Resource.Discrete, List<Resource>> resourceMap = resources.stream() 158 + Map<DiscreteResource, List<Resource>> resourceMap = resources.stream()
157 .filter(x -> x.parent().isPresent()) 159 .filter(x -> x.parent().isPresent())
158 .collect(Collectors.groupingBy(x -> x.parent().get())); 160 .collect(Collectors.groupingBy(x -> x.parent().get()));
159 161
160 - for (Map.Entry<Resource.Discrete, List<Resource>> entry: resourceMap.entrySet()) { 162 + for (Map.Entry<DiscreteResource, List<Resource>> entry: resourceMap.entrySet()) {
161 - Optional<Resource.Discrete> child = lookup(childTxMap, entry.getKey()); 163 + Optional<DiscreteResource> child = lookup(childTxMap, entry.getKey());
162 if (!child.isPresent()) { 164 if (!child.isPresent()) {
163 return abortTransaction(tx); 165 return abortTransaction(tx);
164 } 166 }
...@@ -186,25 +188,25 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -186,25 +188,25 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
186 TransactionContext tx = service.transactionContextBuilder().build(); 188 TransactionContext tx = service.transactionContextBuilder().build();
187 tx.begin(); 189 tx.begin();
188 190
189 - TransactionalMap<Resource.Discrete, Set<Resource>> childTxMap = 191 + TransactionalMap<DiscreteResource, Set<Resource>> childTxMap =
190 tx.getTransactionalMap(CHILD_MAP, SERIALIZER); 192 tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
191 - TransactionalMap<Resource.Discrete, ResourceConsumer> discreteConsumerTxMap = 193 + TransactionalMap<DiscreteResource, ResourceConsumer> discreteConsumerTxMap =
192 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER); 194 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
193 TransactionalMap<ResourceId, ContinuousResourceAllocation> continuousConsumerTxMap = 195 TransactionalMap<ResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
194 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER); 196 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
195 197
196 // Extract Discrete instances from resources 198 // Extract Discrete instances from resources
197 - Map<Resource.Discrete, List<Resource>> resourceMap = resources.stream() 199 + Map<DiscreteResource, List<Resource>> resourceMap = resources.stream()
198 .filter(x -> x.parent().isPresent()) 200 .filter(x -> x.parent().isPresent())
199 .collect(Collectors.groupingBy(x -> x.parent().get())); 201 .collect(Collectors.groupingBy(x -> x.parent().get()));
200 202
201 // even if one of the resources is allocated to a consumer, 203 // even if one of the resources is allocated to a consumer,
202 // all unregistrations are regarded as failure 204 // all unregistrations are regarded as failure
203 - for (Map.Entry<Resource.Discrete, List<Resource>> entry: resourceMap.entrySet()) { 205 + for (Map.Entry<DiscreteResource, List<Resource>> entry: resourceMap.entrySet()) {
204 boolean allocated = entry.getValue().stream().anyMatch(x -> { 206 boolean allocated = entry.getValue().stream().anyMatch(x -> {
205 - if (x instanceof Resource.Discrete) { 207 + if (x instanceof DiscreteResource) {
206 - return discreteConsumerTxMap.get((Resource.Discrete) x) != null; 208 + return discreteConsumerTxMap.get((DiscreteResource) x) != null;
207 - } else if (x instanceof Resource.Continuous) { 209 + } else if (x instanceof ContinuousResource) {
208 ContinuousResourceAllocation allocations = continuousConsumerTxMap.get(x.id()); 210 ContinuousResourceAllocation allocations = continuousConsumerTxMap.get(x.id());
209 return allocations != null && !allocations.allocations().isEmpty(); 211 return allocations != null && !allocations.allocations().isEmpty();
210 } else { 212 } else {
...@@ -239,31 +241,31 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -239,31 +241,31 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
239 TransactionContext tx = service.transactionContextBuilder().build(); 241 TransactionContext tx = service.transactionContextBuilder().build();
240 tx.begin(); 242 tx.begin();
241 243
242 - TransactionalMap<Resource.Discrete, Set<Resource>> childTxMap = 244 + TransactionalMap<DiscreteResource, Set<Resource>> childTxMap =
243 tx.getTransactionalMap(CHILD_MAP, SERIALIZER); 245 tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
244 - TransactionalMap<Resource.Discrete, ResourceConsumer> discreteConsumerTxMap = 246 + TransactionalMap<DiscreteResource, ResourceConsumer> discreteConsumerTxMap =
245 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER); 247 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
246 TransactionalMap<ResourceId, ContinuousResourceAllocation> continuousConsumerTxMap = 248 TransactionalMap<ResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
247 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER); 249 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
248 250
249 for (Resource resource: resources) { 251 for (Resource resource: resources) {
250 - if (resource instanceof Resource.Discrete) { 252 + if (resource instanceof DiscreteResource) {
251 if (!lookup(childTxMap, resource).isPresent()) { 253 if (!lookup(childTxMap, resource).isPresent()) {
252 return abortTransaction(tx); 254 return abortTransaction(tx);
253 } 255 }
254 256
255 - ResourceConsumer oldValue = discreteConsumerTxMap.put((Resource.Discrete) resource, consumer); 257 + ResourceConsumer oldValue = discreteConsumerTxMap.put((DiscreteResource) resource, consumer);
256 if (oldValue != null) { 258 if (oldValue != null) {
257 return abortTransaction(tx); 259 return abortTransaction(tx);
258 } 260 }
259 - } else if (resource instanceof Resource.Continuous) { 261 + } else if (resource instanceof ContinuousResource) {
260 - Optional<Resource.Continuous> continuous = lookup(childTxMap, (Resource.Continuous) resource); 262 + Optional<ContinuousResource> continuous = lookup(childTxMap, (ContinuousResource) resource);
261 if (!continuous.isPresent()) { 263 if (!continuous.isPresent()) {
262 return abortTransaction(tx); 264 return abortTransaction(tx);
263 } 265 }
264 266
265 ContinuousResourceAllocation allocations = continuousConsumerTxMap.get(continuous.get().id()); 267 ContinuousResourceAllocation allocations = continuousConsumerTxMap.get(continuous.get().id());
266 - if (!hasEnoughResource(continuous.get(), (Resource.Continuous) resource, allocations)) { 268 + if (!hasEnoughResource(continuous.get(), (ContinuousResource) resource, allocations)) {
267 return abortTransaction(tx); 269 return abortTransaction(tx);
268 } 270 }
269 271
...@@ -287,7 +289,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -287,7 +289,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
287 TransactionContext tx = service.transactionContextBuilder().build(); 289 TransactionContext tx = service.transactionContextBuilder().build();
288 tx.begin(); 290 tx.begin();
289 291
290 - TransactionalMap<Resource.Discrete, ResourceConsumer> discreteConsumerTxMap = 292 + TransactionalMap<DiscreteResource, ResourceConsumer> discreteConsumerTxMap =
291 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER); 293 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
292 TransactionalMap<ResourceId, ContinuousResourceAllocation> continuousConsumerTxMap = 294 TransactionalMap<ResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
293 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER); 295 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
...@@ -298,18 +300,18 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -298,18 +300,18 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
298 Resource resource = resourceIte.next(); 300 Resource resource = resourceIte.next();
299 ResourceConsumer consumer = consumerIte.next(); 301 ResourceConsumer consumer = consumerIte.next();
300 302
301 - if (resource instanceof Resource.Discrete) { 303 + if (resource instanceof DiscreteResource) {
302 // if this single release fails (because the resource is allocated to another consumer, 304 // if this single release fails (because the resource is allocated to another consumer,
303 // the whole release fails 305 // the whole release fails
304 - if (!discreteConsumerTxMap.remove((Resource.Discrete) resource, consumer)) { 306 + if (!discreteConsumerTxMap.remove((DiscreteResource) resource, consumer)) {
305 return abortTransaction(tx); 307 return abortTransaction(tx);
306 } 308 }
307 - } else if (resource instanceof Resource.Continuous) { 309 + } else if (resource instanceof ContinuousResource) {
308 - Resource.Continuous continuous = (Resource.Continuous) resource; 310 + ContinuousResource continuous = (ContinuousResource) resource;
309 ContinuousResourceAllocation allocation = continuousConsumerTxMap.get(continuous.id()); 311 ContinuousResourceAllocation allocation = continuousConsumerTxMap.get(continuous.id());
310 ImmutableList<ResourceAllocation> newAllocations = allocation.allocations().stream() 312 ImmutableList<ResourceAllocation> newAllocations = allocation.allocations().stream()
311 .filter(x -> !(x.consumer().equals(consumer) && 313 .filter(x -> !(x.consumer().equals(consumer) &&
312 - ((Resource.Continuous) x.resource()).value() == continuous.value())) 314 + ((ContinuousResource) x.resource()).value() == continuous.value()))
313 .collect(GuavaCollectors.toImmutableList()); 315 .collect(GuavaCollectors.toImmutableList());
314 316
315 if (!continuousConsumerTxMap.replace(continuous.id(), allocation, 317 if (!continuousConsumerTxMap.replace(continuous.id(), allocation,
...@@ -325,7 +327,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -325,7 +327,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
325 @Override 327 @Override
326 public boolean isAvailable(Resource resource) { 328 public boolean isAvailable(Resource resource) {
327 checkNotNull(resource); 329 checkNotNull(resource);
328 - checkArgument(resource instanceof Resource.Discrete || resource instanceof Resource.Continuous); 330 + checkArgument(resource instanceof DiscreteResource || resource instanceof ContinuousResource);
329 331
330 // check if it's registered or not. 332 // check if it's registered or not.
331 Versioned<Set<Resource>> v = childMap.get(resource.parent().get()); 333 Versioned<Set<Resource>> v = childMap.get(resource.parent().get());
...@@ -333,15 +335,15 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -333,15 +335,15 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
333 return false; 335 return false;
334 } 336 }
335 337
336 - if (resource instanceof Resource.Discrete) { 338 + if (resource instanceof DiscreteResource) {
337 // check if already consumed 339 // check if already consumed
338 - return getConsumer((Resource.Discrete) resource).isEmpty(); 340 + return getConsumer((DiscreteResource) resource).isEmpty();
339 } else { 341 } else {
340 - Resource.Continuous requested = (Resource.Continuous) resource; 342 + ContinuousResource requested = (ContinuousResource) resource;
341 - Resource.Continuous registered = v.value().stream() 343 + ContinuousResource registered = v.value().stream()
342 .filter(c -> c.id().equals(resource.id())) 344 .filter(c -> c.id().equals(resource.id()))
343 .findFirst() 345 .findFirst()
344 - .map(c -> (Resource.Continuous) c) 346 + .map(c -> (ContinuousResource) c)
345 .get(); 347 .get();
346 if (registered.value() < requested.value()) { 348 if (registered.value() < requested.value()) {
347 // Capacity < requested, can never satisfy 349 // Capacity < requested, can never satisfy
...@@ -352,7 +354,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -352,7 +354,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
352 } 354 }
353 } 355 }
354 356
355 - private boolean isAvailable(Resource.Continuous resource) { 357 + private boolean isAvailable(ContinuousResource resource) {
356 Versioned<ContinuousResourceAllocation> allocation = continuousConsumers.get(resource.id()); 358 Versioned<ContinuousResourceAllocation> allocation = continuousConsumers.get(resource.id());
357 if (allocation == null) { 359 if (allocation == null) {
358 // no allocation (=no consumer) full registered resources available 360 // no allocation (=no consumer) full registered resources available
...@@ -368,11 +370,11 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -368,11 +370,11 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
368 370
369 // NOTE: getting all entries may become performance bottleneck 371 // NOTE: getting all entries may become performance bottleneck
370 // TODO: revisit for better backend data structure 372 // TODO: revisit for better backend data structure
371 - Stream<Resource.Discrete> discreteStream = discreteConsumers.entrySet().stream() 373 + Stream<DiscreteResource> discreteStream = discreteConsumers.entrySet().stream()
372 .filter(x -> x.getValue().value().equals(consumer)) 374 .filter(x -> x.getValue().value().equals(consumer))
373 .map(Map.Entry::getKey); 375 .map(Map.Entry::getKey);
374 376
375 - Stream<Resource.Continuous> continuousStream = continuousConsumers.values().stream() 377 + Stream<ContinuousResource> continuousStream = continuousConsumers.values().stream()
376 .flatMap(x -> x.value().allocations().stream() 378 .flatMap(x -> x.value().allocations().stream()
377 .map(y -> Maps.immutableEntry(x.value().original(), y))) 379 .map(y -> Maps.immutableEntry(x.value().original(), y)))
378 .filter(x -> x.getValue().consumer().equals(consumer)) 380 .filter(x -> x.getValue().consumer().equals(consumer))
...@@ -384,12 +386,12 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -384,12 +386,12 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
384 @Override 386 @Override
385 public Collection<Resource> getChildResources(Resource parent) { 387 public Collection<Resource> getChildResources(Resource parent) {
386 checkNotNull(parent); 388 checkNotNull(parent);
387 - if (!(parent instanceof Resource.Discrete)) { 389 + if (!(parent instanceof DiscreteResource)) {
388 // only Discrete resource can have child resource 390 // only Discrete resource can have child resource
389 return ImmutableList.of(); 391 return ImmutableList.of();
390 } 392 }
391 393
392 - Versioned<Set<Resource>> children = childMap.get((Resource.Discrete) parent); 394 + Versioned<Set<Resource>> children = childMap.get((DiscreteResource) parent);
393 if (children == null) { 395 if (children == null) {
394 return ImmutableList.of(); 396 return ImmutableList.of();
395 } 397 }
...@@ -401,23 +403,23 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -401,23 +403,23 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
401 public <T> Collection<Resource> getAllocatedResources(Resource parent, Class<T> cls) { 403 public <T> Collection<Resource> getAllocatedResources(Resource parent, Class<T> cls) {
402 checkNotNull(parent); 404 checkNotNull(parent);
403 checkNotNull(cls); 405 checkNotNull(cls);
404 - checkArgument(parent instanceof Resource.Discrete); 406 + checkArgument(parent instanceof DiscreteResource);
405 407
406 - Versioned<Set<Resource>> children = childMap.get((Resource.Discrete) parent); 408 + Versioned<Set<Resource>> children = childMap.get((DiscreteResource) parent);
407 if (children == null) { 409 if (children == null) {
408 return ImmutableList.of(); 410 return ImmutableList.of();
409 } 411 }
410 412
411 - Stream<Resource.Discrete> discrete = children.value().stream() 413 + Stream<DiscreteResource> discrete = children.value().stream()
412 .filter(x -> x.last().getClass().equals(cls)) 414 .filter(x -> x.last().getClass().equals(cls))
413 - .filter(x -> x instanceof Resource.Discrete) 415 + .filter(x -> x instanceof DiscreteResource)
414 - .map(x -> (Resource.Discrete) x) 416 + .map(x -> (DiscreteResource) x)
415 .filter(discreteConsumers::containsKey); 417 .filter(discreteConsumers::containsKey);
416 418
417 - Stream<Resource.Continuous> continuous = children.value().stream() 419 + Stream<ContinuousResource> continuous = children.value().stream()
418 .filter(x -> x.id().equals(parent.id().child(cls))) 420 .filter(x -> x.id().equals(parent.id().child(cls)))
419 - .filter(x -> x instanceof Resource.Continuous) 421 + .filter(x -> x instanceof ContinuousResource)
420 - .map(x -> (Resource.Continuous) x) 422 + .map(x -> (ContinuousResource) x)
421 .filter(x -> continuousConsumers.containsKey(x.id())) 423 .filter(x -> continuousConsumers.containsKey(x.id()))
422 .filter(x -> continuousConsumers.get(x.id()) != null) 424 .filter(x -> continuousConsumers.get(x.id()) != null)
423 .filter(x -> !continuousConsumers.get(x.id()).value().allocations().isEmpty()); 425 .filter(x -> !continuousConsumers.get(x.id()).value().allocations().isEmpty());
...@@ -438,7 +440,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -438,7 +440,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
438 440
439 // Appends the specified ResourceAllocation to the existing values stored in the map 441 // Appends the specified ResourceAllocation to the existing values stored in the map
440 private boolean appendValue(TransactionalMap<ResourceId, ContinuousResourceAllocation> map, 442 private boolean appendValue(TransactionalMap<ResourceId, ContinuousResourceAllocation> map,
441 - Resource.Continuous original, ResourceAllocation value) { 443 + ContinuousResource original, ResourceAllocation value) {
442 ContinuousResourceAllocation oldValue = map.putIfAbsent(original.id(), 444 ContinuousResourceAllocation oldValue = map.putIfAbsent(original.id(),
443 new ContinuousResourceAllocation(original, ImmutableList.of(value))); 445 new ContinuousResourceAllocation(original, ImmutableList.of(value)));
444 if (oldValue == null) { 446 if (oldValue == null) {
...@@ -521,7 +523,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -521,7 +523,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
521 */ 523 */
522 // Naive implementation, which traverses all elements in the list 524 // Naive implementation, which traverses all elements in the list
523 private <T extends Resource> Optional<T> lookup( 525 private <T extends Resource> Optional<T> lookup(
524 - TransactionalMap<Resource.Discrete, Set<Resource>> map, T resource) { 526 + TransactionalMap<DiscreteResource, Set<Resource>> map, T resource) {
525 // if it is root, always returns itself 527 // if it is root, always returns itself
526 if (!resource.parent().isPresent()) { 528 if (!resource.parent().isPresent()) {
527 return Optional.of(resource); 529 return Optional.of(resource);
...@@ -549,17 +551,17 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -549,17 +551,17 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
549 * @param allocation current allocation of the resource 551 * @param allocation current allocation of the resource
550 * @return true if there is enough resource volume. Otherwise, false. 552 * @return true if there is enough resource volume. Otherwise, false.
551 */ 553 */
552 - private boolean hasEnoughResource(Resource.Continuous original, 554 + private boolean hasEnoughResource(ContinuousResource original,
553 - Resource.Continuous request, 555 + ContinuousResource request,
554 ContinuousResourceAllocation allocation) { 556 ContinuousResourceAllocation allocation) {
555 if (allocation == null) { 557 if (allocation == null) {
556 return request.value() <= original.value(); 558 return request.value() <= original.value();
557 } 559 }
558 560
559 double allocated = allocation.allocations().stream() 561 double allocated = allocation.allocations().stream()
560 - .filter(x -> x.resource() instanceof Resource.Continuous) 562 + .filter(x -> x.resource() instanceof ContinuousResource)
561 - .map(x -> (Resource.Continuous) x.resource()) 563 + .map(x -> (ContinuousResource) x.resource())
562 - .mapToDouble(Resource.Continuous::value) 564 + .mapToDouble(ContinuousResource::value)
563 .sum(); 565 .sum();
564 double left = original.value() - allocated; 566 double left = original.value() - allocated;
565 return request.value() <= left; 567 return request.value() <= left;
...@@ -567,16 +569,16 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -567,16 +569,16 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
567 569
568 // internal use only 570 // internal use only
569 private static final class ContinuousResourceAllocation { 571 private static final class ContinuousResourceAllocation {
570 - private final Resource.Continuous original; 572 + private final ContinuousResource original;
571 private final ImmutableList<ResourceAllocation> allocations; 573 private final ImmutableList<ResourceAllocation> allocations;
572 574
573 - private ContinuousResourceAllocation(Resource.Continuous original, 575 + private ContinuousResourceAllocation(ContinuousResource original,
574 ImmutableList<ResourceAllocation> allocations) { 576 ImmutableList<ResourceAllocation> allocations) {
575 this.original = original; 577 this.original = original;
576 this.allocations = allocations; 578 this.allocations = allocations;
577 } 579 }
578 580
579 - private Resource.Continuous original() { 581 + private ContinuousResource original() {
580 return original; 582 return original;
581 } 583 }
582 584
......
...@@ -172,6 +172,10 @@ import org.onosproject.net.intent.constraint.PartialFailureConstraint; ...@@ -172,6 +172,10 @@ import org.onosproject.net.intent.constraint.PartialFailureConstraint;
172 import org.onosproject.net.intent.constraint.WaypointConstraint; 172 import org.onosproject.net.intent.constraint.WaypointConstraint;
173 import org.onosproject.net.link.DefaultLinkDescription; 173 import org.onosproject.net.link.DefaultLinkDescription;
174 import org.onosproject.net.meter.MeterId; 174 import org.onosproject.net.meter.MeterId;
175 +import org.onosproject.net.newresource.ContinuousResource;
176 +import org.onosproject.net.newresource.ContinuousResourceId;
177 +import org.onosproject.net.newresource.DiscreteResource;
178 +import org.onosproject.net.newresource.DiscreteResourceId;
175 import org.onosproject.net.newresource.ResourceAllocation; 179 import org.onosproject.net.newresource.ResourceAllocation;
176 import org.onosproject.net.newresource.ResourceId; 180 import org.onosproject.net.newresource.ResourceId;
177 import org.onosproject.net.newresource.Resource; 181 import org.onosproject.net.newresource.Resource;
...@@ -434,11 +438,11 @@ public final class KryoNamespaces { ...@@ -434,11 +438,11 @@ public final class KryoNamespaces {
434 BandwidthResourceAllocation.class, 438 BandwidthResourceAllocation.class,
435 LambdaResourceAllocation.class, 439 LambdaResourceAllocation.class,
436 Resource.class, 440 Resource.class,
437 - Resource.Discrete.class, 441 + DiscreteResource.class,
438 - Resource.Continuous.class, 442 + ContinuousResource.class,
439 ResourceId.class, 443 ResourceId.class,
440 - ResourceId.Discrete.class, 444 + DiscreteResourceId.class,
441 - ResourceId.Continuous.class, 445 + ContinuousResourceId.class,
442 ResourceAllocation.class, 446 ResourceAllocation.class,
443 // Constraints 447 // Constraints
444 LambdaConstraint.class, 448 LambdaConstraint.class,
......