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;
19 public class MergeData extends ModifyData implements VersionedSerializableMessage {
20 private static final long serialVersionUID = 1L;
22 public static final Class<MergeData> SERIALIZABLE_CLASS = MergeData.class;
27 public MergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
32 public Object toSerializable(short toVersion) {
33 if(toVersion >= DataStoreVersions.LITHIUM_VERSION) {
34 setVersion(toVersion);
37 // To base or R1 Helium version
38 Encoded encoded = new NormalizedNodeToNodeCodec(null).encode(getPath(), getData());
39 return ShardTransactionMessages.MergeData.newBuilder()
40 .setInstanceIdentifierPathArguments(encoded.getEncodedPath())
41 .setNormalizedNode(encoded.getEncodedNode().getNormalizedNode()).build();
45 public static MergeData fromSerializable(Object serializable){
46 if(serializable instanceof MergeData) {
47 return (MergeData) serializable;
49 // From base or R1 Helium version
50 ShardTransactionMessages.MergeData o = (ShardTransactionMessages.MergeData) serializable;
51 Decoded decoded = new NormalizedNodeToNodeCodec(null).decode(
52 o.getInstanceIdentifierPathArguments(), o.getNormalizedNode());
53 return new MergeData(decoded.getDecodedPath(), decoded.getDecodedNode());
57 public static boolean isSerializedType(Object message) {
58 return SERIALIZABLE_CLASS.isInstance(message) ||
59 message instanceof ShardTransactionMessages.MergeData;