401c15b542e61ad7befa9bee17c0bcb0bb2febb2
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ChainedCommitCohort.java
1 /*
2  * Copyright (c) 2015 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.datastore;
9
10 import com.google.common.base.Preconditions;
11 import com.google.common.primitives.UnsignedLong;
12 import com.google.common.util.concurrent.FutureCallback;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 final class ChainedCommitCohort extends ShardDataTreeCohort {
22     private static final Logger LOG = LoggerFactory.getLogger(ChainedCommitCohort.class);
23     private final ReadWriteShardDataTreeTransaction transaction;
24     private final ShardDataTreeTransactionChain chain;
25     private final ShardDataTreeCohort delegate;
26
27     ChainedCommitCohort(final ShardDataTreeTransactionChain chain, final ReadWriteShardDataTreeTransaction transaction, final ShardDataTreeCohort delegate) {
28         this.transaction = Preconditions.checkNotNull(transaction);
29         this.delegate = Preconditions.checkNotNull(delegate);
30         this.chain = Preconditions.checkNotNull(chain);
31     }
32
33     @Override
34     public void commit(final FutureCallback<UnsignedLong> callback) {
35         delegate.commit(new FutureCallback<UnsignedLong>() {
36             @Override
37             public void onSuccess(final UnsignedLong result) {
38                 chain.clearTransaction(transaction);
39                 LOG.debug("Committed transaction {}", transaction);
40                 callback.onSuccess(result);
41             }
42
43             @Override
44             public void onFailure(final Throwable t) {
45                 LOG.error("Transaction {} commit failed, cannot recover", transaction, t);
46                 callback.onFailure(t);
47             }
48         });
49     }
50
51     @Override
52     public TransactionIdentifier getIdentifier() {
53         return delegate.getIdentifier();
54     }
55
56     @Override
57     public void canCommit(final FutureCallback<Void> callback) {
58         delegate.canCommit(callback);
59     }
60
61     @Override
62     public void preCommit(final FutureCallback<DataTreeCandidate> callback) {
63         delegate.preCommit(callback);
64     }
65
66     @Override
67     public ListenableFuture<Void> abort() {
68         return delegate.abort();
69     }
70
71     @Override
72     DataTreeCandidateTip getCandidate() {
73         return delegate.getCandidate();
74     }
75
76     @Override
77     DataTreeModification getDataTreeModification() {
78         return delegate.getDataTreeModification();
79     }
80
81     @Override
82     public boolean isFailed() {
83         return delegate.isFailed();
84     }
85
86     @Override
87     public State getState() {
88         return delegate.getState();
89     }
90 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.