Bump cds-access-api ABIVersion
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / concepts / AbstractRequestProxy.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, 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 package org.opendaylight.controller.cluster.access.concepts;
9
10 import akka.actor.ActorRef;
11 import akka.serialization.JavaSerializer;
12 import akka.serialization.Serialization;
13 import com.google.common.annotations.Beta;
14 import java.io.IOException;
15 import java.io.ObjectInput;
16 import java.io.ObjectOutput;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.yangtools.concepts.WritableIdentifier;
19
20 /**
21  * Abstract Externalizable proxy for use with {@link Request} subclasses.
22  *
23  * @author Robert Varga
24  *
25  * @param <T> Target identifier type
26  */
27 @Beta
28 public abstract class AbstractRequestProxy<T extends WritableIdentifier, C extends Request<T, C>>
29         extends AbstractMessageProxy<T, C> {
30     private static final long serialVersionUID = 1L;
31     private ActorRef replyTo;
32
33     protected AbstractRequestProxy() {
34         // For Externalizable
35     }
36
37     protected AbstractRequestProxy(final @NonNull C request) {
38         super(request);
39         this.replyTo = request.getReplyTo();
40     }
41
42     @Override
43     public void writeExternal(final ObjectOutput out) throws IOException {
44         super.writeExternal(out);
45         out.writeObject(Serialization.serializedActorPath(replyTo));
46     }
47
48     @Override
49     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
50         super.readExternal(in);
51         replyTo = JavaSerializer.currentSystem().value().provider().resolveActorRef((String) in.readObject());
52     }
53
54     @Override
55     final C createMessage(final T target, final long sequence) {
56         return createRequest(target, sequence, replyTo);
57     }
58
59     protected abstract @NonNull C createRequest(@NonNull T target, long sequence, @NonNull ActorRef replyToActor);
60 }