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> |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 22 | * A transaction context is a vehicle for grouping operations into a unit with the |
| 23 | * properties of atomicity, isolation, and durability. Transactions also provide the |
| 24 | * ability to maintain an application's invariants or integrity constraints, |
| 25 | * supporting the property of consistency. Together these properties are known as ACID. |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 26 | * <p> |
| 27 | * A transaction context provides a boundary within which transactions |
| 28 | * are run. It also is a place where all modifications made within a transaction |
| 29 | * are cached until the point when the transaction commits or aborts. It thus ensures |
| 30 | * isolation of work happening with in the transaction boundary. Within a transaction |
| 31 | * context isolation level is REPEATABLE_READS i.e. only data that is committed can be read. |
| 32 | * The only uncommitted data that can be read is the data modified by the current transaction. |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 33 | */ |
| 34 | public interface TransactionContext { |
| 35 | |
| 36 | /** |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 37 | * Returns the unique transactionId. |
| 38 | * |
| 39 | * @return transaction id |
| 40 | */ |
| 41 | long transactionId(); |
| 42 | |
| 43 | /** |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 44 | * Returns if this transaction context is open. |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 45 | * |
| 46 | * @return true if open, false otherwise |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 47 | */ |
| 48 | boolean isOpen(); |
| 49 | |
| 50 | /** |
| 51 | * Starts a new transaction. |
| 52 | */ |
| 53 | void begin(); |
| 54 | |
| 55 | /** |
| 56 | * Commits a transaction that was previously started thereby making its changes permanent |
| 57 | * and externally visible. |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 58 | * |
Sho SHIMIZU | d936b42 | 2015-11-02 16:38:18 -0800 | [diff] [blame] | 59 | * @return true if this transaction succeeded, otherwise false. |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 60 | */ |
Sho SHIMIZU | d936b42 | 2015-11-02 16:38:18 -0800 | [diff] [blame] | 61 | boolean commit(); |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 62 | |
| 63 | /** |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 64 | * Aborts any changes made in this transaction context and discarding all locally cached updates. |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 65 | */ |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 66 | void abort(); |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 67 | |
| 68 | /** |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 69 | * Returns a transactional map data structure with the specified name. |
| 70 | * |
Ray Milkey | 144eec5 | 2015-02-20 11:22:32 -0800 | [diff] [blame] | 71 | * @param <K> key type |
| 72 | * @param <V> value type |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 73 | * @param mapName name of the transactional map |
| 74 | * @param serializer serializer to use for encoding/decoding keys and values of the map |
| 75 | * @return Transactional Map |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 76 | */ |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 77 | <K, V> TransactionalMap<K, V> getTransactionalMap(String mapName, Serializer serializer); |
Ray Milkey | 144eec5 | 2015-02-20 11:22:32 -0800 | [diff] [blame] | 78 | } |