Upgrade to the Neon base platform
[netvirt.git] / cache / impl / src / main / java / org / opendaylight / netvirt / cache / impl / l2gw / L2GatewayCacheImpl.java
1 /*
2  * Copyright (c) 2017 Inocybe Technologies and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netvirt.cache.impl.l2gw;
9
10 import java.util.Collection;
11 import java.util.Collections;
12 import java.util.concurrent.ConcurrentHashMap;
13 import java.util.concurrent.ConcurrentMap;
14 import javax.inject.Singleton;
15 import org.apache.aries.blueprint.annotation.service.Service;
16 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
17 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
18
19 /**
20  * Implementation of L2GatewayCache.
21  *
22  * @author Thomas Pantelis
23  */
24 @Singleton
25 @Service(classes = L2GatewayCache.class)
26 public class L2GatewayCacheImpl implements L2GatewayCache {
27     private final ConcurrentMap<String, L2GatewayDevice> cache = new ConcurrentHashMap<>();
28
29     @Override
30     public L2GatewayDevice addOrGet(String deviceName) {
31         return cache.computeIfAbsent(deviceName, key -> new L2GatewayDevice(deviceName));
32     }
33
34     @Override
35     public L2GatewayDevice remove(String deviceName) {
36         return deviceName != null ? cache.remove(deviceName) : null;
37     }
38
39     @Override
40     public L2GatewayDevice get(String deviceName) {
41         return deviceName != null ? cache.get(deviceName) : null;
42     }
43
44     @Override
45     public Collection<L2GatewayDevice> getAll() {
46         return Collections.unmodifiableCollection(cache.values());
47     }
48 }