2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.cloudservicechain.utils;
10 import java.util.List;
11 import java.util.concurrent.ConcurrentHashMap;
12 import java.util.concurrent.ConcurrentMap;
13 import javax.annotation.Nonnull;
14 import javax.annotation.Nullable;
15 import javax.annotation.PostConstruct;
16 import javax.inject.Inject;
17 import javax.inject.Singleton;
18 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.cloud.servicechain.state.rev160711.vpn.to.pseudo.port.list.VpnToPseudoPortData;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * Manages a per-blade cache, which is fed by a clustered data change listener.
27 public class VpnPseudoPortCache {
28 private static final Logger LOG = LoggerFactory.getLogger(VpnPseudoPortCache.class);
30 private final DataBroker broker;
31 private final ConcurrentMap<String, Long> cache = new ConcurrentHashMap<>();
34 public VpnPseudoPortCache(DataBroker broker) {
40 LOG.info("Initial read of Vpn to VpnPseudoPort map from Datastore");
41 List<VpnToPseudoPortData> allVpnToPseudoPortData = VpnServiceChainUtils.getAllVpnToPseudoPortData(broker);
42 for (VpnToPseudoPortData vpnToPseudoPort : allVpnToPseudoPortData) {
43 add(vpnToPseudoPort.getVrfId(), vpnToPseudoPort.getVpnLportTag());
47 public void add(@Nonnull String vrfId, long vpnPseudoLportTag) {
48 LOG.debug("Adding vpn {} and vpnPseudoLportTag {} to VpnPseudoPortCache", vrfId, vpnPseudoLportTag);
49 cache.put(vrfId, Long.valueOf(vpnPseudoLportTag));
53 public Long get(@Nonnull String vrfId) {
54 return cache.get(vrfId);
58 public Long remove(@Nonnull String vrfId) {
59 LOG.debug("Removing vpn {} from VpnPseudoPortCache", vrfId);
60 return cache.remove(vrfId);