2 * Copyright (c) 2014 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
9 package org.opendaylight.controller.cluster.datastore.messages;
11 import com.google.common.base.Optional;
12 import com.google.common.util.concurrent.CheckedFuture;
13 import com.google.common.util.concurrent.SettableFuture;
14 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
15 import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils;
16 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
17 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
18 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22 public class ReadData extends AbstractRead<Optional<NormalizedNode<?, ?>>> {
23 private static final long serialVersionUID = 1L;
28 public ReadData(final YangInstanceIdentifier path, short version) {
34 protected Object newLegacySerializedInstance() {
35 return ShardTransactionMessages.ReadData.newBuilder()
36 .setInstanceIdentifierPathArguments(InstanceIdentifierUtils.toSerializable(getPath())).build();
40 public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> apply(DOMStoreReadTransaction readDelegate) {
41 return readDelegate.read(getPath());
45 public void processResponse(Object readResponse, SettableFuture<Optional<NormalizedNode<?, ?>>> returnFuture) {
46 if(ReadDataReply.isSerializedType(readResponse)) {
47 ReadDataReply reply = ReadDataReply.fromSerializable(readResponse);
48 returnFuture.set(Optional.<NormalizedNode<?, ?>> fromNullable(reply.getNormalizedNode()));
50 returnFuture.setException(new ReadFailedException("Invalid response reading data for path " + getPath()));
55 protected AbstractRead<Optional<NormalizedNode<?, ?>>> newInstance(short withVersion) {
56 return new ReadData(getPath(), withVersion);
59 public static ReadData fromSerializable(final Object serializable) {
60 if(serializable instanceof ReadData) {
61 return (ReadData)serializable;
63 ShardTransactionMessages.ReadData o = (ShardTransactionMessages.ReadData)serializable;
64 return new ReadData(InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPathArguments()),
65 DataStoreVersions.LITHIUM_VERSION);
69 public static boolean isSerializedType(Object message) {
70 return message instanceof ReadData || message instanceof ShardTransactionMessages.ReadData;