Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.store.service; |
| 18 | |
| 19 | /** |
| 20 | * Provides a context for transactional operations. |
| 21 | * <p> |
| 22 | * A transaction context provides a boundary within which transactions |
| 23 | * are run. It also is a place where all modifications made within a transaction |
| 24 | * are cached until the point when the transaction commits or aborts. It thus ensures |
| 25 | * isolation of work happening with in the transaction boundary. |
| 26 | * <p> |
| 27 | * A transaction context is a vehicle for grouping operations into a unit with the |
| 28 | * properties of atomicity, isolation, and durability. Transactions also provide the |
| 29 | * ability to maintain an application's invariants or integrity constraints, |
| 30 | * supporting the property of consistency. Together these properties are known as ACID. |
| 31 | */ |
| 32 | public interface TransactionContext { |
| 33 | |
| 34 | /** |
| 35 | * Returns if this transaction context is open. |
| 36 | * @return true if open, false otherwise. |
| 37 | */ |
| 38 | boolean isOpen(); |
| 39 | |
| 40 | /** |
| 41 | * Starts a new transaction. |
| 42 | */ |
| 43 | void begin(); |
| 44 | |
| 45 | /** |
| 46 | * Commits a transaction that was previously started thereby making its changes permanent |
| 47 | * and externally visible. |
| 48 | * @throws TransactionException if transaction fails to commit. |
| 49 | */ |
| 50 | void commit(); |
| 51 | |
| 52 | /** |
| 53 | * Rolls back the current transaction, discarding all its changes. |
| 54 | */ |
| 55 | void rollback(); |
| 56 | |
| 57 | /** |
| 58 | * Creates a new transactional map. |
Ray Milkey | 144eec5 | 2015-02-20 11:22:32 -0800 | [diff] [blame] | 59 | * @param <K> key type |
| 60 | * @param <V> value type |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 61 | * @param mapName name of the transactional map. |
| 62 | * @param serializer serializer to use for encoding/decoding keys and vaulues. |
| 63 | * @return new Transactional Map. |
| 64 | */ |
| 65 | <K, V> TransactionalMap<K, V> createTransactionalMap(String mapName, Serializer serializer); |
Ray Milkey | 144eec5 | 2015-02-20 11:22:32 -0800 | [diff] [blame] | 66 | } |