Committed by
Sho Shimizu
Add facade object called UnifiedDiscreteResources
This is for ONOS-4281 Change-Id: I04649932fdb8983492878732a04c93a21b4cafe7 (cherry picked from commit ac6ff6e1)
Showing
5 changed files
with
100 additions
and
3 deletions
... | @@ -71,6 +71,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour | ... | @@ -71,6 +71,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour |
71 | 71 | ||
72 | static final Serializer SERIALIZER = Serializer.using( | 72 | static final Serializer SERIALIZER = Serializer.using( |
73 | Arrays.asList(KryoNamespaces.API), | 73 | Arrays.asList(KryoNamespaces.API), |
74 | + UnifiedDiscreteResources.class, | ||
74 | NonEncodableDiscreteResources.class, | 75 | NonEncodableDiscreteResources.class, |
75 | ContinuousResourceAllocation.class); | 76 | ContinuousResourceAllocation.class); |
76 | 77 | ... | ... |
... | @@ -32,7 +32,17 @@ interface DiscreteResources { | ... | @@ -32,7 +32,17 @@ interface DiscreteResources { |
32 | * @return a empty set. | 32 | * @return a empty set. |
33 | */ | 33 | */ |
34 | static DiscreteResources empty() { | 34 | static DiscreteResources empty() { |
35 | - return NonEncodableDiscreteResources.empty(); | 35 | + return UnifiedDiscreteResources.empty(); |
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * Create an instace from the specified resources. | ||
40 | + * | ||
41 | + * @param resources resources | ||
42 | + * @return instance | ||
43 | + */ | ||
44 | + static DiscreteResources of(List<DiscreteResource> resources) { | ||
45 | + return UnifiedDiscreteResources.of(resources); | ||
36 | } | 46 | } |
37 | 47 | ||
38 | /** | 48 | /** | ... | ... |
core/store/dist/src/main/java/org/onosproject/store/resource/impl/NonEncodableDiscreteResources.java
... | @@ -34,11 +34,15 @@ final class NonEncodableDiscreteResources implements DiscreteResources { | ... | @@ -34,11 +34,15 @@ final class NonEncodableDiscreteResources implements DiscreteResources { |
34 | return new NonEncodableDiscreteResources(); | 34 | return new NonEncodableDiscreteResources(); |
35 | } | 35 | } |
36 | 36 | ||
37 | + static NonEncodableDiscreteResources of(List<DiscreteResource> resources) { | ||
38 | + return new NonEncodableDiscreteResources(resources); | ||
39 | + } | ||
40 | + | ||
37 | private NonEncodableDiscreteResources() { | 41 | private NonEncodableDiscreteResources() { |
38 | this.values = new LinkedHashSet<>(); | 42 | this.values = new LinkedHashSet<>(); |
39 | } | 43 | } |
40 | 44 | ||
41 | - NonEncodableDiscreteResources(List<DiscreteResource> values) { | 45 | + private NonEncodableDiscreteResources(List<DiscreteResource> values) { |
42 | this.values = new LinkedHashSet<>(values); | 46 | this.values = new LinkedHashSet<>(values); |
43 | } | 47 | } |
44 | 48 | ... | ... |
... | @@ -59,7 +59,7 @@ class TransactionalDiscreteResourceSubStore { | ... | @@ -59,7 +59,7 @@ class TransactionalDiscreteResourceSubStore { |
59 | return true; | 59 | return true; |
60 | } | 60 | } |
61 | 61 | ||
62 | - DiscreteResources requested = new NonEncodableDiscreteResources(values); | 62 | + DiscreteResources requested = DiscreteResources.of(values); |
63 | DiscreteResources oldValues = childMap.putIfAbsent(key, requested); | 63 | DiscreteResources oldValues = childMap.putIfAbsent(key, requested); |
64 | if (oldValues == null) { | 64 | if (oldValues == null) { |
65 | return true; | 65 | return true; | ... | ... |
core/store/dist/src/main/java/org/onosproject/store/resource/impl/UnifiedDiscreteResources.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present 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.store.resource.impl; | ||
17 | + | ||
18 | +import org.onosproject.net.resource.DiscreteResource; | ||
19 | +import org.onosproject.net.resource.DiscreteResourceId; | ||
20 | + | ||
21 | +import java.util.List; | ||
22 | +import java.util.Optional; | ||
23 | +import java.util.Set; | ||
24 | + | ||
25 | +/** | ||
26 | + * Represents a set of resources containing resources that can be encoded as integer | ||
27 | + * and those that can't encoded as integer. | ||
28 | + */ | ||
29 | +final class UnifiedDiscreteResources implements DiscreteResources { | ||
30 | + private final DiscreteResources nonEncodables; | ||
31 | + | ||
32 | + static DiscreteResources empty() { | ||
33 | + return new UnifiedDiscreteResources(); | ||
34 | + } | ||
35 | + | ||
36 | + static DiscreteResources of(List<DiscreteResource> resources) { | ||
37 | + return new UnifiedDiscreteResources(resources); | ||
38 | + } | ||
39 | + | ||
40 | + private UnifiedDiscreteResources() { | ||
41 | + this.nonEncodables = NonEncodableDiscreteResources.empty(); | ||
42 | + } | ||
43 | + | ||
44 | + private UnifiedDiscreteResources(List<DiscreteResource> resources) { | ||
45 | + this.nonEncodables = NonEncodableDiscreteResources.of(resources); | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public Optional<DiscreteResource> lookup(DiscreteResourceId id) { | ||
50 | + return nonEncodables.lookup(id); | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public DiscreteResources difference(DiscreteResources other) { | ||
55 | + return nonEncodables.difference(other); | ||
56 | + } | ||
57 | + | ||
58 | + @Override | ||
59 | + public boolean isEmpty() { | ||
60 | + return nonEncodables.isEmpty(); | ||
61 | + } | ||
62 | + | ||
63 | + @Override | ||
64 | + public boolean containsAny(List<DiscreteResource> other) { | ||
65 | + return nonEncodables.containsAny(other); | ||
66 | + } | ||
67 | + | ||
68 | + @Override | ||
69 | + public DiscreteResources add(DiscreteResources other) { | ||
70 | + return nonEncodables.add(other); | ||
71 | + } | ||
72 | + | ||
73 | + @Override | ||
74 | + public DiscreteResources remove(List<DiscreteResource> removed) { | ||
75 | + return nonEncodables.remove(removed); | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public Set<DiscreteResource> values() { | ||
80 | + return nonEncodables.values(); | ||
81 | + } | ||
82 | +} |
-
Please register or login to post a comment