+
+ private void ensureReady(final Collection<TransactionModification> modifications) {
+ // We may have a combination of READY + SIMPLE/THREE_PHASE , in which case we want to ready the transaction
+ // only once.
+ if (state instanceof Ready) {
+ LOG.debug("{}: {} is already in state {}", persistenceId(), getIdentifier(), state);
+ return;
+ }
+
+ applyModifications(modifications);
+ state = new Ready(checkOpen().ready());
+ LOG.debug("{}: transitioned {} to ready", persistenceId(), getIdentifier());
+ }
+
+ private void throwIfFailed() throws RequestException {
+ if (state instanceof Failed) {
+ LOG.debug("{}: {} has failed, rejecting request", persistenceId(), getIdentifier());
+ throw ((Failed) state).cause;
+ }
+ }
+
+ private ReadWriteShardDataTreeTransaction checkOpen() {
+ Preconditions.checkState(state instanceof Open, "%s expect to be open, is in state %s", getIdentifier(),
+ state);
+ return ((Open) state).openTransaction;
+ }
+
+ private Ready checkReady() {
+ Preconditions.checkState(state instanceof Ready, "%s expect to be ready, is in state %s", getIdentifier(),
+ state);
+ return (Ready) state;
+ }
+
+ private DataTreeModification checkSealed() {
+ Preconditions.checkState(state instanceof Sealed, "%s expect to be sealed, is in state %s", getIdentifier(),
+ state);
+ return ((Sealed) state).sealedModification;
+ }