Remove deprecated Helium Payload methods
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / raft / protobuff / client / messages / CompositeModificationByteStringPayload.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.raft.protobuff.client.messages;
10
11 import com.google.common.annotations.VisibleForTesting;
12 import com.google.common.base.Preconditions;
13 import com.google.protobuf.ByteString;
14 import com.google.protobuf.InvalidProtocolBufferException;
15 import java.io.IOException;
16 import java.io.Serializable;
17 import java.lang.ref.SoftReference;
18 import org.opendaylight.controller.protobuff.messages.persistent.PersistentMessages;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 @Deprecated
23 public class CompositeModificationByteStringPayload extends Payload implements
24         Serializable {
25     private static final long serialVersionUID = 1L;
26
27     private ByteString byteString;
28     private SoftReference<PersistentMessages.CompositeModification> modificationReference;
29     private static final Logger LOG = LoggerFactory.getLogger(CompositeModificationByteStringPayload.class);
30
31     public CompositeModificationByteStringPayload(){
32         byteString = null;
33     }
34     public CompositeModificationByteStringPayload(Object modification){
35         this(((PersistentMessages.CompositeModification) modification).toByteString());
36         this.modificationReference = new SoftReference<>((PersistentMessages.CompositeModification) modification);
37     }
38
39     private CompositeModificationByteStringPayload(ByteString byteString){
40         this.byteString = Preconditions.checkNotNull(byteString, "byteString should not be null");
41     }
42
43     public Object getModification(){
44         return getModificationInternal();
45     }
46
47     private PersistentMessages.CompositeModification getModificationInternal(){
48         if(this.modificationReference != null && this.modificationReference.get() != null){
49             return this.modificationReference.get();
50         }
51         try {
52             PersistentMessages.CompositeModification compositeModification = PersistentMessages.CompositeModification.parseFrom(this.byteString);
53             this.modificationReference = new SoftReference<>(compositeModification);
54             return compositeModification;
55         } catch (InvalidProtocolBufferException e) {
56             LOG.error("Unexpected exception occurred when parsing byteString to CompositeModification", e);
57         }
58
59         return null;
60     }
61
62     @Override
63     public int size(){
64         return byteString.size();
65     }
66
67     private void writeObject(java.io.ObjectOutputStream stream)
68             throws IOException {
69         byteString.writeTo(stream);
70     }
71
72     private void readObject(java.io.ObjectInputStream stream)
73             throws IOException, ClassNotFoundException {
74         byteString = ByteString.readFrom(stream);
75     }
76
77     @VisibleForTesting
78     public void clearModificationReference(){
79         if(this.modificationReference != null) {
80             this.modificationReference.clear();
81         }
82     }
83 }