Sonar - technical debt of FRS app
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / util / ReconciliationRegistry.java
1 /**
2  * Copyright (c) 2016 Cisco Systems, Inc. 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
9 package org.opendaylight.openflowplugin.applications.frsync.util;
10
11 import java.util.Date;
12 import java.util.Map;
13 import java.util.concurrent.ConcurrentHashMap;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * Holder of registration request for reconciliation (fresh operational).
20  */
21 public class ReconciliationRegistry {
22     private static final Logger LOG = LoggerFactory.getLogger(ReconciliationRegistry.class);
23     private final Map<NodeId, Date> registration = new ConcurrentHashMap<>();
24
25     public Date register(NodeId nodeId) {
26         Date timestamp = new Date();
27         registration.put(nodeId, timestamp);
28         LOG.debug("Registered for next consistent operational: {}", nodeId.getValue());
29         // TODO  elicit statistics gathering if not running actually
30         return timestamp;
31     }
32
33     public Date unregisterIfRegistered(NodeId nodeId) {
34         Date timestamp = registration.remove(nodeId);
35         if (timestamp != null) {
36             LOG.debug("Unregistered for next consistent operational: {}", nodeId.getValue());
37         }
38         return timestamp;
39     }
40
41     public boolean isRegistered(NodeId nodeId) {
42         return registration.get(nodeId) != null;
43     }
44
45     public Date getRegistrationTimestamp(NodeId nodeId) {
46         return registration.get(nodeId);
47     }
48
49 }