MD-SAL transaction chaining API 54/5054/4
authorRobert Varga <rovarga@cisco.com>
Fri, 31 Jan 2014 09:31:46 +0000 (10:31 +0100)
committerRobert Varga <rovarga@cisco.com>
Mon, 3 Feb 2014 12:14:00 +0000 (13:14 +0100)
This API complements the normal MD-SAL transaction API. Applications can
use this API to maintain inter-transaction ordering and data
consistency.

Change-Id: Ia603f7dacf081fb1528d149f4635c2f22101a7a0
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChain.java [new file with mode: 0644]
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChainClosedException.java [new file with mode: 0644]
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChainFactory.java [new file with mode: 0644]
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChainListener.java [new file with mode: 0644]

diff --git a/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChain.java b/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChain.java
new file mode 100644 (file)
index 0000000..ff3aa2e
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.common.api.data;
+
+/**
+ * A chain of transactions. Transactions in a chain need to be committed in sequence and each
+ * transaction should see the effects of previous transactions as if they happened. A chain
+ * makes no guarantees of atomicity, in fact transactions are committed as soon as possible.
+ */
+public interface TransactionChain<P/* extends Path<P> */, D> extends AutoCloseable {
+    /**
+     * Create a new transaction which will continue the chain. The previous transaction
+     * has to be either COMMITTED or CANCELLED.
+     *
+     * @return New transaction in the chain.
+     * @throws IllegalStateException if the previous transaction was not COMMITTED or CANCELLED.
+     * @throws TransactionChainClosedException if the chain has been closed.
+     */
+    DataModification<P, D> newTransaction();
+
+    @Override
+    void close();
+}
+
diff --git a/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChainClosedException.java b/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChainClosedException.java
new file mode 100644 (file)
index 0000000..5e1b35d
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.common.api.data;
+
+/**
+ * Exception thrown when an attempt is made to open a new transaction in a closed
+ * chain.
+ */
+public final class TransactionChainClosedException extends IllegalStateException {
+    private static final long serialVersionUID = 1L;
+
+    public TransactionChainClosedException(final String message) {
+        super(message);
+    }
+
+    public TransactionChainClosedException(final String message, final Throwable cause) {
+        super(message, cause);
+    }
+}
diff --git a/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChainFactory.java b/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChainFactory.java
new file mode 100644 (file)
index 0000000..4e7e12e
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.common.api.data;
+
+/**
+ * Interface for creating transaction chains.
+ */
+public interface TransactionChainFactory<P/* extends Path<P> */, D> {
+    /**
+     * Create a new transaction chain. The chain will be initialized to read
+     * from its backing datastore, with no outstanding transaction. Listener
+     * will be registered to handle chain-level events.
+     *
+     * @param listener Transaction chain event listener
+     * @return A new transaction chain.
+     */
+    TransactionChain<P, D> createTransactionChain(TransactionChainListener listener);
+}
+
diff --git a/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChainListener.java b/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChainListener.java
new file mode 100644 (file)
index 0000000..4dac6f5
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.common.api.data;
+
+import java.util.EventListener;
+
+/**
+ * Listener for transaction chain events.
+ */
+public interface TransactionChainListener extends EventListener {
+    /**
+     * Invoked if when a transaction in the chain fails. All other transactions are automatically cancelled by the time
+     * this notification is invoked. Implementations should invoke chain.close() to close the chain.
+     *
+     * @param chain Transaction chain which failed
+     * @param transaction Transaction which caused the chain to fail
+     * @param cause The cause of transaction failure
+     */
+    void onTransactionChainFailed(TransactionChain<?, ?> chain, DataModification<?, ?> transaction, Throwable cause);
+
+    /**
+     * Invoked when a transaction chain is completed. A transaction chain is considered completed when it has been
+     * closed and all its instructions have completed successfully.
+     *
+     * @param chain Transaction chain which completed
+     */
+    void onTransactionChainSuccessful(TransactionChain<?, ?> chain);
+}
+