X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fmessages%2FReadData.java;h=c2709d757fdacc83ea6932337dd27ee64f7ab46f;hb=refs%2Fchanges%2F78%2F33178%2F3;hp=cb6347f3e54909330ea924956029f895f44f69e1;hpb=fe4049d34de103016d11f3a9050853c6380646d3;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ReadData.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ReadData.java index cb6347f3e5..c2709d757f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ReadData.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ReadData.java @@ -8,30 +8,68 @@ package org.opendaylight.controller.cluster.datastore.messages; -import org.opendaylight.controller.cluster.datastore.utils.InstanceIdentifierUtils; +import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.SettableFuture; +import org.opendaylight.controller.cluster.datastore.DataStoreVersions; +import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils; +import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; - -public class ReadData { - public static final Class SERIALIZABLE_CLASS = ShardTransactionMessages.ReadData.class; - private final InstanceIdentifier path; - - public ReadData(InstanceIdentifier path) { - this.path = path; - } - - public InstanceIdentifier getPath() { - return path; - } - - public Object toSerializable(){ - return ShardTransactionMessages.ReadData.newBuilder() - .setInstanceIdentifierPathArguments(path.toString()) - .build(); - } - - public static ReadData fromSerializable(Object serializable){ - ShardTransactionMessages.ReadData o = (ShardTransactionMessages.ReadData) serializable; - return new ReadData(InstanceIdentifierUtils.from(o.getInstanceIdentifierPathArguments())); - } +import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; + +public class ReadData extends AbstractRead>> { + private static final long serialVersionUID = 1L; + + public ReadData() { + } + + public ReadData(final YangInstanceIdentifier path, short version) { + super(path, version); + } + + @Override + public Object toSerializable() { + if(getVersion() >= DataStoreVersions.BORON_VERSION) { + return this; + } else { + return ShardTransactionMessages.ReadData.newBuilder().setInstanceIdentifierPathArguments( + InstanceIdentifierUtils.toSerializable(getPath())).build(); + } + } + + @Override + public CheckedFuture>, ReadFailedException> apply(DOMStoreReadTransaction readDelegate) { + return readDelegate.read(getPath()); + } + + @Override + public void processResponse(Object readResponse, SettableFuture>> returnFuture) { + if(ReadDataReply.isSerializedType(readResponse)) { + ReadDataReply reply = ReadDataReply.fromSerializable(readResponse); + returnFuture.set(Optional.> fromNullable(reply.getNormalizedNode())); + } else { + returnFuture.setException(new ReadFailedException("Invalid response reading data for path " + getPath())); + } + } + + @Override + protected AbstractRead>> newInstance(short withVersion) { + return new ReadData(getPath(), withVersion); + } + + public static ReadData fromSerializable(final Object serializable) { + if(serializable instanceof ReadData) { + return (ReadData)serializable; + } else { + ShardTransactionMessages.ReadData o = (ShardTransactionMessages.ReadData)serializable; + return new ReadData(InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPathArguments()), + DataStoreVersions.LITHIUM_VERSION); + } + } + + public static boolean isSerializedType(Object message) { + return message instanceof ReadData || message instanceof ShardTransactionMessages.ReadData; + } }