Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.store.newresource.impl; |
| 17 | |
| 18 | import com.google.common.annotations.Beta; |
| 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Reference; |
| 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 23 | import org.apache.felix.scr.annotations.Service; |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 24 | import org.onosproject.net.newresource.ResourceConsumer; |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 25 | import org.onosproject.net.newresource.ResourcePath; |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 26 | import org.onosproject.net.newresource.ResourceStore; |
| 27 | import org.onosproject.store.serializers.KryoNamespaces; |
| 28 | import org.onosproject.store.service.ConsistentMap; |
| 29 | import org.onosproject.store.service.Serializer; |
| 30 | import org.onosproject.store.service.StorageService; |
| 31 | import org.onosproject.store.service.TransactionContext; |
| 32 | import org.onosproject.store.service.TransactionException; |
| 33 | import org.onosproject.store.service.TransactionalMap; |
| 34 | import org.onosproject.store.service.Versioned; |
| 35 | import org.slf4j.Logger; |
| 36 | import org.slf4j.LoggerFactory; |
| 37 | |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 38 | import java.util.ArrayList; |
| 39 | import java.util.Arrays; |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 40 | import java.util.Collection; |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 41 | import java.util.Collections; |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 42 | import java.util.Iterator; |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 43 | import java.util.LinkedHashSet; |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 44 | import java.util.List; |
| 45 | import java.util.Map; |
| 46 | import java.util.Optional; |
| 47 | import java.util.stream.Collectors; |
| 48 | |
| 49 | import static com.google.common.base.Preconditions.checkArgument; |
| 50 | import static com.google.common.base.Preconditions.checkNotNull; |
| 51 | |
| 52 | /** |
| 53 | * Implementation of ResourceStore using TransactionalMap. |
| 54 | */ |
| 55 | @Component(immediate = true, enabled = false) |
| 56 | @Service |
| 57 | @Beta |
| 58 | public class ConsistentResourceStore implements ResourceStore { |
| 59 | private static final Logger log = LoggerFactory.getLogger(ConsistentResourceStore.class); |
| 60 | |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 61 | private static final String CONSUMER_MAP = "onos-resource-consumers"; |
| 62 | private static final String CHILD_MAP = "onos-resource-children"; |
| 63 | private static final Serializer SERIALIZER = Serializer.using( |
| 64 | Arrays.asList(KryoNamespaces.BASIC, KryoNamespaces.API)); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 65 | |
| 66 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 67 | protected StorageService service; |
| 68 | |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 69 | private ConsistentMap<ResourcePath, ResourceConsumer> consumerMap; |
| 70 | private ConsistentMap<ResourcePath, List<ResourcePath>> childMap; |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 71 | |
| 72 | @Activate |
| 73 | public void activate() { |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 74 | consumerMap = service.<ResourcePath, ResourceConsumer>consistentMapBuilder() |
| 75 | .withName(CONSUMER_MAP) |
| 76 | .withSerializer(SERIALIZER) |
| 77 | .build(); |
| 78 | childMap = service.<ResourcePath, List<ResourcePath>>consistentMapBuilder() |
| 79 | .withName(CHILD_MAP) |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 80 | .withSerializer(SERIALIZER) |
| 81 | .build(); |
| 82 | } |
| 83 | |
| 84 | @Override |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 85 | public Optional<ResourceConsumer> getConsumer(ResourcePath resource) { |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 86 | checkNotNull(resource); |
| 87 | |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 88 | Versioned<ResourceConsumer> consumer = consumerMap.get(resource); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 89 | if (consumer == null) { |
| 90 | return Optional.empty(); |
| 91 | } |
| 92 | |
| 93 | return Optional.of(consumer.value()); |
| 94 | } |
| 95 | |
| 96 | @Override |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 97 | public boolean register(List<ResourcePath> resources) { |
| 98 | checkNotNull(resources); |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 99 | |
| 100 | TransactionContext tx = service.transactionContextBuilder().build(); |
| 101 | tx.begin(); |
| 102 | |
| 103 | try { |
| 104 | TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap = |
| 105 | tx.getTransactionalMap(CHILD_MAP, SERIALIZER); |
| 106 | |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 107 | Map<ResourcePath, List<ResourcePath>> resourceMap = resources.stream() |
| 108 | .filter(x -> x.parent().isPresent()) |
| 109 | .collect(Collectors.groupingBy(x -> x.parent().get())); |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 110 | |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 111 | for (Map.Entry<ResourcePath, List<ResourcePath>> entry: resourceMap.entrySet()) { |
| 112 | if (!isRegistered(childTxMap, entry.getKey())) { |
| 113 | return abortTransaction(tx); |
| 114 | } |
| 115 | |
| 116 | if (!appendValues(childTxMap, entry.getKey(), entry.getValue())) { |
| 117 | return abortTransaction(tx); |
| 118 | } |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | return commitTransaction(tx); |
| 122 | } catch (TransactionException e) { |
| 123 | log.error("Exception thrown, abort the transaction", e); |
| 124 | return abortTransaction(tx); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | @Override |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 129 | public boolean unregister(List<ResourcePath> resources) { |
| 130 | checkNotNull(resources); |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame] | 131 | |
| 132 | TransactionContext tx = service.transactionContextBuilder().build(); |
| 133 | tx.begin(); |
| 134 | |
| 135 | try { |
| 136 | TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap = |
| 137 | tx.getTransactionalMap(CHILD_MAP, SERIALIZER); |
| 138 | TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap = |
| 139 | tx.getTransactionalMap(CONSUMER_MAP, SERIALIZER); |
| 140 | |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 141 | Map<ResourcePath, List<ResourcePath>> resourceMap = resources.stream() |
| 142 | .filter(x -> x.parent().isPresent()) |
| 143 | .collect(Collectors.groupingBy(x -> x.parent().get())); |
| 144 | |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame] | 145 | // even if one of the resources is allocated to a consumer, |
| 146 | // all unregistrations are regarded as failure |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 147 | for (Map.Entry<ResourcePath, List<ResourcePath>> entry: resourceMap.entrySet()) { |
| 148 | if (entry.getValue().stream().anyMatch(x -> consumerTxMap.get(x) != null)) { |
| 149 | return abortTransaction(tx); |
| 150 | } |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame] | 151 | |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 152 | if (!removeValues(childTxMap, entry.getKey(), entry.getValue())) { |
| 153 | return abortTransaction(tx); |
| 154 | } |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | return commitTransaction(tx); |
| 158 | } catch (TransactionException e) { |
| 159 | log.error("Exception thrown, abort the transaction", e); |
| 160 | return abortTransaction(tx); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | @Override |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 165 | public boolean allocate(List<ResourcePath> resources, ResourceConsumer consumer) { |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 166 | checkNotNull(resources); |
| 167 | checkNotNull(consumer); |
| 168 | |
| 169 | TransactionContext tx = service.transactionContextBuilder().build(); |
| 170 | tx.begin(); |
| 171 | |
| 172 | try { |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 173 | TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap = |
| 174 | tx.getTransactionalMap(CHILD_MAP, SERIALIZER); |
| 175 | TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap = |
| 176 | tx.getTransactionalMap(CONSUMER_MAP, SERIALIZER); |
| 177 | |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 178 | for (ResourcePath resource: resources) { |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 179 | if (!isRegistered(childTxMap, resource)) { |
| 180 | return abortTransaction(tx); |
| 181 | } |
| 182 | |
| 183 | ResourceConsumer oldValue = consumerTxMap.put(resource, consumer); |
| 184 | if (oldValue != null) { |
Sho SHIMIZU | d29847f | 2015-08-13 09:10:59 -0700 | [diff] [blame] | 185 | return abortTransaction(tx); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 186 | } |
| 187 | } |
Sho SHIMIZU | d29847f | 2015-08-13 09:10:59 -0700 | [diff] [blame] | 188 | |
| 189 | return commitTransaction(tx); |
Sho SHIMIZU | 264e4b7 | 2015-08-12 12:22:14 -0700 | [diff] [blame] | 190 | } catch (TransactionException e) { |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 191 | log.error("Exception thrown, abort the transaction", e); |
Sho SHIMIZU | d29847f | 2015-08-13 09:10:59 -0700 | [diff] [blame] | 192 | return abortTransaction(tx); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
| 196 | @Override |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 197 | public boolean release(List<ResourcePath> resources, List<ResourceConsumer> consumers) { |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 198 | checkNotNull(resources); |
| 199 | checkNotNull(consumers); |
| 200 | checkArgument(resources.size() == consumers.size()); |
| 201 | |
| 202 | TransactionContext tx = service.transactionContextBuilder().build(); |
| 203 | tx.begin(); |
| 204 | |
| 205 | try { |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 206 | TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap = |
| 207 | tx.getTransactionalMap(CONSUMER_MAP, SERIALIZER); |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 208 | Iterator<ResourcePath> resourceIte = resources.iterator(); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 209 | Iterator<ResourceConsumer> consumerIte = consumers.iterator(); |
| 210 | |
| 211 | while (resourceIte.hasNext() && consumerIte.hasNext()) { |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 212 | ResourcePath resource = resourceIte.next(); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 213 | ResourceConsumer consumer = consumerIte.next(); |
| 214 | |
| 215 | // if this single release fails (because the resource is allocated to another consumer, |
| 216 | // the whole release fails |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 217 | if (!consumerTxMap.remove(resource, consumer)) { |
Sho SHIMIZU | d29847f | 2015-08-13 09:10:59 -0700 | [diff] [blame] | 218 | return abortTransaction(tx); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
Sho SHIMIZU | d29847f | 2015-08-13 09:10:59 -0700 | [diff] [blame] | 222 | return commitTransaction(tx); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 223 | } catch (TransactionException e) { |
| 224 | log.error("Exception thrown, abort the transaction", e); |
Sho SHIMIZU | d29847f | 2015-08-13 09:10:59 -0700 | [diff] [blame] | 225 | return abortTransaction(tx); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
| 229 | @Override |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 230 | public Collection<ResourcePath> getResources(ResourceConsumer consumer) { |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 231 | checkNotNull(consumer); |
| 232 | |
| 233 | // NOTE: getting all entries may become performance bottleneck |
| 234 | // TODO: revisit for better backend data structure |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 235 | return consumerMap.entrySet().stream() |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 236 | .filter(x -> x.getValue().value().equals(consumer)) |
| 237 | .map(Map.Entry::getKey) |
| 238 | .collect(Collectors.toList()); |
| 239 | } |
| 240 | |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 241 | @Override |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 242 | public <T> Collection<ResourcePath> getAllocatedResources(ResourcePath parent, Class<T> cls) { |
| 243 | checkNotNull(parent); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 244 | checkNotNull(cls); |
| 245 | |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 246 | Versioned<List<ResourcePath>> children = childMap.get(parent); |
| 247 | if (children == null) { |
| 248 | return Collections.emptyList(); |
| 249 | } |
| 250 | |
| 251 | return children.value().stream() |
| 252 | .filter(x -> x.lastComponent().getClass().equals(cls)) |
| 253 | .filter(consumerMap::containsKey) |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 254 | .collect(Collectors.toList()); |
| 255 | } |
Sho SHIMIZU | d29847f | 2015-08-13 09:10:59 -0700 | [diff] [blame] | 256 | |
| 257 | /** |
| 258 | * Abort the transaction. |
| 259 | * |
| 260 | * @param tx transaction context |
| 261 | * @return always false |
| 262 | */ |
| 263 | private boolean abortTransaction(TransactionContext tx) { |
| 264 | tx.abort(); |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Commit the transaction. |
| 270 | * |
| 271 | * @param tx transaction context |
| 272 | * @return always true |
| 273 | */ |
| 274 | private boolean commitTransaction(TransactionContext tx) { |
| 275 | tx.commit(); |
| 276 | return true; |
| 277 | } |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 278 | |
| 279 | /** |
| 280 | * Appends the values to the existing values associated with the specified key. |
Sho SHIMIZU | 4568c41 | 2015-08-21 16:39:07 -0700 | [diff] [blame^] | 281 | * If the map already has all the given values, appending will not happen. |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 282 | * |
| 283 | * @param map map holding multiple values for a key |
| 284 | * @param key key specifying values |
| 285 | * @param values values to be appended |
| 286 | * @param <K> type of the key |
| 287 | * @param <V> type of the element of the list |
| 288 | * @return true if the operation succeeds, false otherwise. |
| 289 | */ |
Sho SHIMIZU | 2a1b233 | 2015-08-18 22:40:12 -0700 | [diff] [blame] | 290 | private <K, V> boolean appendValues(TransactionalMap<K, List<V>> map, K key, List<V> values) { |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 291 | List<V> oldValues = map.get(key); |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 292 | if (oldValues == null) { |
Sho SHIMIZU | 4568c41 | 2015-08-21 16:39:07 -0700 | [diff] [blame^] | 293 | return map.replace(key, oldValues, new ArrayList<>(values)); |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Sho SHIMIZU | 4568c41 | 2015-08-21 16:39:07 -0700 | [diff] [blame^] | 296 | LinkedHashSet<V> oldSet = new LinkedHashSet<>(oldValues); |
| 297 | if (oldSet.containsAll(values)) { |
| 298 | // don't write to map because all values are already stored |
| 299 | return true; |
| 300 | } |
| 301 | |
| 302 | oldSet.addAll(values); |
| 303 | return map.replace(key, oldValues, new ArrayList<>(oldSet)); |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /** |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame] | 307 | * Removes teh values from the existing values associated with the specified key. |
| 308 | * |
| 309 | * @param map map holding multiple values for a key |
| 310 | * @param key key specifying values |
| 311 | * @param values values to be removed |
| 312 | * @param <K> type of the key |
| 313 | * @param <V> type of the element of the list |
| 314 | * @return true if the operation succeeds, false otherwise |
| 315 | */ |
| 316 | private <K, V> boolean removeValues(TransactionalMap<K, List<V>> map, K key, List<V> values) { |
| 317 | List<V> oldValues = map.get(key); |
| 318 | List<V> newValues; |
| 319 | if (oldValues == null) { |
| 320 | newValues = new ArrayList<>(); |
| 321 | } else { |
| 322 | LinkedHashSet<V> newSet = new LinkedHashSet<>(oldValues); |
| 323 | newSet.removeAll(values); |
| 324 | newValues = new ArrayList<>(newSet); |
| 325 | } |
| 326 | |
| 327 | return map.replace(key, oldValues, newValues); |
| 328 | } |
| 329 | |
| 330 | /** |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 331 | * Checks if the specified resource is registered as a child of a resource in the map. |
| 332 | * |
| 333 | * @param map map storing parent - child relationship of resources |
| 334 | * @param resource resource to be checked |
| 335 | * @return true if the resource is registered, false otherwise. |
| 336 | */ |
| 337 | private boolean isRegistered(TransactionalMap<ResourcePath, List<ResourcePath>> map, ResourcePath resource) { |
| 338 | // root is always regarded to be registered |
Sho SHIMIZU | 0112078 | 2015-08-21 15:48:43 -0700 | [diff] [blame] | 339 | if (resource.isRoot()) { |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 340 | return true; |
| 341 | } |
| 342 | |
| 343 | List<ResourcePath> value = map.get(resource.parent().get()); |
| 344 | return value != null && value.contains(resource); |
| 345 | } |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 346 | } |