/* * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.genius.datastoreutils; import com.google.common.util.concurrent.ListenableFuture; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicInteger; /** * JobEntry is the entity built per job submitted by the application and * enqueued to the book-keeping data structure. */ public class JobEntry { private final String key; private Callable>> mainWorker; private final RollbackCallable rollbackWorker; private final AtomicInteger retryCount; private List> futures; public JobEntry(String key, Callable>> mainWorker, RollbackCallable rollbackWorker, int maxRetries) { this.key = key; this.mainWorker = mainWorker; this.rollbackWorker = rollbackWorker; retryCount = new AtomicInteger(maxRetries); } /** * Get the key provided by the application that segregates the * callables that can be run parallely. * NOTE: Currently, this is a string. Can be converted to Object where * Object implementation should provide the hashcode and equals methods. */ public String getKey() { return key; } public Callable>> getMainWorker() { return mainWorker; } public void setMainWorker(Callable>> mainWorker) { this.mainWorker = mainWorker; } public RollbackCallable getRollbackWorker() { return rollbackWorker; } public int getRetryCount() { return retryCount.get(); } public int decrementRetryCountAndGet() { return retryCount.decrementAndGet(); } public List> getFutures() { return futures; } public void setFutures(List> futures) { this.futures = futures; } @Override public String toString() { return "JobEntry{" + "key='" + key + '\'' + ", mainWorker=" + mainWorker + ", rollbackWorker=" + rollbackWorker + ", retryCount=" + retryCount + ", futures=" + futures + '}'; } }