Merge "Remove M2E lifecycle-mapping <execute/> for yang-maven-plugin"
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / dao / FlowCapableNodeSnapshotDao.java
1 /**\r
2  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 \r
9 package org.opendaylight.openflowplugin.applications.frsync.dao;\r
10 \r
11 import java.util.concurrent.ConcurrentHashMap;\r
12 \r
13 import javax.annotation.Nonnull;\r
14 \r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
17 \r
18 import com.google.common.base.Optional;\r
19 \r
20 /**\r
21  * Adding cache to data access object of {@link FlowCapableNode}.\r
22  */\r
23 public class FlowCapableNodeSnapshotDao implements FlowCapableNodeDao {\r
24 \r
25     private final ConcurrentHashMap<String, FlowCapableNode> cache = new ConcurrentHashMap<>();\r
26 \r
27     public void updateCache(@Nonnull NodeId nodeId, Optional<FlowCapableNode> dataAfter) {\r
28         if (dataAfter.isPresent()) {\r
29             cache.put(nodeId.getValue(), dataAfter.get());\r
30         } else {\r
31             cache.remove(nodeId.getValue());\r
32         }\r
33     }\r
34 \r
35     public Optional<FlowCapableNode> loadByNodeId(@Nonnull NodeId nodeId) {\r
36         final FlowCapableNode node = cache.get(nodeId.getValue());\r
37         return Optional.fromNullable(node);\r
38     }\r
39 \r
40 }\r