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
diff --git a/neutronvpn/neutronvpn-api/src/main/java/org/opendaylight/vpnservice/neutronvpn/api/l2gw/utils/L2GatewayCacheUtils.java b/neutronvpn/neutronvpn-api/src/main/java/org/opendaylight/vpnservice/neutronvpn/api/l2gw/utils/L2GatewayCacheUtils.java
new file mode 100644 (file)
index 0000000..d941dec
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.vpnservice.neutronvpn.api.l2gw.utils;
+
+import java.util.concurrent.ConcurrentMap;
+
+import org.opendaylight.vpnservice.neutronvpn.api.l2gw.L2GatewayDevice;
+import org.opendaylight.vpnservice.utils.cache.CacheUtil;
+
+public class L2GatewayCacheUtils {
+    public static final String L2GATEWAY_CACHE_NAME = "L2GW";
+
+    public static void createL2DeviceCache() {
+        if (CacheUtil.getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME) == null) {
+            CacheUtil.createCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
+        }
+    }
+
+    public static void addL2DeviceToCache(String devicename, L2GatewayDevice l2GwDevice) {
+        ConcurrentMap<String, L2GatewayDevice> cachedMap = (ConcurrentMap<String, L2GatewayDevice>) CacheUtil
+                .getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
+        cachedMap.put(devicename, l2GwDevice);
+    }
+
+    public static L2GatewayDevice removeL2DeviceFromCache(String devicename) {
+        ConcurrentMap<String, L2GatewayDevice> cachedMap = (ConcurrentMap<String, L2GatewayDevice>) CacheUtil
+                .getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
+        return cachedMap.remove(devicename);
+    }
+
+    public static L2GatewayDevice getL2DeviceFromCache(String devicename) {
+        ConcurrentMap<String, L2GatewayDevice> cachedMap = (ConcurrentMap<String, L2GatewayDevice>) CacheUtil
+                .getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
+        return cachedMap.get(devicename);
+    }
+}