blob: 94942e208d9013e2dc4422b2e22293080496a5a3 [file] [log] [blame]
Madan Jampani64689552015-02-17 10:00:27 -08001/*
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
17package org.onosproject.store.service;
18
19/**
20 * Provides a context for transactional operations.
21 * <p>
Madan Jampani64689552015-02-17 10:00:27 -080022 * 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 Jampanibff6d8f2015-03-31 16:53:47 -070026 * <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 Jampani64689552015-02-17 10:00:27 -080033 */
34public interface TransactionContext {
35
36 /**
Madan Jampanibff6d8f2015-03-31 16:53:47 -070037 * Returns the unique transactionId.
38 *
39 * @return transaction id
40 */
41 long transactionId();
42
43 /**
Madan Jampani64689552015-02-17 10:00:27 -080044 * Returns if this transaction context is open.
Madan Jampanibff6d8f2015-03-31 16:53:47 -070045 *
46 * @return true if open, false otherwise
Madan Jampani64689552015-02-17 10:00:27 -080047 */
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 Jampanibff6d8f2015-03-31 16:53:47 -070058 *
59 * @throws TransactionException if transaction fails to commit
Madan Jampani64689552015-02-17 10:00:27 -080060 */
61 void commit();
62
63 /**
Madan Jampanibff6d8f2015-03-31 16:53:47 -070064 * Aborts any changes made in this transaction context and discarding all locally cached updates.
Madan Jampani64689552015-02-17 10:00:27 -080065 */
Madan Jampanibff6d8f2015-03-31 16:53:47 -070066 void abort();
Madan Jampani64689552015-02-17 10:00:27 -080067
68 /**
Madan Jampanibff6d8f2015-03-31 16:53:47 -070069 * Returns a transactional map data structure with the specified name.
70 *
Ray Milkey144eec52015-02-20 11:22:32 -080071 * @param <K> key type
72 * @param <V> value type
Madan Jampanibff6d8f2015-03-31 16:53:47 -070073 * @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 Jampani64689552015-02-17 10:00:27 -080076 */
Madan Jampanibff6d8f2015-03-31 16:53:47 -070077 <K, V> TransactionalMap<K, V> getTransactionalMap(String mapName, Serializer serializer);
Ray Milkey144eec52015-02-20 11:22:32 -080078}