*/
package org.opendaylight.mdsal.dom.spi.store;
-import static com.google.common.base.Preconditions.checkNotNull;
+import static java.util.Objects.requireNonNull;
import com.google.common.annotations.Beta;
import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import org.opendaylight.mdsal.common.api.ReadFailedException;
*/
@Beta
public final class SnapshotBackedReadTransaction<T> extends
- AbstractDOMStoreTransaction<T> implements DOMStoreReadTransaction {
+ AbstractDOMStoreTransaction<T> implements DOMStoreReadTransaction, SnapshotBackedTransaction {
private static final Logger LOG = LoggerFactory.getLogger(SnapshotBackedReadTransaction.class);
private volatile DataTreeSnapshot stableSnapshot;
*/
SnapshotBackedReadTransaction(final T identifier, final boolean debug, final DataTreeSnapshot snapshot) {
super(identifier, debug);
- this.stableSnapshot = Preconditions.checkNotNull(snapshot);
+ this.stableSnapshot = requireNonNull(snapshot);
LOG.debug("ReadOnly Tx: {} allocated with snapshot {}", identifier, snapshot);
}
@Override
public CheckedFuture<Optional<NormalizedNode<?,?>>, ReadFailedException> read(final YangInstanceIdentifier path) {
LOG.debug("Tx: {} Read: {}", getIdentifier(), path);
- checkNotNull(path, "Path must not be null.");
+ requireNonNull(path, "Path must not be null.");
final DataTreeSnapshot snapshot = stableSnapshot;
if (snapshot == null) {
@Override
public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) {
LOG.debug("Tx: {} Exists: {}", getIdentifier(), path);
- checkNotNull(path, "Path must not be null.");
+ requireNonNull(path, "Path must not be null.");
try {
return Futures.immediateCheckedFuture(read(path).checkedGet().isPresent());
return Futures.immediateFailedCheckedFuture(e);
}
}
+
+ @Override
+ public java.util.Optional<DataTreeSnapshot> getSnapshot() {
+ return java.util.Optional.ofNullable(stableSnapshot);
+ }
}
--- /dev/null
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.dom.spi.store;
+
+import com.google.common.annotations.Beta;
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
+
+/**
+ * Interface implemented by {@link DOMStoreTransaction}s which are backed by a {@link DataTreeSnapshot}.
+ *
+ * @author Robert Varga
+ */
+@Beta
+@NonNullByDefault
+public interface SnapshotBackedTransaction extends DOMStoreTransaction {
+ /**
+ * Returns the {@link DataTreeSnapshot} underlying this transaction. If this transaction is no longer open,
+ * {@link Optional#empty()} is returned.
+ *
+ * @return DataTreeSnapshot attached to this transaction if this transaction is still open.
+ */
+ Optional<DataTreeSnapshot> getSnapshot();
+}
import org.slf4j.LoggerFactory;
/**
- * Implementation of Write transaction which is backed by
- * {@link DataTreeSnapshot} and executed according to
- * {@link org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction.TransactionReadyPrototype}.
+ * Implementation of Write transaction which is backed by {@link DataTreeSnapshot} and executed according to
+ * {@link TransactionReadyPrototype}.
*
* @param <T> Identifier type
*/
@Beta
public class SnapshotBackedWriteTransaction<T> extends AbstractDOMStoreTransaction<T>
- implements DOMStoreWriteTransaction {
+ implements DOMStoreWriteTransaction, SnapshotBackedTransaction {
private static final Logger LOG = LoggerFactory.getLogger(SnapshotBackedWriteTransaction.class);
}
}
+ @Override
+ public Optional<DataTreeSnapshot> getSnapshot() {
+ return readyImpl == null ? Optional.empty() : Optional.ofNullable(mutableTree);
+ }
+
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
return toStringHelper.add("ready", readyImpl == null);