Move sal-netconf-connector to plugins/
[netconf.git] / plugins / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / listener / 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.netconf.sal.connect.netconf.listener;
9
10 import static com.google.common.base.Preconditions.checkState;
11
12 import com.google.common.util.concurrent.AbstractFuture;
13 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
14
15 final class UncancellableFuture<V> extends AbstractFuture<V> {
16     private volatile boolean uncancellable = false;
17
18     UncancellableFuture(final boolean uncancellable) {
19         this.uncancellable = uncancellable;
20     }
21
22     public boolean setUncancellable() {
23         if (isCancelled()) {
24             return false;
25         }
26
27         uncancellable = true;
28         return true;
29     }
30
31     public boolean isUncancellable() {
32         return uncancellable;
33     }
34
35     @Override
36     public boolean cancel(final boolean mayInterruptIfRunning) {
37         return !uncancellable && super.cancel(mayInterruptIfRunning);
38     }
39
40     @SuppressFBWarnings(value = "NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE",
41             justification = "Unrecognised NullableDecl")
42     @Override
43     public boolean set(final V value) {
44         checkState(uncancellable);
45         return super.set(value);
46     }
47
48     @Override
49     protected boolean setException(final Throwable throwable) {
50         checkState(uncancellable);
51         return super.setException(throwable);
52     }
53 }