Improve LocalProxyTransaction.doExists()
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / AbstractTransactionCommitCohort.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.base.MoreObjects;
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
16 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
17 import org.opendaylight.yangtools.yang.common.Empty;
18
19 /**
20  * Base class for internal {@link DOMStoreThreePhaseCommitCohort} implementation. It contains utility constants for
21  * wide reuse.
22  *
23  * @author Robert Varga
24  */
25 abstract class AbstractTransactionCommitCohort implements DOMStoreThreePhaseCommitCohort {
26     static final ListenableFuture<Boolean> TRUE_FUTURE = Futures.immediateFuture(Boolean.TRUE);
27     static final ListenableFuture<Empty> EMPTY_FUTURE = Futures.immediateFuture(Empty.value());
28
29     private final AbstractClientHistory parent;
30     private final TransactionIdentifier txId;
31
32     AbstractTransactionCommitCohort(final AbstractClientHistory parent, final TransactionIdentifier txId) {
33         this.parent = requireNonNull(parent);
34         this.txId = requireNonNull(txId);
35     }
36
37     final void complete() {
38         parent.onTransactionComplete(txId);
39     }
40
41     @Override
42     public final String toString() {
43         return MoreObjects.toStringHelper(this).add("txId", txId).toString();
44     }
45 }