Imported vpnservice as a subtree
[netvirt.git] / vpnservice / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / vpnservice / datastoreutils / JobEntry.java
1 /*
2  * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.vpnservice.datastoreutils;
10
11 import com.google.common.util.concurrent.ListenableFuture;
12
13 import java.util.List;
14 import java.util.concurrent.Callable;
15 import java.util.concurrent.atomic.AtomicInteger;
16
17 /**
18  * JobEntry is the entity built per job submitted by the application and
19  * enqueued to the book-keeping data structure.
20  */
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;
27
28     public JobEntry(String key,
29                     Callable<List<ListenableFuture<Void>>> mainWorker,
30                     RollbackCallable rollbackWorker,
31                     int maxRetries) {
32         this.key = key;
33         this.mainWorker = mainWorker;
34         this.rollbackWorker = rollbackWorker;
35         retryCount = new AtomicInteger(maxRetries);
36     }
37
38     /**
39      *
40      * @return
41      *
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.
46      */
47     public String getKey() {
48         return key;
49     }
50
51     public Callable<List<ListenableFuture<Void>>> getMainWorker() {
52         return mainWorker;
53     }
54
55     public void setMainWorker(Callable<List<ListenableFuture<Void>>> mainWorker) {
56         this.mainWorker = mainWorker;
57     }
58
59     public RollbackCallable getRollbackWorker() {
60         return rollbackWorker;
61     }
62
63     public int decrementRetryCountAndGet() {
64         return retryCount.decrementAndGet();
65     }
66
67     public List<ListenableFuture<Void>> getFutures() {
68         return futures;
69     }
70
71     public void setFutures(List<ListenableFuture<Void>> futures) {
72         this.futures = futures;
73     }
74
75     @Override
76     public String toString() {
77         return "JobEntry{" +
78                 "key='" + key + '\'' +
79                 ", mainWorker=" + mainWorker +
80                 ", rollbackWorker=" + rollbackWorker +
81                 ", retryCount=" + retryCount +
82                 ", futures=" + futures +
83                 '}';
84     }
85 }