Bug 1073: Implemented Transaction chain on InMemoryDOMDataStore level.
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / main / java / org / opendaylight / controller / sal / connect / netconf / UncancellableFuture.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.connect.netconf;
9
10 import javax.annotation.Nullable;
11 import javax.annotation.concurrent.GuardedBy;
12
13 import com.google.common.base.Preconditions;
14 import com.google.common.util.concurrent.AbstractFuture;
15
16 final class UncancellableFuture<V> extends AbstractFuture<V> {
17     @GuardedBy("this")
18     private boolean uncancellable = false;
19
20     public UncancellableFuture(boolean uncancellable) {
21         this.uncancellable = uncancellable;
22     }
23
24     public synchronized boolean setUncancellable() {
25         if (isCancelled()) {
26             return false;
27         }
28
29         uncancellable = true;
30         return true;
31     }
32
33     public synchronized boolean isUncancellable() {
34         return uncancellable;
35     }
36
37     @Override
38     public synchronized boolean cancel(boolean mayInterruptIfRunning) {
39         if (uncancellable) {
40             return false;
41         }
42
43         return super.cancel(mayInterruptIfRunning);
44     }
45
46     @Override
47     public synchronized boolean set(@Nullable V value) {
48         Preconditions.checkState(uncancellable == true);
49         return super.set(value);
50     }
51
52     @Override
53     protected boolean setException(Throwable throwable) {
54         Preconditions.checkState(uncancellable == true);
55         return super.setException(throwable);
56     }
57 }