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
9 package org.opendaylight.openflowplugin.applications.frsync.util;
11 import java.util.Date;
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;
19 * Holder of registration request for fresh operational.
21 public class RetryRegistry {
23 private static final Logger LOG = LoggerFactory.getLogger(RetryRegistry.class);
24 private final Map<NodeId, Date> registration = new ConcurrentHashMap<>();
25 public static final String DATE_AND_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
27 public Date register(NodeId nodeId) {
28 Date timestamp = new Date();
29 registration.put(nodeId, timestamp);
30 if (timestamp != null) {
31 LOG.debug("Registered for next consistent operational: {}", nodeId.getValue());
36 public Date unregisterIfRegistered(NodeId nodeId) {
37 Date timestamp = registration.remove(nodeId);
38 if (timestamp != null) {
39 LOG.debug("Unregistered for next consistent operational: {}", nodeId.getValue());
44 public boolean isRegistered(NodeId nodeId) {
45 return registration.get(nodeId) != null;
48 public Date getRegistration(NodeId nodeId) {
49 return registration.get(nodeId);