Refactor transaction support in preparation for migration to latest APIs
- Added a explicit transaction id type
- cli command now just returns the identifiers of in-progress transactions
- Removed redriveTransactions until a better alternative is provided
- Removed DatabaseUpdate and replaced its usage with MapUpdate
Change-Id: Ic4a14967072068834510cd8459fd2a6790e456ef
diff --git a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/Transaction.java b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/Transaction.java
new file mode 100644
index 0000000..ac5238a
--- /dev/null
+++ b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/Transaction.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.store.primitives.impl;
+
+import java.util.List;
+
+import org.onosproject.store.primitives.TransactionId;
+import org.onosproject.store.primitives.resources.impl.MapUpdate;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableList;
+
+/**
+ * An immutable transaction object.
+ */
+public class Transaction {
+
+ enum State {
+ /**
+ * Indicates a new transaction that is about to be prepared. All transactions
+ * start their life in this state.
+ */
+ PREPARING,
+
+ /**
+ * Indicates a transaction that is successfully prepared i.e. all participants voted to commit
+ */
+ PREPARED,
+
+ /**
+ * Indicates a transaction that is about to be committed.
+ */
+ COMMITTING,
+
+ /**
+ * Indicates a transaction that has successfully committed.
+ */
+ COMMITTED,
+
+ /**
+ * Indicates a transaction that is about to be rolled back.
+ */
+ ROLLINGBACK,
+
+ /**
+ * Indicates a transaction that has been rolled back and all locks are released.
+ */
+ ROLLEDBACK
+ }
+
+ private final TransactionId transactionId;
+ private final List<MapUpdate<String, byte[]>> updates;
+ private final State state;
+
+ public Transaction(TransactionId transactionId, List<MapUpdate<String, byte[]>> updates) {
+ this(transactionId, updates, State.PREPARING);
+ }
+
+ private Transaction(TransactionId transactionId,
+ List<MapUpdate<String, byte[]>> updates,
+ State state) {
+ this.transactionId = transactionId;
+ this.updates = ImmutableList.copyOf(updates);
+ this.state = state;
+ }
+
+ public TransactionId id() {
+ return transactionId;
+ }
+
+ public List<MapUpdate<String, byte[]>> updates() {
+ return updates;
+ }
+
+ public State state() {
+ return state;
+ }
+
+ public Transaction transition(State newState) {
+ return new Transaction(transactionId, updates, newState);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("transactionId", transactionId)
+ .add("updates", updates)
+ .add("state", state)
+ .toString();
+ }
+}
\ No newline at end of file