blob: 0ac490b5ee7951f13a394390ec86c00922ce396d [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
Madan Jampanicadd70b2016-02-08 13:45:43 -080019import org.onosproject.store.primitives.TransactionId;
20
Madan Jampani64689552015-02-17 10:00:27 -080021/**
22 * Provides a context for transactional operations.
23 * <p>
Madan Jampani64689552015-02-17 10:00:27 -080024 * 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 Jampanibff6d8f2015-03-31 16:53:47 -070028 * <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 Jampani64689552015-02-17 10:00:27 -080035 */
Madan Jampanicadd70b2016-02-08 13:45:43 -080036public interface TransactionContext extends DistributedPrimitive {
37
38 @Override
39 default DistributedPrimitive.Type type() {
40 return DistributedPrimitive.Type.TRANSACTION_CONTEXT;
41 }
Madan Jampani64689552015-02-17 10:00:27 -080042
43 /**
Madan Jampanicadd70b2016-02-08 13:45:43 -080044 * Returns the transaction identifier.
Madan Jampanibff6d8f2015-03-31 16:53:47 -070045 *
46 * @return transaction id
47 */
Madan Jampanicadd70b2016-02-08 13:45:43 -080048 TransactionId transactionId();
Madan Jampanibff6d8f2015-03-31 16:53:47 -070049
50 /**
Madan Jampani64689552015-02-17 10:00:27 -080051 * Returns if this transaction context is open.
Madan Jampanibff6d8f2015-03-31 16:53:47 -070052 *
53 * @return true if open, false otherwise
Madan Jampani64689552015-02-17 10:00:27 -080054 */
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 Jampanibff6d8f2015-03-31 16:53:47 -070065 *
Sho SHIMIZUd936b422015-11-02 16:38:18 -080066 * @return true if this transaction succeeded, otherwise false.
Madan Jampani64689552015-02-17 10:00:27 -080067 */
Sho SHIMIZUd936b422015-11-02 16:38:18 -080068 boolean commit();
Madan Jampani64689552015-02-17 10:00:27 -080069
70 /**
Madan Jampanibff6d8f2015-03-31 16:53:47 -070071 * Aborts any changes made in this transaction context and discarding all locally cached updates.
Madan Jampani64689552015-02-17 10:00:27 -080072 */
Madan Jampanibff6d8f2015-03-31 16:53:47 -070073 void abort();
Madan Jampani64689552015-02-17 10:00:27 -080074
75 /**
Madan Jampanibff6d8f2015-03-31 16:53:47 -070076 * Returns a transactional map data structure with the specified name.
77 *
Ray Milkey144eec52015-02-20 11:22:32 -080078 * @param <K> key type
79 * @param <V> value type
Madan Jampanibff6d8f2015-03-31 16:53:47 -070080 * @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 Jampani64689552015-02-17 10:00:27 -080083 */
Madan Jampanibff6d8f2015-03-31 16:53:47 -070084 <K, V> TransactionalMap<K, V> getTransactionalMap(String mapName, Serializer serializer);
Ray Milkey144eec52015-02-20 11:22:32 -080085}