+ private enum CommitStage {
+ READY,
+ CAN_COMMIT_PENDING,
+ CAN_COMMIT_COMPLETE,
+ PRE_COMMIT_PENDING,
+ PRE_COMMIT_COMPLETE,
+ COMMIT_PENDING,
+ }
+
+ private abstract static class State {
+ @Override
+ public abstract String toString();
+ }
+
+ private static final class Failed extends State {
+ final RequestException cause;
+
+ Failed(final RequestException cause) {
+ this.cause = Preconditions.checkNotNull(cause);
+ }
+
+ @Override
+ public String toString() {
+ return "FAILED (" + cause.getMessage() + ")";
+ }
+ }
+
+ private static final class Open extends State {
+ final ReadWriteShardDataTreeTransaction openTransaction;
+
+ Open(final ReadWriteShardDataTreeTransaction openTransaction) {
+ this.openTransaction = Preconditions.checkNotNull(openTransaction);
+ }
+
+ @Override
+ public String toString() {
+ return "OPEN";
+ }
+ }
+
+ private static final class Ready extends State {
+ final ShardDataTreeCohort readyCohort;
+ CommitStage stage;
+
+ Ready(final ShardDataTreeCohort readyCohort) {
+ this.readyCohort = Preconditions.checkNotNull(readyCohort);
+ this.stage = CommitStage.READY;
+ }
+
+ @Override
+ public String toString() {
+ return "READY (" + stage + ")";
+ }
+ }
+
+ private static final class Sealed extends State {
+ final DataTreeModification sealedModification;
+
+ Sealed(final DataTreeModification sealedModification) {
+ this.sealedModification = Preconditions.checkNotNull(sealedModification);
+ }
+
+ @Override
+ public String toString() {
+ return "SEALED";
+ }
+ }
+
+ /**
+ * Retired state, needed to catch and suppress callbacks after we have removed associated state.
+ */
+ private static final class Retired extends State {
+ private final String prevStateString;
+
+ Retired(final State prevState) {
+ prevStateString = prevState.toString();
+ }
+
+ @Override
+ public String toString() {
+ return "RETIRED (in " + prevStateString + ")";
+ }
+ }
+