Merge "Bug 9127: Make IT more robust when receiving packets"
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / timebucket / containers / TimeBucket.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.lispflowmapping.implementation.timebucket.containers;
10
11 import java.util.concurrent.ConcurrentHashMap;
12
13 import org.opendaylight.lispflowmapping.implementation.MappingSystem;
14 import org.opendaylight.lispflowmapping.lisp.type.MappingData;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * Created by Shakib Ahmed on 12/1/16.
21  */
22 public class TimeBucket {
23     private static final Logger LOG = LoggerFactory.getLogger(TimeBucket.class);
24
25     private final ConcurrentHashMap<Eid, MappingData> bucketElements;
26
27     private final MappingSystem mappingSystem;
28
29     public TimeBucket(MappingSystem mappingSystem) {
30         bucketElements = new ConcurrentHashMap<>();
31         this.mappingSystem = mappingSystem;
32     }
33
34     public void add(Eid key, MappingData mappingData) {
35         bucketElements.put(key, mappingData);
36     }
37
38     public void removeFromBucketOnly(Eid key) {
39         MappingData mappingData = bucketElements.get(key);
40
41         if (mappingData != null) {
42             bucketElements.remove(key);
43         }
44     }
45
46     public void clearBucket() {
47         bucketElements.forEach((key, mappingData) -> {
48             mappingSystem.handleSbExpiredMapping(key, null, mappingData);
49         });
50     }
51 }