Remove use of thread-local input
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / AbstractRead.java
1 /*
2  * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.datastore.messages;
10
11 import com.google.common.util.concurrent.FluentFuture;
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.mdsal.dom.spi.store.DOMStoreReadTransaction;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19
20 /**
21  * Abstract base class for ReadData and DataExists messages.
22  *
23  * @author gwu
24  *
25  */
26 public abstract class AbstractRead<T> extends VersionedExternalizableMessage {
27     private static final long serialVersionUID = 1L;
28
29     private YangInstanceIdentifier path;
30
31     protected AbstractRead() {
32     }
33
34     public AbstractRead(final YangInstanceIdentifier path, final short version) {
35         super(version);
36         this.path = path;
37     }
38
39     public YangInstanceIdentifier getPath() {
40         return path;
41     }
42
43     @Override
44     public final void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
45         super.readExternal(in);
46         path = SerializationUtils.readPath(in);
47     }
48
49     @Override
50     public void writeExternal(final ObjectOutput out) throws IOException {
51         super.writeExternal(out);
52         SerializationUtils.writePath(out, path);
53     }
54
55     public AbstractRead<T> asVersion(final short version) {
56         return version == getVersion() ? this : newInstance(version);
57     }
58
59     public abstract FluentFuture<T> apply(DOMStoreReadTransaction readDelegate);
60
61     public abstract void processResponse(Object reponse, SettableFuture<T> promise);
62
63     protected abstract AbstractRead<T> newInstance(short withVersion);
64 }