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.util.ArrayList;
19 import java.util.List;
20 import java.util.Optional;
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> {
31 private static final long serialVersionUID = 1L;
33 private List<ActorSelection> alternates;
34 private ActorRef backend;
35 private long maxMessages;
37 public ConnectClientSuccessProxyV1() {
41 ConnectClientSuccessProxyV1(final ConnectClientSuccess success) {
43 this.alternates = success.getAlternates();
44 this.backend = success.getBackend();
45 // We are ignoring the DataTree, it is not serializable anyway
49 public void writeExternal(final ObjectOutput out) throws IOException {
50 super.writeExternal(out);
52 out.writeUTF(Serialization.serializedActorPath(backend));
54 out.writeInt(alternates.size());
55 for (ActorSelection b : alternates) {
56 out.writeObject(b.toSerializationFormat());
59 out.writeLong(maxMessages);
63 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
64 super.readExternal(in);
66 backend = JavaSerializer.currentSystem().value().provider().resolveActorRef(in.readUTF());
68 final int backendsSize = in.readInt();
69 if (backendsSize < 1) {
70 throw new IOException("Illegal number of backends " + backendsSize);
73 alternates = new ArrayList<>(backendsSize);
74 for (int i = 0; i < backendsSize; ++i) {
75 alternates.add(ActorSelection.apply(ActorRef.noSender(), (String)in.readObject()));
78 maxMessages = in.readLong();
82 protected ConnectClientSuccess createSuccess(final ClientIdentifier target) {
83 return new ConnectClientSuccess(target, backend, alternates, Optional.empty(), maxMessages);
87 protected ClientIdentifier readTarget(final DataInput in) throws IOException {
88 return ClientIdentifier.readFrom(in);