2 * Copyright (c) 2017 Cisco Systems, Inc. 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.neutron.mappingmanager;
10 import java.util.ArrayList;
11 import java.util.List;
12 import java.util.concurrent.ConcurrentHashMap;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
19 * Created by Shakib Ahmed on 1/12/17.
21 public class HostIdToRlocMapper {
22 private static final Logger LOG = LoggerFactory.getLogger(HostIdToRlocMapper.class);
24 private ConcurrentHashMap<String, List<Rloc>> mapper;
25 private static HostIdToRlocMapper instance;
27 private HostIdToRlocMapper() {
28 mapper = new ConcurrentHashMap();
31 public static synchronized HostIdToRlocMapper getInstance() {
32 if (instance == null) {
33 instance = new HostIdToRlocMapper();
38 public synchronized void addMapping(String hostId, Rloc hostRloc) {
39 List<Rloc> hostIdSpeceficRlocs = mapper.get(hostId);
41 if (hostIdSpeceficRlocs == null) {
42 hostIdSpeceficRlocs = new ArrayList<>();
45 hostIdSpeceficRlocs.add(hostRloc);
46 mapper.put(hostId, hostIdSpeceficRlocs);
47 LOG.debug("Adding " + hostRloc.getAddress() + " as Rloc of " + hostId);
50 public List<Rloc> getRlocs(String hostId) {
51 return mapper.get(hostId);
54 public synchronized void deleteMapping(String hostId) {
55 //for now, delete all rlocs
56 mapper.remove(hostId);