2 * Copyright (c) 2017 Inocybe Technologies and others. All rights reserved.
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
8 package org.opendaylight.netvirt.cache.impl.l2gw;
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;
20 * Implementation of L2GatewayCache.
22 * @author Thomas Pantelis
25 @Service(classes = L2GatewayCache.class)
26 public class L2GatewayCacheImpl implements L2GatewayCache {
27 private final ConcurrentMap<String, L2GatewayDevice> cache = new ConcurrentHashMap<>();
30 public L2GatewayDevice addOrGet(String deviceName) {
31 return cache.computeIfAbsent(deviceName, key -> new L2GatewayDevice(deviceName));
35 public L2GatewayDevice remove(String deviceName) {
36 return deviceName != null ? cache.remove(deviceName) : null;
40 public L2GatewayDevice get(String deviceName) {
41 return deviceName != null ? cache.get(deviceName) : null;
45 public Collection<L2GatewayDevice> getAll() {
46 return Collections.unmodifiableCollection(cache.values());