2 * Copyright (c) 2016 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.access.concepts;
10 import akka.actor.ActorRef;
11 import akka.serialization.JavaSerializer;
12 import akka.serialization.Serialization;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import java.io.Serial;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.yangtools.concepts.WritableIdentifier;
21 * Abstract Externalizable proxy for use with {@link Request} subclasses.
23 * @param <T> Target identifier type
25 public abstract class AbstractRequestProxy<T extends WritableIdentifier, C extends Request<T, C>>
26 extends AbstractMessageProxy<T, C> {
28 private static final long serialVersionUID = 1L;
30 private ActorRef replyTo;
32 protected AbstractRequestProxy() {
36 protected AbstractRequestProxy(final @NonNull C request) {
38 this.replyTo = request.getReplyTo();
42 public void writeExternal(final ObjectOutput out) throws IOException {
43 super.writeExternal(out);
44 out.writeObject(Serialization.serializedActorPath(replyTo));
48 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
49 super.readExternal(in);
50 replyTo = JavaSerializer.currentSystem().value().provider().resolveActorRef((String) in.readObject());
54 final C createMessage(final T target, final long sequence) {
55 return createRequest(target, sequence, replyTo);
58 protected abstract @NonNull C createRequest(@NonNull T target, long sequence, @NonNull ActorRef replyToActor);