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 =
23 ShardTransactionMessages.ReadData.class;
25 public ReadData(final YangInstanceIdentifier path) {
29 public Object toSerializable(){
30 return ShardTransactionMessages.ReadData.newBuilder()
31 .setInstanceIdentifierPathArguments(InstanceIdentifierUtils.toSerializable(getPath()))
35 public static ReadData fromSerializable(final Object serializable){
36 ShardTransactionMessages.ReadData o = (ShardTransactionMessages.ReadData) serializable;
37 return new ReadData(InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPathArguments()));
41 public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> apply(DOMStoreReadTransaction readDelegate) {
42 return readDelegate.read(getPath());
46 public void processResponse(Object readResponse, SettableFuture<Optional<NormalizedNode<?, ?>>> returnFuture) {
47 if(readResponse instanceof ReadDataReply) {
48 ReadDataReply reply = (ReadDataReply) readResponse;
49 returnFuture.set(Optional.<NormalizedNode<?, ?>> fromNullable(reply.getNormalizedNode()));
51 } else if(ReadDataReply.isSerializedType(readResponse)) {
52 ReadDataReply reply = ReadDataReply.fromSerializable(readResponse);
53 returnFuture.set(Optional.<NormalizedNode<?, ?>> fromNullable(reply.getNormalizedNode()));
56 returnFuture.setException(new ReadFailedException("Invalid response reading data for path " + getPath()));