66b1f95fc924ed04817671b284b252fd57b14887
[netvirt.git] / dhcpservice / impl / src / main / java / org / opendaylight / netvirt / dhcpservice / DhcpPortCache.java
1 /*
2  * Copyright © 2015, 2018 Ericsson India Global Services Pvt Ltd. and others.  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 package org.opendaylight.netvirt.dhcpservice;
9
10 import java.util.concurrent.ConcurrentHashMap;
11 import javax.annotation.Nonnull;
12 import javax.annotation.Nullable;
13 import javax.annotation.PostConstruct;
14 import javax.inject.Singleton;
15
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 @Singleton
21 public class DhcpPortCache {
22
23     private static final Logger LOG = LoggerFactory.getLogger(DhcpPortCache.class);
24     private final ConcurrentHashMap<String, Port> portMap = new ConcurrentHashMap<>();
25
26     @PostConstruct
27     public void init() {
28         LOG.trace("Initialize DhcpPortCache. ");
29     }
30
31     public  void put(@Nonnull  String interfaceName, Port port) {
32         portMap.put(interfaceName, port);
33         LOG.trace("Added the interface {} to DhcpPortCache",interfaceName);
34     }
35
36     @Nullable
37     public Port get(@Nonnull String interfaceName) {
38         return portMap.get(interfaceName);
39     }
40
41     public void remove(@Nonnull String interfaceName) {
42         portMap.remove(interfaceName);
43     }
44 }