Synchronize Flow and Group Remove events
[openflowplugin.git] / applications / forwardingrules-manager / src / main / java / org / opendaylight / openflowplugin / applications / frm / nodeconfigurator / JobEntry.java
1 /*
2  * Copyright (c) 2018 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 package org.opendaylight.openflowplugin.applications.frm.nodeconfigurator;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import com.google.common.util.concurrent.SettableFuture;
12 import java.util.concurrent.Callable;
13 import javax.annotation.Nullable;
14
15 /**
16  * JobEntry is the entity built per job submitted by the application and
17  * enqueued to the book-keeping data structure.
18  */
19 class JobEntry<T> {
20     private final SettableFuture<T> resultFuture = SettableFuture.create();
21     private @Nullable final Callable<ListenableFuture<T>> mainWorker;
22     private final String key;
23
24     JobEntry(String key, Callable<ListenableFuture<T>> mainWorker) {
25         this.key = key;
26         this.mainWorker = mainWorker;
27     }
28
29     String getKey() {
30         return key;
31     }
32
33     @Nullable Callable<ListenableFuture<T>> getMainWorker() {
34         return mainWorker;
35     }
36
37     ListenableFuture<T> getResultFuture() {
38         return resultFuture;
39     }
40
41     void setResult(@Nullable T result) {
42         resultFuture.set(result);
43     }
44
45     void setFailure(Throwable failure) {
46         resultFuture.setException(failure);
47     }
48 }