Merge "Bug 2597: Batch modification operations in TransactionProxy"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / DeleteData.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.datastore.messages;
10
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
15 import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils;
16 import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils;
17 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19
20 /**
21  * @deprecated Replaced by BatchedModifications.
22  */
23 @Deprecated
24 public class DeleteData extends VersionedExternalizableMessage {
25     private static final long serialVersionUID = 1L;
26
27     public static final Class<DeleteData> SERIALIZABLE_CLASS = DeleteData.class;
28
29     private YangInstanceIdentifier path;
30
31     public DeleteData() {
32     }
33
34     public DeleteData(final YangInstanceIdentifier path, short version) {
35         super(version);
36         this.path = path;
37     }
38
39     public YangInstanceIdentifier getPath() {
40         return path;
41     }
42
43     @Override
44     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
45         super.readExternal(in);
46         path = SerializationUtils.deserializePath(in);
47     }
48
49     @Override
50     public void writeExternal(ObjectOutput out) throws IOException {
51         super.writeExternal(out);
52         SerializationUtils.serializePath(path, out);
53     }
54
55     @Override
56     public Object toSerializable() {
57         if(getVersion() >= DataStoreVersions.LITHIUM_VERSION) {
58             return this;
59         } else {
60             // To base or R1 Helium version
61             return ShardTransactionMessages.DeleteData.newBuilder().setInstanceIdentifierPathArguments(
62                     InstanceIdentifierUtils.toSerializable(path)).build();
63         }
64     }
65
66     public static DeleteData fromSerializable(final Object serializable) {
67         if(serializable instanceof DeleteData) {
68             return (DeleteData) serializable;
69         } else {
70             // From base or R1 Helium version
71             ShardTransactionMessages.DeleteData o = (ShardTransactionMessages.DeleteData) serializable;
72             return new DeleteData(InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPathArguments()),
73                     DataStoreVersions.HELIUM_2_VERSION);
74         }
75     }
76
77     public static boolean isSerializedType(Object message) {
78         return SERIALIZABLE_CLASS.isInstance(message) ||
79                message instanceof ShardTransactionMessages.DeleteData;
80     }
81 }