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.base.Preconditions;
13 import com.google.common.util.concurrent.CheckedFuture;
14 import com.google.common.util.concurrent.SettableFuture;
15 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
16 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 public class ReadData extends AbstractRead<Optional<NormalizedNode<?, ?>>> {
21 private static final long serialVersionUID = 1L;
26 public ReadData(final YangInstanceIdentifier path, short version) {
31 public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> apply(
32 DOMStoreReadTransaction readDelegate) {
33 return readDelegate.read(getPath());
37 public void processResponse(Object readResponse, SettableFuture<Optional<NormalizedNode<?, ?>>> returnFuture) {
38 if (ReadDataReply.isSerializedType(readResponse)) {
39 ReadDataReply reply = ReadDataReply.fromSerializable(readResponse);
40 returnFuture.set(Optional.<NormalizedNode<?, ?>>fromNullable(reply.getNormalizedNode()));
42 returnFuture.setException(new ReadFailedException("Invalid response reading data for path " + getPath()));
47 protected AbstractRead<Optional<NormalizedNode<?, ?>>> newInstance(short withVersion) {
48 return new ReadData(getPath(), withVersion);
51 public static ReadData fromSerializable(final Object serializable) {
52 Preconditions.checkArgument(serializable instanceof ReadData);
53 return (ReadData)serializable;
56 public static boolean isSerializedType(Object message) {
57 return message instanceof ReadData;