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 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;
21 * Abstract Externalizable proxy for use with {@link Request} subclasses.
23 * @author Robert Varga
25 * @param <T> Target identifier type
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;
33 protected AbstractRequestProxy() {
37 protected AbstractRequestProxy(final @NonNull C request) {
39 this.replyTo = request.getReplyTo();
43 public void writeExternal(final ObjectOutput out) throws IOException {
44 super.writeExternal(out);
45 out.writeObject(Serialization.serializedActorPath(replyTo));
49 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
50 super.readExternal(in);
51 replyTo = JavaSerializer.currentSystem().value().provider().resolveActorRef((String) in.readObject());
55 final C createMessage(final T target, final long sequence) {
56 return createRequest(target, sequence, replyTo);
59 protected abstract @NonNull C createRequest(@NonNull T target, long sequence, @NonNull ActorRef replyToActor);