9b21b98682bf71a7e807985dba4f0f5c7e586832
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / DirectTransactionCommitCohort.java
1 /*
2  * Copyright (c) 2016 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.cluster.databroker.actors.dds;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.util.concurrent.ListenableFuture;
13 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
14
15 /**
16  * An {@link AbstractTransactionCommitCohort} implementation for transactions which contain a single proxy. Since there
17  * is only one proxy,
18  *
19  * @author Robert Varga
20  */
21 final class DirectTransactionCommitCohort extends AbstractTransactionCommitCohort {
22     private final AbstractProxyTransaction proxy;
23
24     DirectTransactionCommitCohort(final AbstractClientHistory parent, final TransactionIdentifier txId,
25         final AbstractProxyTransaction proxy) {
26         super(parent, txId);
27         this.proxy = requireNonNull(proxy);
28     }
29
30     @Override
31     public ListenableFuture<Boolean> canCommit() {
32         return proxy.directCommit();
33     }
34
35     @Override
36     public ListenableFuture<Void> preCommit() {
37         return VOID_FUTURE;
38     }
39
40     @Override
41     public ListenableFuture<Void> abort() {
42         complete();
43         return VOID_FUTURE;
44     }
45
46     @Override
47     public ListenableFuture<Void> commit() {
48         complete();
49         return VOID_FUTURE;
50     }
51 }