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.util.InstanceIdentifierUtils;
15 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
16 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 public class ReadData extends AbstractRead<Optional<NormalizedNode<?, ?>>> {
22 public static final Class<ShardTransactionMessages.ReadData> SERIALIZABLE_CLASS = ShardTransactionMessages.ReadData.class;
24 public ReadData(final YangInstanceIdentifier path) {
29 public Object toSerializable() {
30 return ShardTransactionMessages.ReadData.newBuilder()
31 .setInstanceIdentifierPathArguments(InstanceIdentifierUtils.toSerializable(getPath())).build();
34 public static ReadData fromSerializable(final Object serializable) {
35 ShardTransactionMessages.ReadData o = (ShardTransactionMessages.ReadData)serializable;
36 return new ReadData(InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPathArguments()));
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()));