X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fnetconf-topology-singleton%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Ftopology%2Fsingleton%2Fimpl%2Ftx%2FProxyReadTransaction.java;h=ed972c1d5d3689cdbeed2203102a9448424be0d9;hb=e60546d08fbc89e4780406c4123ba25c3e7698ef;hp=0756f33ddfbc445c64ed72c24fb4a3ccb21ac068;hpb=9c18390ba25a0635f994b5bffd899306fd7c1e6c;p=netconf.git diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/tx/ProxyReadTransaction.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/tx/ProxyReadTransaction.java index 0756f33ddf..ed972c1d5d 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/tx/ProxyReadTransaction.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/tx/ProxyReadTransaction.java @@ -9,124 +9,25 @@ package org.opendaylight.netconf.topology.singleton.impl.tx; import akka.actor.ActorRef; -import akka.actor.ActorSystem; -import akka.dispatch.OnComplete; -import akka.pattern.Patterns; import akka.util.Timeout; -import com.google.common.base.Optional; -import com.google.common.util.concurrent.CheckedFuture; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.SettableFuture; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction; import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; -import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils; -import org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage; -import org.opendaylight.netconf.topology.singleton.messages.transactions.EmptyReadResponse; -import org.opendaylight.netconf.topology.singleton.messages.transactions.ExistsRequest; -import org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import scala.concurrent.ExecutionContext; import scala.concurrent.Future; /** * ProxyReadTransaction uses provided {@link ActorRef} to delegate method calls to master * {@link org.opendaylight.netconf.topology.singleton.impl.actors.ReadTransactionActor}. */ -public class ProxyReadTransaction implements DOMDataReadOnlyTransaction { +public class ProxyReadTransaction extends ProxyReadWriteTransaction implements DOMDataReadOnlyTransaction { - private static final Logger LOG = LoggerFactory.getLogger(ProxyReadTransaction.class); - - private final ActorRef masterTxActor; - private final RemoteDeviceId id; - private final ActorSystem actorSystem; - private final Timeout askTimeout; - - /** - * @param masterTxActor {@link org.opendaylight.netconf.topology.singleton.impl.actors.ReadTransactionActor} ref - * @param id device id - * @param actorSystem system - * @param askTimeout - */ - public ProxyReadTransaction(final ActorRef masterTxActor, final RemoteDeviceId id, final ActorSystem actorSystem, - final Timeout askTimeout) { - this.masterTxActor = masterTxActor; - this.id = id; - this.actorSystem = actorSystem; - this.askTimeout = askTimeout; + public ProxyReadTransaction(final RemoteDeviceId id, final Future masterTxActorFuture, + final ExecutionContext executionContext, final Timeout askTimeout) { + super(id, masterTxActorFuture, executionContext, askTimeout); } @Override public void close() { - //noop - } - - @Override - public CheckedFuture>, ReadFailedException> read(final LogicalDatastoreType store, - final YangInstanceIdentifier path) { - LOG.trace("{}: Read {} via NETCONF: {}", id, store, path); - - final Future future = Patterns.ask(masterTxActor, new ReadRequest(store, path), askTimeout); - final SettableFuture>> settableFuture = SettableFuture.create(); - future.onComplete(new OnComplete() { - @Override - public void onComplete(final Throwable failure, - final Object success) throws Throwable { - if (failure != null) { // ask timeout - final Exception exception = NetconfTopologyUtils.createMasterIsDownException(id); - settableFuture.setException(exception); - return; - } - if (success instanceof Throwable) { // Error sended by master - settableFuture.setException((Throwable) success); - return; - } - if (success instanceof EmptyReadResponse) { - settableFuture.set(Optional.absent()); - return; - } - if (success instanceof NormalizedNodeMessage) { - final NormalizedNodeMessage data = (NormalizedNodeMessage) success; - settableFuture.set(Optional.of(data.getNode())); - } - } - }, actorSystem.dispatcher()); - return Futures.makeChecked(settableFuture, ReadFailedException.MAPPER); - } - - @Override - public CheckedFuture exists(final LogicalDatastoreType store, - final YangInstanceIdentifier path) { - final Future existsScalaFuture = - Patterns.ask(masterTxActor, new ExistsRequest(store, path), askTimeout); - - LOG.trace("{}: Exists {} via NETCONF: {}", id, store, path); - - final SettableFuture settableFuture = SettableFuture.create(); - existsScalaFuture.onComplete(new OnComplete() { - @Override - public void onComplete(final Throwable failure, final Object success) throws Throwable { - if (failure != null) { // ask timeout - final Exception exception = NetconfTopologyUtils.createMasterIsDownException(id); - settableFuture.setException(exception); - return; - } - if (success instanceof Throwable) { - settableFuture.setException((Throwable) success); - return; - } - settableFuture.set((Boolean) success); - } - }, actorSystem.dispatcher()); - return Futures.makeChecked(settableFuture, ReadFailedException.MAPPER); - } - - - @Override - public Object getIdentifier() { - return this; + // noop } }