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