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;
36 public ConnectClientSuccessProxyV1() {
40 ConnectClientSuccessProxyV1(final ConnectClientSuccess success) {
42 this.alternates = success.getAlternates();
43 this.backend = success.getBackend();
44 // We are ignoring the DataTree, it is not serializable anyway
48 public void writeExternal(final ObjectOutput out) throws IOException {
49 super.writeExternal(out);
51 out.writeUTF(Serialization.serializedActorPath(backend));
53 out.writeInt(alternates.size());
54 for (ActorSelection b : alternates) {
55 out.writeObject(b.toSerializationFormat());
60 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
61 super.readExternal(in);
63 backend = JavaSerializer.currentSystem().value().provider().resolveActorRef(in.readUTF());
65 final int backendsSize = in.readInt();
66 if (backendsSize < 1) {
67 throw new IOException("Illegal number of backends " + backendsSize);
70 alternates = new ArrayList<>(backendsSize);
71 for (int i = 0; i < backendsSize; ++i) {
72 alternates.add(ActorSelection.apply(ActorRef.noSender(), (String)in.readObject()));
77 protected ConnectClientSuccess createSuccess(final ClientIdentifier target) {
78 return new ConnectClientSuccess(target, backend, alternates, Optional.empty());
82 protected ClientIdentifier readTarget(final DataInput in) throws IOException {
83 return ClientIdentifier.readFrom(in);