L2 Gw create changes related to ITM Tunnels creation in neutronvpn module
[vpnservice.git] / neutronvpn / neutronvpn-api / src / main / java / org / opendaylight / vpnservice / neutronvpn / api / l2gw / utils / L2GatewayCacheUtils.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.vpnservice.neutronvpn.api.l2gw.utils;
9
10 import java.util.concurrent.ConcurrentMap;
11
12 import org.opendaylight.vpnservice.neutronvpn.api.l2gw.L2GatewayDevice;
13 import org.opendaylight.vpnservice.utils.cache.CacheUtil;
14
15 public class L2GatewayCacheUtils {
16     public static final String L2GATEWAY_CACHE_NAME = "L2GW";
17
18     public static void createL2DeviceCache() {
19         if (CacheUtil.getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME) == null) {
20             CacheUtil.createCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
21         }
22     }
23
24     public static void addL2DeviceToCache(String devicename, L2GatewayDevice l2GwDevice) {
25         ConcurrentMap<String, L2GatewayDevice> cachedMap = (ConcurrentMap<String, L2GatewayDevice>) CacheUtil
26                 .getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
27         cachedMap.put(devicename, l2GwDevice);
28     }
29
30     public static L2GatewayDevice removeL2DeviceFromCache(String devicename) {
31         ConcurrentMap<String, L2GatewayDevice> cachedMap = (ConcurrentMap<String, L2GatewayDevice>) CacheUtil
32                 .getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
33         return cachedMap.remove(devicename);
34     }
35
36     public static L2GatewayDevice getL2DeviceFromCache(String devicename) {
37         ConcurrentMap<String, L2GatewayDevice> cachedMap = (ConcurrentMap<String, L2GatewayDevice>) CacheUtil
38                 .getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
39         return cachedMap.get(devicename);
40     }
41 }