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.commands;
10 import akka.actor.ActorRef;
11 import akka.actor.ActorSelection;
12 import akka.serialization.JavaSerializer;
13 import akka.serialization.Serialization;
14 import java.io.DataInput;
15 import java.io.IOException;
16 import java.io.ObjectInput;
17 import java.io.ObjectOutput;
18 import java.io.Serial;
19 import java.util.ArrayList;
20 import java.util.List;
21 import org.opendaylight.controller.cluster.access.concepts.AbstractSuccessProxy;
22 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
25 * Externalizable proxy for use with {@link ConnectClientSuccess}. It implements the initial (Boron) serialization
28 * @author Robert Varga
30 final class ConnectClientSuccessProxyV1 extends AbstractSuccessProxy<ClientIdentifier, ConnectClientSuccess> {
32 private static final long serialVersionUID = 1L;
34 private List<ActorSelection> alternates;
35 private ActorRef backend;
36 private int maxMessages;
38 // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to
39 // be able to create instances via reflection.
40 @SuppressWarnings("checkstyle:RedundantModifier")
41 public ConnectClientSuccessProxyV1() {
45 ConnectClientSuccessProxyV1(final ConnectClientSuccess success) {
47 alternates = success.getAlternates();
48 backend = success.getBackend();
49 maxMessages = success.getMaxMessages();
50 // We are ignoring the DataTree, it is not serializable anyway
54 public void writeExternal(final ObjectOutput out) throws IOException {
55 super.writeExternal(out);
57 out.writeObject(Serialization.serializedActorPath(backend));
58 out.writeInt(maxMessages);
60 out.writeInt(alternates.size());
61 for (ActorSelection b : alternates) {
62 out.writeObject(b.toSerializationFormat());
67 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
68 super.readExternal(in);
70 backend = JavaSerializer.currentSystem().value().provider().resolveActorRef((String) in.readObject());
71 maxMessages = in.readInt();
73 final int alternatesSize = in.readInt();
74 alternates = new ArrayList<>(alternatesSize);
75 for (int i = 0; i < alternatesSize; ++i) {
76 alternates.add(ActorSelection.apply(ActorRef.noSender(), (String)in.readObject()));
81 protected ConnectClientSuccess createSuccess(final ClientIdentifier target, final long sequence) {
82 return new ConnectClientSuccess(target, sequence, backend, alternates, maxMessages, null);
86 protected ClientIdentifier readTarget(final DataInput in) throws IOException {
87 return ClientIdentifier.readFrom(in);