Allow SnapshotBackedReadTransaction customization
[controller.git] / opendaylight / md-sal / sal-dom-spi / src / main / java / org / opendaylight / controller / sal / core / spi / data / SnapshotBackedTransactions.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.core.spi.data;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedReadTransaction.TransactionClosePrototype;
14 import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
16
17 /**
18  * Public utility class for instantiating snapshot-backed transactions.
19  */
20 @Beta
21 public final class SnapshotBackedTransactions {
22     private SnapshotBackedTransactions() {
23         throw new UnsupportedOperationException("Utility class");
24     }
25
26     /**
27      * Creates a new read-only transaction.
28      *
29      * @param identifier Transaction Identifier
30      * @param debug Enable transaction debugging
31      * @param snapshot Snapshot which will be modified.
32      * @return A new read-only transaction
33      */
34     public static <T> SnapshotBackedReadTransaction<T> newReadTransaction(final T identifier, final boolean debug,
35             final DataTreeSnapshot snapshot) {
36         return new SnapshotBackedReadTransaction<>(identifier, debug, snapshot, null);
37     }
38
39     /**
40      * Creates a new read-only transaction.
41      *
42      * @param identifier Transaction Identifier
43      * @param debug Enable transaction debugging
44      * @param snapshot Snapshot which will be modified.
45      * @param closeImpl Implementation of close method
46      * @return A new read-only transaction
47      */
48     public static <T> SnapshotBackedReadTransaction<T> newReadTransaction(final T identifier,
49             final boolean debug, final DataTreeSnapshot snapshot, final TransactionClosePrototype<T> closeImpl) {
50         return new SnapshotBackedReadTransaction<>(identifier, debug, snapshot, requireNonNull(closeImpl));
51     }
52
53     /**
54      * Creates a new read-write transaction.
55      *
56      * @param identifier transaction Identifier
57      * @param debug Enable transaction debugging
58      * @param snapshot Snapshot which will be modified.
59      * @param readyImpl Implementation of ready method.
60      * @return A new read-write transaction
61      */
62     public static <T> SnapshotBackedReadWriteTransaction<T> newReadWriteTransaction(final T identifier,
63             final boolean debug, final DataTreeSnapshot snapshot, final TransactionReadyPrototype<T> readyImpl) {
64         return new SnapshotBackedReadWriteTransaction<>(identifier, debug, snapshot, readyImpl);
65     }
66
67     /**
68      * Creates a new write-only transaction.
69      *
70      * @param identifier transaction Identifier
71      * @param debug Enable transaction debugging
72      * @param snapshot Snapshot which will be modified.
73      * @param readyImpl Implementation of ready method.
74      * @return A new write transaction
75      */
76     public static <T> SnapshotBackedWriteTransaction<T> newWriteTransaction(final T identifier, final boolean debug,
77             final DataTreeSnapshot snapshot, final TransactionReadyPrototype<T> readyImpl) {
78         return new SnapshotBackedWriteTransaction<>(identifier, debug, snapshot, readyImpl);
79     }
80 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.