BUG-8618: improve logging
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ShardDataTreeCohort.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.annotations.VisibleForTesting;
11 import com.google.common.base.MoreObjects;
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import com.google.common.primitives.UnsignedLong;
14 import com.google.common.util.concurrent.FutureCallback;
15 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
16 import org.opendaylight.yangtools.concepts.Identifiable;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
20
21 @VisibleForTesting
22 public abstract class ShardDataTreeCohort implements Identifiable<TransactionIdentifier> {
23     public enum State {
24         READY,
25         CAN_COMMIT_PENDING,
26         CAN_COMMIT_COMPLETE,
27         PRE_COMMIT_PENDING,
28         PRE_COMMIT_COMPLETE,
29         COMMIT_PENDING,
30
31         ABORTED,
32         COMMITTED,
33         FAILED,
34     }
35
36     ShardDataTreeCohort() {
37         // Prevent foreign instantiation
38     }
39
40     // FIXME: This leaks internal state generated in preCommit,
41     // should be result of canCommit
42     abstract DataTreeCandidateTip getCandidate();
43
44     abstract DataTreeModification getDataTreeModification();
45
46     // FIXME: Should return rebased DataTreeCandidateTip
47     @VisibleForTesting
48     public abstract void canCommit(FutureCallback<Void> callback);
49
50     @VisibleForTesting
51     public abstract void preCommit(FutureCallback<DataTreeCandidate> callback);
52
53     @VisibleForTesting
54     public abstract void abort(FutureCallback<Void> callback);
55
56     @VisibleForTesting
57     public abstract void commit(FutureCallback<UnsignedLong> callback);
58
59     public abstract boolean isFailed();
60
61     public abstract State getState();
62
63     @Override
64     public final String toString() {
65         return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString();
66     }
67
68     ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
69         return toStringHelper.add("id", getIdentifier()).add("state", getState());
70     }
71 }

©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.