2 * Copyright (c) 2015 Huawei, 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.util.concurrent.CheckedFuture;
12 import com.google.common.util.concurrent.SettableFuture;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
17 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
18 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 * Abstract base class for ReadData and DataExists messages.
27 public abstract class AbstractRead<T> extends VersionedExternalizableMessage {
28 private static final long serialVersionUID = 1L;
30 private YangInstanceIdentifier path;
32 protected AbstractRead() {
35 public AbstractRead(final YangInstanceIdentifier path, final short version) {
40 public YangInstanceIdentifier getPath() {
45 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
46 super.readExternal(in);
47 path = SerializationUtils.deserializePath(in);
51 public void writeExternal(ObjectOutput out) throws IOException {
52 super.writeExternal(out);
53 SerializationUtils.serializePath(path, out);
56 public AbstractRead<T> asVersion(short version) {
57 return version == getVersion() ? this : newInstance(version);
60 public abstract CheckedFuture<T, ReadFailedException> apply(DOMStoreReadTransaction readDelegate);
62 public abstract void processResponse(Object reponse, SettableFuture<T> promise);
64 protected abstract AbstractRead<T> newInstance(short withVersion);