2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.neutronvpn.api.l2gw.utils;
10 import java.util.concurrent.ConcurrentMap;
11 import org.opendaylight.genius.utils.cache.CacheUtil;
12 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
14 public class L2GatewayCacheUtils {
15 public static final String L2GATEWAY_CACHE_NAME = "L2GW";
17 public static void createL2DeviceCache() {
18 if (CacheUtil.getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME) == null) {
19 CacheUtil.createCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
23 public static void addL2DeviceToCache(String devicename, L2GatewayDevice l2GwDevice) {
24 ConcurrentMap<String, L2GatewayDevice> cachedMap = (ConcurrentMap<String, L2GatewayDevice>) CacheUtil
25 .getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
26 cachedMap.put(devicename, l2GwDevice);
29 public static L2GatewayDevice removeL2DeviceFromCache(String devicename) {
30 ConcurrentMap<String, L2GatewayDevice> cachedMap = (ConcurrentMap<String, L2GatewayDevice>) CacheUtil
31 .getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
32 return cachedMap.remove(devicename);
35 public static L2GatewayDevice getL2DeviceFromCache(String devicename) {
36 ConcurrentMap<String, L2GatewayDevice> cachedMap = (ConcurrentMap<String, L2GatewayDevice>) CacheUtil
37 .getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
38 return cachedMap.get(devicename);
41 public static ConcurrentMap<String, L2GatewayDevice> getCache() {
42 return (ConcurrentMap<String, L2GatewayDevice>) CacheUtil
43 .getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);