2 * Copyright (c) 2014 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
9 package org.opendaylight.controller.cluster.datastore.messages;
11 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
12 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
13 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Decoded;
14 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Encoded;
15 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 * @deprecated Replaced by BatchedModifications.
23 public class MergeData extends ModifyData {
24 private static final long serialVersionUID = 1L;
26 public static final Class<MergeData> SERIALIZABLE_CLASS = MergeData.class;
31 public MergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data, short version) {
32 super(path, data, version);
36 public Object toSerializable() {
37 if(getVersion() >= DataStoreVersions.LITHIUM_VERSION) {
40 // To base or R1 Helium version
41 Encoded encoded = new NormalizedNodeToNodeCodec(null).encode(getPath(), getData());
42 return ShardTransactionMessages.MergeData.newBuilder()
43 .setInstanceIdentifierPathArguments(encoded.getEncodedPath())
44 .setNormalizedNode(encoded.getEncodedNode().getNormalizedNode()).build();
48 public static MergeData fromSerializable(Object serializable){
49 if(serializable instanceof MergeData) {
50 return (MergeData) serializable;
52 // From base or R1 Helium version
53 ShardTransactionMessages.MergeData o = (ShardTransactionMessages.MergeData) serializable;
54 Decoded decoded = new NormalizedNodeToNodeCodec(null).decode(
55 o.getInstanceIdentifierPathArguments(), o.getNormalizedNode());
56 return new MergeData(decoded.getDecodedPath(), decoded.getDecodedNode(),
57 DataStoreVersions.HELIUM_2_VERSION);
61 public static boolean isSerializedType(Object message) {
62 return SERIALIZABLE_CLASS.isInstance(message) ||
63 message instanceof ShardTransactionMessages.MergeData;