Merge "BUG-2188 :To report (TCP) port number (for the OpenFlow connection) for switch...
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / dao / FlowCapableNodeCachedDao.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 javax.annotation.Nonnull;\r
12 \r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
15 \r
16 import com.google.common.base.Optional;\r
17 \r
18 /**\r
19  * Implementation of data access object for {@link FlowCapableNode}.\r
20  * Contains pair of snapshot and odl DAOs.\r
21  */\r
22 public class FlowCapableNodeCachedDao implements FlowCapableNodeDao {\r
23 \r
24     private final FlowCapableNodeDao snapshotDao;\r
25     private final FlowCapableNodeDao odlDao;\r
26 \r
27     public FlowCapableNodeCachedDao(FlowCapableNodeDao snapshotDao, FlowCapableNodeDao odlDao) {\r
28         this.snapshotDao = snapshotDao;\r
29         this.odlDao = odlDao;\r
30     }\r
31 \r
32     public Optional<FlowCapableNode> loadByNodeId(@Nonnull NodeId nodeId) {\r
33         final Optional<FlowCapableNode> node = snapshotDao.loadByNodeId(nodeId);\r
34 \r
35         if (node.isPresent()) {\r
36             return node;\r
37         }\r
38 \r
39         return odlDao.loadByNodeId(nodeId);\r
40     }\r
41 \r
42 }\r