Improve LocalProxyTransaction.doExists()
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / EmptyTransactionCommitCohort.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 com.google.common.util.concurrent.ListenableFuture;
11 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
12 import org.opendaylight.mdsal.common.api.CommitInfo;
13 import org.opendaylight.yangtools.yang.common.Empty;
14
15 /**
16  * An {@link AbstractTransactionCommitCohort} for use with empty transactions. This relies on the fact that no backends
17  * have been touched, hence all state book-keeping needs to happen only locally and shares fate with the coordinator.
18  *
19  * <p>
20  * Therefore all methods can finish immediately without any effects.
21  *
22  * @author Robert Varga
23  */
24 final class EmptyTransactionCommitCohort extends AbstractTransactionCommitCohort {
25     EmptyTransactionCommitCohort(final AbstractClientHistory parent, final TransactionIdentifier txId) {
26         super(parent, txId);
27     }
28
29     @Override
30     public ListenableFuture<Boolean> canCommit() {
31         return TRUE_FUTURE;
32     }
33
34     @Override
35     public ListenableFuture<Empty> preCommit() {
36         return EMPTY_FUTURE;
37     }
38
39     @Override
40     public ListenableFuture<Empty> abort() {
41         complete();
42         return EMPTY_FUTURE;
43     }
44
45     @Override
46     public ListenableFuture<CommitInfo> commit() {
47         complete();
48         return CommitInfo.emptyFluentFuture();
49     }
50 }