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