Enable checkstyle for neutronvpn
[netvirt.git] / vpnservice / neutronvpn / neutronvpn-api / src / main / java / org / opendaylight / netvirt / 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.netvirt.neutronvpn.api.l2gw.utils;
9
10 import java.util.concurrent.ConcurrentMap;
11 import org.opendaylight.genius.utils.cache.CacheUtil;
12 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
13
14 public class L2GatewayCacheUtils {
15     public static final String L2GATEWAY_CACHE_NAME = "L2GW";
16
17     public static void createL2DeviceCache() {
18         if (CacheUtil.getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME) == null) {
19             CacheUtil.createCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
20         }
21     }
22
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);
27     }
28
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);
33     }
34
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);
39     }
40
41     public static ConcurrentMap<String, L2GatewayDevice> getCache() {
42         return (ConcurrentMap<String, L2GatewayDevice>) CacheUtil
43                 .getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
44     }
45
46 }