2 * Copyright (c) 2015 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.datastore;
10 import com.google.common.base.Preconditions;
11 import com.google.common.io.ByteArrayDataOutput;
12 import com.google.common.io.ByteStreams;
13 import java.io.Externalizable;
14 import java.io.IOException;
15 import java.io.ObjectInput;
16 import java.io.ObjectOutput;
17 import org.opendaylight.controller.cluster.datastore.persisted.DataTreeCandidateInputOutput;
18 import org.opendaylight.controller.cluster.raft.persisted.MigratedSerializable;
19 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
20 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
23 * @deprecated Deprecated in Boron in favor of CommitTransactionPayload
26 final class DataTreeCandidatePayload extends Payload implements Externalizable, MigratedSerializable {
27 private static final long serialVersionUID = 1L;
29 private transient byte[] serialized;
31 public DataTreeCandidatePayload() {
32 // Required by Externalizable
35 private DataTreeCandidatePayload(final byte[] serialized) {
36 this.serialized = Preconditions.checkNotNull(serialized);
40 * @deprecated Use CommitTransactionPayload instead
43 static DataTreeCandidatePayload create(final DataTreeCandidate candidate) {
44 final ByteArrayDataOutput out = ByteStreams.newDataOutput();
46 DataTreeCandidateInputOutput.writeDataTreeCandidate(out, candidate);
47 } catch (IOException e) {
48 throw new IllegalArgumentException(String.format("Failed to serialize candidate %s", candidate), e);
51 return new DataTreeCandidatePayload(out.toByteArray());
54 public DataTreeCandidate getCandidate() throws IOException {
55 return DataTreeCandidateInputOutput.readDataTreeCandidate(ByteStreams.newDataInput(serialized));
60 return serialized.length;
64 public void writeExternal(final ObjectOutput out) throws IOException {
65 out.writeByte((byte)serialVersionUID);
66 out.writeInt(serialized.length);
67 out.write(serialized);
71 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
72 final long version = in.readByte();
73 Preconditions.checkArgument(version == serialVersionUID, "Unsupported serialization version %s", version);
75 final int length = in.readInt();
76 serialized = new byte[length];
77 in.readFully(serialized);
81 public boolean isMigrated() {
87 public Object writeReplace() {