2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.netconf.topology.singleton.impl.tx;
11 import akka.actor.ActorRef;
12 import akka.actor.ActorSystem;
13 import akka.util.Timeout;
14 import com.google.common.base.Optional;
15 import com.google.common.util.concurrent.CheckedFuture;
16 import com.google.common.util.concurrent.FluentFuture;
17 import com.google.common.util.concurrent.MoreExecutors;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
20 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
21 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
22 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
23 import org.opendaylight.mdsal.common.api.CommitInfo;
24 import org.opendaylight.mdsal.common.api.MappingCheckedFuture;
25 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
26 import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
28 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
31 * ProxyReadWriteTransaction uses provided {@link ActorRef} to delegate method calls to master
32 * {@link org.opendaylight.netconf.topology.singleton.impl.actors.ReadWriteTransactionActor}.
34 public class ProxyReadWriteTransaction implements DOMDataReadWriteTransaction {
36 private final ProxyReadAdapter delegateRead;
37 private final ProxyWriteAdapter delegateWrite;
40 * Constructor for {@code ProxyReadWriteTransaction}.
42 * @param masterTxActor
43 * {@link org.opendaylight.netconf.topology.singleton.impl.actors.ReadWriteTransactionActor} ref
45 * @param actorSystem system
46 * @param askTimeout timeout
48 public ProxyReadWriteTransaction(final ActorRef masterTxActor, final RemoteDeviceId id,
49 final ActorSystem actorSystem, final Timeout askTimeout) {
50 delegateRead = new ProxyReadAdapter(masterTxActor, id, actorSystem, askTimeout);
51 delegateWrite = new ProxyWriteAdapter(masterTxActor, id, actorSystem, askTimeout);
55 public boolean cancel() {
56 return delegateWrite.cancel();
60 public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store,
61 final YangInstanceIdentifier path) {
62 return delegateRead.read(store, path);
66 public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
67 final YangInstanceIdentifier path) {
68 return delegateRead.exists(store, path);
72 public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
73 delegateWrite.delete(store, path);
77 public CheckedFuture<Void, TransactionCommitFailedException> submit() {
78 return MappingCheckedFuture.create(commit().transform(ignored -> null, MoreExecutors.directExecutor()),
79 new ExceptionMapper<TransactionCommitFailedException>("commit", TransactionCommitFailedException.class) {
81 protected TransactionCommitFailedException newWithCause(String message, Throwable cause) {
82 return new TransactionCommitFailedException(message, cause);
88 public @NonNull FluentFuture<? extends @NonNull CommitInfo> commit() {
89 return delegateWrite.commit(getIdentifier());
93 public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
94 final NormalizedNode<?, ?> data) {
95 delegateWrite.put(store, path, data, getIdentifier());
99 public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
100 final NormalizedNode<?, ?> data) {
101 delegateWrite.merge(store, path, data, getIdentifier());
105 public Object getIdentifier() {