2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.core.spi.data;
10 import static java.util.Objects.requireNonNull;
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;
18 * Public utility class for instantiating snapshot-backed transactions.
21 public final class SnapshotBackedTransactions {
22 private SnapshotBackedTransactions() {
23 throw new UnsupportedOperationException("Utility class");
27 * Creates a new read-only transaction.
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
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);
40 * Creates a new read-only transaction.
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
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));
54 * Creates a new read-write transaction.
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
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);
68 * Creates a new write-only transaction.
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
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);