From c4b5fc6270b981196be687d04f42a94cb10ef69f Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 31 Jan 2014 10:31:46 +0100 Subject: [PATCH] MD-SAL transaction chaining API 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 --- .../sal/common/api/data/TransactionChain.java | 29 ++++++++++++++++ .../data/TransactionChainClosedException.java | 24 +++++++++++++ .../api/data/TransactionChainFactory.java | 24 +++++++++++++ .../api/data/TransactionChainListener.java | 34 +++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChain.java create mode 100644 opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChainClosedException.java create mode 100644 opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChainFactory.java create mode 100644 opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChainListener.java 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 index 0000000000..ff3aa2e325 --- /dev/null +++ b/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChain.java @@ -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

*/, 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 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 index 0000000000..5e1b35dbe5 --- /dev/null +++ b/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChainClosedException.java @@ -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 index 0000000000..4e7e12e0a1 --- /dev/null +++ b/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChainFactory.java @@ -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

*/, 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 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 index 0000000000..4dac6f557e --- /dev/null +++ b/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChainListener.java @@ -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); +} + -- 2.36.6