2 * Copyright (c) 2016 Brocade Communications 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
8 package org.opendaylight.ovsdb.southbound.reconciliation;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
13 import java.util.concurrent.ConcurrentHashMap;
14 import java.util.concurrent.Future;
17 * This class is a task cache manager that provides a cache to store
18 * the task that is queued for the reconciliation. Whenever new task
19 * is submitted to the reconciliation manager, it will be cached in
20 * the cache. If the reconciliation is successful or it's done with
21 * all the attempt of reconciliation,
23 * Caching of the task is required, because reconciliation task might
24 * require longer duration to reconcile and there is a possibility that
25 * meanwhile user can change the configuration in config data store while
26 * task is queued for the reconciliation. In that scenario, reconciliation
27 * manager should not attempt any further reconciliation attempt for that
28 * task. ReconciliationManager will call cancelTask() to cancel the task.
30 * Created by Anil Vishnoi (avishnoi@Brocade.com) on 3/15/16.
32 class ReconciliationTaskManager {
33 private static final Logger LOG = LoggerFactory.getLogger(ReconciliationTaskManager.class);
35 private final ConcurrentHashMap<ReconciliationTask,Future<?>> reconciliationTaskCache
36 = new ConcurrentHashMap();
38 public boolean isTaskQueued(ReconciliationTask task) {
39 return reconciliationTaskCache.containsKey(task);
41 public boolean cancelTask(ReconciliationTask task) {
42 if(reconciliationTaskCache.containsKey(task)){
43 Future<?> taskFuture = reconciliationTaskCache.remove(task);
44 if( !taskFuture.isDone() && !taskFuture.isCancelled() ) {
45 LOG.info("Reconciliation task is cancelled : {}",task);
46 return taskFuture.cancel(true);
52 public void cacheTask(ReconciliationTask task, Future<?> taskFuture) {
53 reconciliationTaskCache.put(task,taskFuture);