2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.vpnservice.datastoreutils;
11 import com.google.common.util.concurrent.ListenableFuture;
13 import java.util.List;
14 import java.util.concurrent.Callable;
15 import java.util.concurrent.atomic.AtomicInteger;
18 * JobEntry is the entity built per job submitted by the application and
19 * enqueued to the book-keeping data structure.
21 public class JobEntry {
22 final private String key;
23 private Callable<List<ListenableFuture<Void>>> mainWorker;
24 final private RollbackCallable rollbackWorker;
25 private AtomicInteger retryCount;
26 private List<ListenableFuture<Void>> futures;
28 public JobEntry(String key,
29 Callable<List<ListenableFuture<Void>>> mainWorker,
30 RollbackCallable rollbackWorker,
33 this.mainWorker = mainWorker;
34 this.rollbackWorker = rollbackWorker;
35 retryCount = new AtomicInteger(maxRetries);
42 * The key provided by the application that segregates the
43 * callables that can be run parallely.
44 * NOTE: Currently, this is a string. Can be converted to Object where
45 * Object implementation should provide the hashcode and equals methods.
47 public String getKey() {
51 public Callable<List<ListenableFuture<Void>>> getMainWorker() {
55 public void setMainWorker(Callable<List<ListenableFuture<Void>>> mainWorker) {
56 this.mainWorker = mainWorker;
59 public RollbackCallable getRollbackWorker() {
60 return rollbackWorker;
63 public int decrementRetryCountAndGet() {
64 return retryCount.decrementAndGet();
67 public List<ListenableFuture<Void>> getFutures() {
71 public void setFutures(List<ListenableFuture<Void>> futures) {
72 this.futures = futures;
76 public String toString() {
78 "key='" + key + '\'' +
79 ", mainWorker=" + mainWorker +
80 ", rollbackWorker=" + rollbackWorker +
81 ", retryCount=" + retryCount +
82 ", futures=" + futures +