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 static java.util.Objects.requireNonNull;
12 import org.opendaylight.ovsdb.southbound.OvsdbConnectionManager;
13 import org.opendaylight.ovsdb.southbound.reconciliation.connection.ConnectionReconciliationTask;
14 import org.opendaylight.yangtools.yang.binding.DataObject;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 * Abstract implementation of a reconciliation task. Each new type of
19 * resource configuration reconciliation task should extend this class
20 * and implement the abstract methods.
22 public abstract class ReconciliationTask implements Runnable {
23 protected final ReconciliationManager reconciliationManager;
24 protected final OvsdbConnectionManager connectionManager;
25 protected final InstanceIdentifier<?> nodeIid;
26 protected final DataObject configData;
28 protected ReconciliationTask(final ReconciliationManager reconciliationManager,
29 final OvsdbConnectionManager connectionManager,
30 final InstanceIdentifier<?> nodeIid, final DataObject configData) {
31 this.reconciliationManager = requireNonNull(reconciliationManager, "Reconciliation manager must not be null");
32 this.connectionManager = requireNonNull(connectionManager, "Connection manager must not be null");
33 this.nodeIid = requireNonNull(nodeIid, "Node Iid must not be null");
34 this.configData = configData;
38 * Method contains task reconciliation logic. Please refer to
39 * {@link ConnectionReconciliationTask#reconcileConfiguration(OvsdbConnectionManager)}
41 * @param connectionManagerOfDevice Connection manager to get connection instance of the device
42 * @return True if reconciliation was successful, else false
44 public abstract boolean reconcileConfiguration(OvsdbConnectionManager connectionManagerOfDevice);
47 * Extended task should implement the logic that decides whether retry for the task
48 * is required or not. If retry is required but it does not requires any delay, submit
49 * the task immediately using {@link ReconciliationManager#enqueue(ReconciliationTask)}.
50 * If retry requires delay, use {@link ReconciliationManager#enqueueForRetry(ReconciliationTask)}
51 * and specify the delay using {@link #retryDelayInMills()}.
52 * If data store operation is required to decide if the task need retry, please implement
53 * it as an async operation and submit the task on the callback of the future.
55 * Note:Please do not write blocking data store operations
56 * {@link ConnectionReconciliationTask#doRetry(boolean)}
58 * @param wasPreviousAttemptSuccessful Status of the previous attempt
60 public abstract void doRetry(boolean wasPreviousAttemptSuccessful);
63 * Extended task should implement the logic that check the readiness of the task
64 * for execution. If task is ready for the execution, submit it for immediate
65 * execution using {@link ReconciliationManager#enqueue(ReconciliationTask)}.
66 * If task is not ready for execution yet, enqueue it again for delayed execution
67 * using {@link ReconciliationManager#enqueueForRetry(ReconciliationTask)}.
68 * To check the readiness of the task, if the data store operation is required, please
69 * implement it as an async operation and submit the task on the callback of the future.
71 * Note:Please do not write blocking data store operations
72 * {@link ConnectionReconciliationTask#doRetry(boolean)}
75 public abstract void checkReadinessAndProcess();
78 * Method returns the time interval for retrying the failed task.
79 * {@link ReconciliationTask#doRetry(boolean)}
82 public abstract long retryDelayInMills();
86 boolean status = this.reconcileConfiguration(connectionManager);
91 public boolean equals(final Object obj) {
95 if (obj == null || getClass() != obj.getClass()) {
99 final ReconciliationTask other = (ReconciliationTask) obj;
100 return nodeIid.equals(other.nodeIid);
104 public int hashCode() {
105 return getClass().hashCode() + nodeIid.hashCode();
109 public String toString() {
110 return "ReconciliationTask{ type=" + getClass().toString() + ", nodeIid=" + nodeIid + '}';