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
8 package org.opendaylight.controller.cluster.datastore.messages;
10 import com.google.common.base.Preconditions;
11 import com.google.common.util.concurrent.FluentFuture;
12 import com.google.common.util.concurrent.SettableFuture;
13 import java.util.Optional;
14 import org.opendaylight.mdsal.common.api.ReadFailedException;
15 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 public class ReadData extends AbstractRead<Optional<NormalizedNode>> {
20 private static final long serialVersionUID = 1L;
25 public ReadData(final YangInstanceIdentifier path, final short version) {
30 public FluentFuture<Optional<NormalizedNode>> apply(final DOMStoreReadTransaction readDelegate) {
31 return readDelegate.read(getPath());
35 public void processResponse(final Object readResponse,
36 final SettableFuture<Optional<NormalizedNode>> returnFuture) {
37 if (ReadDataReply.isSerializedType(readResponse)) {
38 ReadDataReply reply = ReadDataReply.fromSerializable(readResponse);
39 returnFuture.set(Optional.ofNullable(reply.getNormalizedNode()));
41 returnFuture.setException(new ReadFailedException("Invalid response reading data for path " + getPath()));
46 protected AbstractRead<Optional<NormalizedNode>> newInstance(final short withVersion) {
47 return new ReadData(getPath(), withVersion);
50 public static ReadData fromSerializable(final Object serializable) {
51 Preconditions.checkArgument(serializable instanceof ReadData);
52 return (ReadData)serializable;
55 public static boolean isSerializedType(final Object message) {
56 return message instanceof ReadData;