2 * Copyright (c) 2016 Cisco Systems, Inc. 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.lispflowmapping.southbound.lisp.cache;
11 import java.util.concurrent.ConcurrentHashMap;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKey;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.metadata.container.MapRegisterCacheMetadata;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.metadata.container.MapRegisterCacheMetadataBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.value.grouping.MapRegisterCacheValue;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.value.grouping.MapRegisterCacheValueBuilder;
18 public class MapRegisterCache {
20 protected final Map<MapRegisterCacheKey, MapRegisterCacheValue> cache;
22 public MapRegisterCache() {
23 cache = new ConcurrentHashMap<>();
26 public void addEntry(final MapRegisterCacheKey mapRegisterCacheKey, final MapRegisterCacheValue
27 mapRegisterCacheValue) {
28 cache.put(mapRegisterCacheKey, mapRegisterCacheValue);
31 public void addEntry(final Map.Entry<MapRegisterCacheKey, MapRegisterCacheValue>
32 mapRegisterCacheEntry) {
33 cache.put(mapRegisterCacheEntry.getKey(), mapRegisterCacheEntry.getValue());
36 public MapRegisterCacheValue getEntry(final MapRegisterCacheKey mapRegisterCacheKey) {
37 if (mapRegisterCacheKey != null) {
38 return cache.get(mapRegisterCacheKey);
43 public void removeEntry(final MapRegisterCacheKey mapRegisterCacheKey) {
44 if (mapRegisterCacheKey != null) {
45 cache.remove(mapRegisterCacheKey);
49 public MapRegisterCacheValue refreshEntry(final MapRegisterCacheKey mapRegisterCacheKey) {
50 final MapRegisterCacheValue mapRegisterCacheValueOld = getEntry(mapRegisterCacheKey);
51 final MapRegisterCacheMetadata mapRegisterCacheMetadataOld = mapRegisterCacheValueOld
52 .getMapRegisterCacheMetadata();
54 final MapRegisterCacheMetadataBuilder mapRegisterCacheMetadataBuilderNew = new MapRegisterCacheMetadataBuilder
55 (mapRegisterCacheMetadataOld);
56 mapRegisterCacheMetadataBuilderNew.setTimestamp(System.currentTimeMillis());
58 final MapRegisterCacheValueBuilder mapRegisterCacheValueBuilderNew = new MapRegisterCacheValueBuilder();
59 mapRegisterCacheValueBuilderNew.setPacketData(mapRegisterCacheValueOld.getPacketData());
60 mapRegisterCacheValueBuilderNew.setMappingAuthkey(mapRegisterCacheValueOld.getMappingAuthkey());
61 mapRegisterCacheValueBuilderNew.setMapRegisterCacheMetadata(mapRegisterCacheMetadataBuilderNew.build());
63 return mapRegisterCacheValueBuilderNew.build();
66 public int cacheSize() {