2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
\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
9 package org.opendaylight.openflowplugin.applications.frsync.dao;
\r
11 import java.util.concurrent.ConcurrentHashMap;
\r
13 import javax.annotation.Nonnull;
\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
18 import com.google.common.base.Optional;
\r
21 * Adding cache to data access object of {@link FlowCapableNode}.
\r
23 public class FlowCapableNodeSnapshotDao implements FlowCapableNodeDao {
\r
25 private final ConcurrentHashMap<String, FlowCapableNode> cache = new ConcurrentHashMap<>();
\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
31 cache.remove(nodeId.getValue());
\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