Committed by
Gerrit Code Review
Use Java 8 Map#compute when possible
Change-Id: Ida300c054449047096f355f09b3843e4934dcd18
Showing
6 changed files
with
15 additions
and
64 deletions
... | @@ -46,7 +46,6 @@ import org.onosproject.net.device.PortStatistics; | ... | @@ -46,7 +46,6 @@ import org.onosproject.net.device.PortStatistics; |
46 | import org.onosproject.net.provider.ProviderId; | 46 | import org.onosproject.net.provider.ProviderId; |
47 | import org.onosproject.store.AbstractStore; | 47 | import org.onosproject.store.AbstractStore; |
48 | import org.onlab.packet.ChassisId; | 48 | import org.onlab.packet.ChassisId; |
49 | -import org.onlab.util.NewConcurrentHashMap; | ||
50 | import org.slf4j.Logger; | 49 | import org.slf4j.Logger; |
51 | 50 | ||
52 | import java.util.ArrayList; | 51 | import java.util.ArrayList; |
... | @@ -73,7 +72,6 @@ import static com.google.common.base.Predicates.notNull; | ... | @@ -73,7 +72,6 @@ import static com.google.common.base.Predicates.notNull; |
73 | import static com.google.common.base.Verify.verify; | 72 | import static com.google.common.base.Verify.verify; |
74 | import static org.onosproject.net.device.DeviceEvent.Type.*; | 73 | import static org.onosproject.net.device.DeviceEvent.Type.*; |
75 | import static org.slf4j.LoggerFactory.getLogger; | 74 | import static org.slf4j.LoggerFactory.getLogger; |
76 | -import static org.apache.commons.lang3.concurrent.ConcurrentUtils.createIfAbsentUnchecked; | ||
77 | import static org.onosproject.net.DefaultAnnotations.union; | 75 | import static org.onosproject.net.DefaultAnnotations.union; |
78 | import static org.onosproject.net.DefaultAnnotations.merge; | 76 | import static org.onosproject.net.DefaultAnnotations.merge; |
79 | 77 | ||
... | @@ -347,8 +345,7 @@ public class SimpleDeviceStore | ... | @@ -347,8 +345,7 @@ public class SimpleDeviceStore |
347 | // Gets the map of ports for the specified device; if one does not already | 345 | // Gets the map of ports for the specified device; if one does not already |
348 | // exist, it creates and registers a new one. | 346 | // exist, it creates and registers a new one. |
349 | private ConcurrentMap<PortNumber, Port> getPortMap(DeviceId deviceId) { | 347 | private ConcurrentMap<PortNumber, Port> getPortMap(DeviceId deviceId) { |
350 | - return createIfAbsentUnchecked(devicePorts, deviceId, | 348 | + return devicePorts.computeIfAbsent(deviceId, k -> new ConcurrentHashMap<>()); |
351 | - NewConcurrentHashMap.ifNeeded()); | ||
352 | } | 349 | } |
353 | 350 | ||
354 | private Map<ProviderId, DeviceDescriptions> getOrCreateDeviceDescriptions( | 351 | private Map<ProviderId, DeviceDescriptions> getOrCreateDeviceDescriptions( | ... | ... |
... | @@ -30,7 +30,6 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -30,7 +30,6 @@ import org.apache.felix.scr.annotations.Deactivate; |
30 | import org.apache.felix.scr.annotations.Modified; | 30 | import org.apache.felix.scr.annotations.Modified; |
31 | import org.apache.felix.scr.annotations.Property; | 31 | import org.apache.felix.scr.annotations.Property; |
32 | import org.apache.felix.scr.annotations.Service; | 32 | import org.apache.felix.scr.annotations.Service; |
33 | -import org.onlab.util.NewConcurrentHashMap; | ||
34 | import org.onlab.util.Tools; | 33 | import org.onlab.util.Tools; |
35 | import org.onosproject.net.DeviceId; | 34 | import org.onosproject.net.DeviceId; |
36 | import org.onosproject.net.flow.CompletedBatchOperation; | 35 | import org.onosproject.net.flow.CompletedBatchOperation; |
... | @@ -66,7 +65,6 @@ import java.util.concurrent.TimeUnit; | ... | @@ -66,7 +65,6 @@ import java.util.concurrent.TimeUnit; |
66 | import java.util.concurrent.TimeoutException; | 65 | import java.util.concurrent.TimeoutException; |
67 | import java.util.concurrent.atomic.AtomicInteger; | 66 | import java.util.concurrent.atomic.AtomicInteger; |
68 | 67 | ||
69 | -import static org.apache.commons.lang3.concurrent.ConcurrentUtils.createIfAbsentUnchecked; | ||
70 | import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVED; | 68 | import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVED; |
71 | import static org.slf4j.LoggerFactory.getLogger; | 69 | import static org.slf4j.LoggerFactory.getLogger; |
72 | 70 | ||
... | @@ -163,10 +161,6 @@ public class SimpleFlowRuleStore | ... | @@ -163,10 +161,6 @@ public class SimpleFlowRuleStore |
163 | } | 161 | } |
164 | } | 162 | } |
165 | 163 | ||
166 | - private static NewConcurrentHashMap<FlowId, List<StoredFlowEntry>> lazyEmptyFlowTable() { | ||
167 | - return NewConcurrentHashMap.ifNeeded(); | ||
168 | - } | ||
169 | - | ||
170 | /** | 164 | /** |
171 | * Returns the flow table for specified device. | 165 | * Returns the flow table for specified device. |
172 | * | 166 | * |
... | @@ -174,8 +168,7 @@ public class SimpleFlowRuleStore | ... | @@ -174,8 +168,7 @@ public class SimpleFlowRuleStore |
174 | * @return Map representing Flow Table of given device. | 168 | * @return Map representing Flow Table of given device. |
175 | */ | 169 | */ |
176 | private ConcurrentMap<FlowId, List<StoredFlowEntry>> getFlowTable(DeviceId deviceId) { | 170 | private ConcurrentMap<FlowId, List<StoredFlowEntry>> getFlowTable(DeviceId deviceId) { |
177 | - return createIfAbsentUnchecked(flowEntries, | 171 | + return flowEntries.computeIfAbsent(deviceId, k -> new ConcurrentHashMap<>()); |
178 | - deviceId, lazyEmptyFlowTable()); | ||
179 | } | 172 | } |
180 | 173 | ||
181 | private List<StoredFlowEntry> getFlowEntries(DeviceId deviceId, FlowId flowId) { | 174 | private List<StoredFlowEntry> getFlowEntries(DeviceId deviceId, FlowId flowId) { |
... | @@ -317,6 +310,7 @@ public class SimpleFlowRuleStore | ... | @@ -317,6 +310,7 @@ public class SimpleFlowRuleStore |
317 | return null; | 310 | return null; |
318 | } | 311 | } |
319 | 312 | ||
313 | + @Override | ||
320 | public void purgeFlowRule(DeviceId deviceId) { | 314 | public void purgeFlowRule(DeviceId deviceId) { |
321 | flowEntries.remove(deviceId); | 315 | flowEntries.remove(deviceId); |
322 | } | 316 | } | ... | ... |
... | @@ -15,7 +15,6 @@ | ... | @@ -15,7 +15,6 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.store.trivial; | 16 | package org.onosproject.store.trivial; |
17 | 17 | ||
18 | -import static org.apache.commons.lang3.concurrent.ConcurrentUtils.createIfAbsentUnchecked; | ||
19 | import static org.slf4j.LoggerFactory.getLogger; | 18 | import static org.slf4j.LoggerFactory.getLogger; |
20 | 19 | ||
21 | import java.util.ArrayList; | 20 | import java.util.ArrayList; |
... | @@ -34,7 +33,6 @@ import org.apache.felix.scr.annotations.Activate; | ... | @@ -34,7 +33,6 @@ import org.apache.felix.scr.annotations.Activate; |
34 | import org.apache.felix.scr.annotations.Component; | 33 | import org.apache.felix.scr.annotations.Component; |
35 | import org.apache.felix.scr.annotations.Deactivate; | 34 | import org.apache.felix.scr.annotations.Deactivate; |
36 | import org.apache.felix.scr.annotations.Service; | 35 | import org.apache.felix.scr.annotations.Service; |
37 | -import org.onlab.util.NewConcurrentHashMap; | ||
38 | import org.onosproject.core.DefaultGroupId; | 36 | import org.onosproject.core.DefaultGroupId; |
39 | import org.onosproject.core.GroupId; | 37 | import org.onosproject.core.GroupId; |
40 | import org.onosproject.net.DeviceId; | 38 | import org.onosproject.net.DeviceId; |
... | @@ -99,26 +97,6 @@ public class SimpleGroupStore | ... | @@ -99,26 +97,6 @@ public class SimpleGroupStore |
99 | log.info("Stopped"); | 97 | log.info("Stopped"); |
100 | } | 98 | } |
101 | 99 | ||
102 | - private static NewConcurrentHashMap<GroupKey, StoredGroupEntry> | ||
103 | - lazyEmptyGroupKeyTable() { | ||
104 | - return NewConcurrentHashMap.ifNeeded(); | ||
105 | - } | ||
106 | - | ||
107 | - private static NewConcurrentHashMap<GroupId, StoredGroupEntry> | ||
108 | - lazyEmptyGroupIdTable() { | ||
109 | - return NewConcurrentHashMap.ifNeeded(); | ||
110 | - } | ||
111 | - | ||
112 | - private static NewConcurrentHashMap<GroupKey, StoredGroupEntry> | ||
113 | - lazyEmptyPendingGroupKeyTable() { | ||
114 | - return NewConcurrentHashMap.ifNeeded(); | ||
115 | - } | ||
116 | - | ||
117 | - private static NewConcurrentHashMap<GroupId, Group> | ||
118 | - lazyEmptyExtraneousGroupIdTable() { | ||
119 | - return NewConcurrentHashMap.ifNeeded(); | ||
120 | - } | ||
121 | - | ||
122 | /** | 100 | /** |
123 | * Returns the group key table for specified device. | 101 | * Returns the group key table for specified device. |
124 | * | 102 | * |
... | @@ -126,8 +104,7 @@ public class SimpleGroupStore | ... | @@ -126,8 +104,7 @@ public class SimpleGroupStore |
126 | * @return Map representing group key table of given device. | 104 | * @return Map representing group key table of given device. |
127 | */ | 105 | */ |
128 | private ConcurrentMap<GroupKey, StoredGroupEntry> getGroupKeyTable(DeviceId deviceId) { | 106 | private ConcurrentMap<GroupKey, StoredGroupEntry> getGroupKeyTable(DeviceId deviceId) { |
129 | - return createIfAbsentUnchecked(groupEntriesByKey, | 107 | + return groupEntriesByKey.computeIfAbsent(deviceId, k -> new ConcurrentHashMap<>()); |
130 | - deviceId, lazyEmptyGroupKeyTable()); | ||
131 | } | 108 | } |
132 | 109 | ||
133 | /** | 110 | /** |
... | @@ -137,8 +114,7 @@ public class SimpleGroupStore | ... | @@ -137,8 +114,7 @@ public class SimpleGroupStore |
137 | * @return Map representing group key table of given device. | 114 | * @return Map representing group key table of given device. |
138 | */ | 115 | */ |
139 | private ConcurrentMap<GroupId, StoredGroupEntry> getGroupIdTable(DeviceId deviceId) { | 116 | private ConcurrentMap<GroupId, StoredGroupEntry> getGroupIdTable(DeviceId deviceId) { |
140 | - return createIfAbsentUnchecked(groupEntriesById, | 117 | + return groupEntriesById.computeIfAbsent(deviceId, k -> new ConcurrentHashMap<>()); |
141 | - deviceId, lazyEmptyGroupIdTable()); | ||
142 | } | 118 | } |
143 | 119 | ||
144 | /** | 120 | /** |
... | @@ -149,8 +125,7 @@ public class SimpleGroupStore | ... | @@ -149,8 +125,7 @@ public class SimpleGroupStore |
149 | */ | 125 | */ |
150 | private ConcurrentMap<GroupKey, StoredGroupEntry> | 126 | private ConcurrentMap<GroupKey, StoredGroupEntry> |
151 | getPendingGroupKeyTable(DeviceId deviceId) { | 127 | getPendingGroupKeyTable(DeviceId deviceId) { |
152 | - return createIfAbsentUnchecked(pendingGroupEntriesByKey, | 128 | + return pendingGroupEntriesByKey.computeIfAbsent(deviceId, k -> new ConcurrentHashMap<>()); |
153 | - deviceId, lazyEmptyPendingGroupKeyTable()); | ||
154 | } | 129 | } |
155 | 130 | ||
156 | /** | 131 | /** |
... | @@ -161,9 +136,7 @@ public class SimpleGroupStore | ... | @@ -161,9 +136,7 @@ public class SimpleGroupStore |
161 | */ | 136 | */ |
162 | private ConcurrentMap<GroupId, Group> | 137 | private ConcurrentMap<GroupId, Group> |
163 | getExtraneousGroupIdTable(DeviceId deviceId) { | 138 | getExtraneousGroupIdTable(DeviceId deviceId) { |
164 | - return createIfAbsentUnchecked(extraneousGroupEntriesById, | 139 | + return extraneousGroupEntriesById.computeIfAbsent(deviceId, k -> new ConcurrentHashMap<>()); |
165 | - deviceId, | ||
166 | - lazyEmptyExtraneousGroupIdTable()); | ||
167 | } | 140 | } |
168 | 141 | ||
169 | /** | 142 | /** | ... | ... |
... | @@ -28,6 +28,7 @@ import java.util.Map.Entry; | ... | @@ -28,6 +28,7 @@ import java.util.Map.Entry; |
28 | import java.util.Objects; | 28 | import java.util.Objects; |
29 | import java.util.Optional; | 29 | import java.util.Optional; |
30 | import java.util.Set; | 30 | import java.util.Set; |
31 | +import java.util.concurrent.ConcurrentHashMap; | ||
31 | import java.util.concurrent.ConcurrentMap; | 32 | import java.util.concurrent.ConcurrentMap; |
32 | import java.util.concurrent.ExecutorService; | 33 | import java.util.concurrent.ExecutorService; |
33 | import java.util.concurrent.ScheduledExecutorService; | 34 | import java.util.concurrent.ScheduledExecutorService; |
... | @@ -43,7 +44,6 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; | ... | @@ -43,7 +44,6 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; |
43 | import org.apache.felix.scr.annotations.Service; | 44 | import org.apache.felix.scr.annotations.Service; |
44 | import org.onlab.packet.ChassisId; | 45 | import org.onlab.packet.ChassisId; |
45 | import org.onlab.util.KryoNamespace; | 46 | import org.onlab.util.KryoNamespace; |
46 | -import org.onlab.util.NewConcurrentHashMap; | ||
47 | import org.onosproject.cluster.ClusterService; | 47 | import org.onosproject.cluster.ClusterService; |
48 | import org.onosproject.cluster.ControllerNode; | 48 | import org.onosproject.cluster.ControllerNode; |
49 | import org.onosproject.cluster.NodeId; | 49 | import org.onosproject.cluster.NodeId; |
... | @@ -106,7 +106,6 @@ import static com.google.common.base.Predicates.notNull; | ... | @@ -106,7 +106,6 @@ import static com.google.common.base.Predicates.notNull; |
106 | import static com.google.common.base.Verify.verify; | 106 | import static com.google.common.base.Verify.verify; |
107 | import static java.util.concurrent.Executors.newCachedThreadPool; | 107 | import static java.util.concurrent.Executors.newCachedThreadPool; |
108 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | 108 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
109 | -import static org.apache.commons.lang3.concurrent.ConcurrentUtils.createIfAbsentUnchecked; | ||
110 | import static org.onlab.util.Tools.groupedThreads; | 109 | import static org.onlab.util.Tools.groupedThreads; |
111 | import static org.onlab.util.Tools.minPriority; | 110 | import static org.onlab.util.Tools.minPriority; |
112 | import static org.onosproject.cluster.ControllerNodeToNodeId.toNodeId; | 111 | import static org.onosproject.cluster.ControllerNodeToNodeId.toNodeId; |
... | @@ -541,6 +540,7 @@ public class GossipDeviceStore | ... | @@ -541,6 +540,7 @@ public class GossipDeviceStore |
541 | } | 540 | } |
542 | } | 541 | } |
543 | 542 | ||
543 | + @Override | ||
544 | public boolean markOnline(DeviceId deviceId) { | 544 | public boolean markOnline(DeviceId deviceId) { |
545 | if (devices.containsKey(deviceId)) { | 545 | if (devices.containsKey(deviceId)) { |
546 | final Timestamp timestamp = deviceClockService.getTimestamp(deviceId); | 546 | final Timestamp timestamp = deviceClockService.getTimestamp(deviceId); |
... | @@ -782,8 +782,7 @@ public class GossipDeviceStore | ... | @@ -782,8 +782,7 @@ public class GossipDeviceStore |
782 | // Gets the map of ports for the specified device; if one does not already | 782 | // Gets the map of ports for the specified device; if one does not already |
783 | // exist, it creates and registers a new one. | 783 | // exist, it creates and registers a new one. |
784 | private ConcurrentMap<PortNumber, Port> getPortMap(DeviceId deviceId) { | 784 | private ConcurrentMap<PortNumber, Port> getPortMap(DeviceId deviceId) { |
785 | - return createIfAbsentUnchecked(devicePorts, deviceId, | 785 | + return devicePorts.computeIfAbsent(deviceId, k -> new ConcurrentHashMap<>()); |
786 | - NewConcurrentHashMap.ifNeeded()); | ||
787 | } | 786 | } |
788 | 787 | ||
789 | private Map<ProviderId, DeviceDescriptions> getOrCreateDeviceDescriptionsMap( | 788 | private Map<ProviderId, DeviceDescriptions> getOrCreateDeviceDescriptionsMap( | ... | ... |
... | @@ -28,7 +28,6 @@ import org.apache.felix.scr.annotations.Reference; | ... | @@ -28,7 +28,6 @@ import org.apache.felix.scr.annotations.Reference; |
28 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 28 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
29 | import org.apache.felix.scr.annotations.Service; | 29 | import org.apache.felix.scr.annotations.Service; |
30 | import org.onlab.util.KryoNamespace; | 30 | import org.onlab.util.KryoNamespace; |
31 | -import org.onlab.util.NewConcurrentHashMap; | ||
32 | import org.onosproject.cfg.ComponentConfigService; | 31 | import org.onosproject.cfg.ComponentConfigService; |
33 | import org.onosproject.cluster.ClusterService; | 32 | import org.onosproject.cluster.ClusterService; |
34 | import org.onosproject.cluster.NodeId; | 33 | import org.onosproject.cluster.NodeId; |
... | @@ -89,7 +88,6 @@ import java.util.concurrent.atomic.AtomicInteger; | ... | @@ -89,7 +88,6 @@ import java.util.concurrent.atomic.AtomicInteger; |
89 | import java.util.stream.Collectors; | 88 | import java.util.stream.Collectors; |
90 | 89 | ||
91 | import static com.google.common.base.Strings.isNullOrEmpty; | 90 | import static com.google.common.base.Strings.isNullOrEmpty; |
92 | -import static org.apache.commons.lang3.concurrent.ConcurrentUtils.createIfAbsentUnchecked; | ||
93 | import static org.onlab.util.Tools.get; | 91 | import static org.onlab.util.Tools.get; |
94 | import static org.onlab.util.Tools.groupedThreads; | 92 | import static org.onlab.util.Tools.groupedThreads; |
95 | import static org.slf4j.LoggerFactory.getLogger; | 93 | import static org.slf4j.LoggerFactory.getLogger; |
... | @@ -239,16 +237,6 @@ public class DistributedGroupStore | ... | @@ -239,16 +237,6 @@ public class DistributedGroupStore |
239 | } | 237 | } |
240 | } | 238 | } |
241 | 239 | ||
242 | - private static NewConcurrentHashMap<GroupId, Group> | ||
243 | - lazyEmptyExtraneousGroupIdTable() { | ||
244 | - return NewConcurrentHashMap.ifNeeded(); | ||
245 | - } | ||
246 | - | ||
247 | - private static NewConcurrentHashMap<GroupId, StoredGroupEntry> | ||
248 | - lazyEmptyGroupIdTable() { | ||
249 | - return NewConcurrentHashMap.ifNeeded(); | ||
250 | - } | ||
251 | - | ||
252 | /** | 240 | /** |
253 | * Returns the group store eventual consistent key map. | 241 | * Returns the group store eventual consistent key map. |
254 | * | 242 | * |
... | @@ -266,8 +254,7 @@ public class DistributedGroupStore | ... | @@ -266,8 +254,7 @@ public class DistributedGroupStore |
266 | * @return Map representing group key table of given device. | 254 | * @return Map representing group key table of given device. |
267 | */ | 255 | */ |
268 | private ConcurrentMap<GroupId, StoredGroupEntry> getGroupIdTable(DeviceId deviceId) { | 256 | private ConcurrentMap<GroupId, StoredGroupEntry> getGroupIdTable(DeviceId deviceId) { |
269 | - return createIfAbsentUnchecked(groupEntriesById, | 257 | + return groupEntriesById.computeIfAbsent(deviceId, k -> new ConcurrentHashMap<>()); |
270 | - deviceId, lazyEmptyGroupIdTable()); | ||
271 | } | 258 | } |
272 | 259 | ||
273 | /** | 260 | /** |
... | @@ -288,9 +275,7 @@ public class DistributedGroupStore | ... | @@ -288,9 +275,7 @@ public class DistributedGroupStore |
288 | */ | 275 | */ |
289 | private ConcurrentMap<GroupId, Group> | 276 | private ConcurrentMap<GroupId, Group> |
290 | getExtraneousGroupIdTable(DeviceId deviceId) { | 277 | getExtraneousGroupIdTable(DeviceId deviceId) { |
291 | - return createIfAbsentUnchecked(extraneousGroupEntriesById, | 278 | + return extraneousGroupEntriesById.computeIfAbsent(deviceId, k -> new ConcurrentHashMap<>()); |
292 | - deviceId, | ||
293 | - lazyEmptyExtraneousGroupIdTable()); | ||
294 | } | 279 | } |
295 | 280 | ||
296 | /** | 281 | /** | ... | ... |
... | @@ -29,7 +29,10 @@ import org.apache.commons.lang3.concurrent.ConcurrentInitializer; | ... | @@ -29,7 +29,10 @@ import org.apache.commons.lang3.concurrent.ConcurrentInitializer; |
29 | * | 29 | * |
30 | * @param <K> ConcurrentHashMap key type | 30 | * @param <K> ConcurrentHashMap key type |
31 | * @param <V> ConcurrentHashMap value type | 31 | * @param <V> ConcurrentHashMap value type |
32 | + * | ||
33 | + * @deprecated in Hummingbird (1.7.0) | ||
32 | */ | 34 | */ |
35 | +@Deprecated | ||
33 | public final class NewConcurrentHashMap<K, V> | 36 | public final class NewConcurrentHashMap<K, V> |
34 | implements ConcurrentInitializer<ConcurrentMap<K, V>> { | 37 | implements ConcurrentInitializer<ConcurrentMap<K, V>> { |
35 | 38 | ... | ... |
-
Please register or login to post a comment