blob: 234dfad1a33343f2f71fd4489817ebef91c1b2e2 [file] [log] [blame]
Madan Jampani64689552015-02-17 10:00:27 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Madan Jampani64689552015-02-17 10:00:27 -08003 *
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 Jampani3780d4b2016-04-04 18:18:24 -070019import java.util.concurrent.CompletableFuture;
20
Madan Jampanicadd70b2016-02-08 13:45:43 -080021import org.onosproject.store.primitives.TransactionId;
22
Madan Jampani64689552015-02-17 10:00:27 -080023/**
24 * Provides a context for transactional operations.
25 * <p>
Madan Jampani64689552015-02-17 10:00:27 -080026 * A transaction context is a vehicle for grouping operations into a unit with the
27 * properties of atomicity, isolation, and durability. Transactions also provide the
28 * ability to maintain an application's invariants or integrity constraints,
29 * supporting the property of consistency. Together these properties are known as ACID.
Madan Jampanibff6d8f2015-03-31 16:53:47 -070030 * <p>
31 * A transaction context provides a boundary within which transactions
32 * are run. It also is a place where all modifications made within a transaction
33 * are cached until the point when the transaction commits or aborts. It thus ensures
34 * isolation of work happening with in the transaction boundary. Within a transaction
35 * context isolation level is REPEATABLE_READS i.e. only data that is committed can be read.
36 * The only uncommitted data that can be read is the data modified by the current transaction.
Madan Jampani64689552015-02-17 10:00:27 -080037 */
Madan Jampanicadd70b2016-02-08 13:45:43 -080038public interface TransactionContext extends DistributedPrimitive {
39
40 @Override
Madan Jampani39fff102016-02-14 13:17:28 -080041 default DistributedPrimitive.Type primitiveType() {
Madan Jampanicadd70b2016-02-08 13:45:43 -080042 return DistributedPrimitive.Type.TRANSACTION_CONTEXT;
43 }
Madan Jampani64689552015-02-17 10:00:27 -080044
45 /**
Madan Jampanicadd70b2016-02-08 13:45:43 -080046 * Returns the transaction identifier.
Madan Jampanibff6d8f2015-03-31 16:53:47 -070047 *
48 * @return transaction id
49 */
Madan Jampanicadd70b2016-02-08 13:45:43 -080050 TransactionId transactionId();
Madan Jampanibff6d8f2015-03-31 16:53:47 -070051
52 /**
Madan Jampani64689552015-02-17 10:00:27 -080053 * Returns if this transaction context is open.
Madan Jampanibff6d8f2015-03-31 16:53:47 -070054 *
55 * @return true if open, false otherwise
Madan Jampani64689552015-02-17 10:00:27 -080056 */
57 boolean isOpen();
58
59 /**
60 * Starts a new transaction.
61 */
62 void begin();
63
64 /**
65 * Commits a transaction that was previously started thereby making its changes permanent
66 * and externally visible.
Madan Jampanibff6d8f2015-03-31 16:53:47 -070067 *
Madan Jampani3780d4b2016-04-04 18:18:24 -070068 * @return A future that will be completed when the operation completes
Madan Jampani64689552015-02-17 10:00:27 -080069 */
Madan Jampani3780d4b2016-04-04 18:18:24 -070070 CompletableFuture<CommitStatus> commit();
Madan Jampani64689552015-02-17 10:00:27 -080071
72 /**
Madan Jampanibff6d8f2015-03-31 16:53:47 -070073 * Aborts any changes made in this transaction context and discarding all locally cached updates.
Madan Jampani64689552015-02-17 10:00:27 -080074 */
Madan Jampanibff6d8f2015-03-31 16:53:47 -070075 void abort();
Madan Jampani64689552015-02-17 10:00:27 -080076
77 /**
Madan Jampanibff6d8f2015-03-31 16:53:47 -070078 * Returns a transactional map data structure with the specified name.
79 *
Ray Milkey144eec52015-02-20 11:22:32 -080080 * @param <K> key type
81 * @param <V> value type
Madan Jampanibff6d8f2015-03-31 16:53:47 -070082 * @param mapName name of the transactional map
83 * @param serializer serializer to use for encoding/decoding keys and values of the map
84 * @return Transactional Map
Madan Jampani64689552015-02-17 10:00:27 -080085 */
Madan Jampanibff6d8f2015-03-31 16:53:47 -070086 <K, V> TransactionalMap<K, V> getTransactionalMap(String mapName, Serializer serializer);
Ray Milkey144eec52015-02-20 11:22:32 -080087}