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 com.google.common.base.Optional;
\r
12 import java.util.concurrent.ConcurrentHashMap;
\r
13 import javax.annotation.Nonnull;
\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
\r
18 * Adding cache to data access object of {@link FlowCapableNode}.
\r
20 public class FlowCapableNodeSnapshotDao implements FlowCapableNodeDao {
\r
22 private final ConcurrentHashMap<String, FlowCapableNode> cache = new ConcurrentHashMap<>();
\r
24 public void updateCache(@Nonnull NodeId nodeId, Optional<FlowCapableNode> dataAfter) {
\r
25 if (dataAfter.isPresent()) {
\r
26 cache.put(nodeId.getValue(), dataAfter.get());
\r
28 cache.remove(nodeId.getValue());
\r
32 public Optional<FlowCapableNode> loadByNodeId(@Nonnull NodeId nodeId) {
\r
33 final FlowCapableNode node = cache.get(nodeId.getValue());
\r
34 return Optional.fromNullable(node);
\r