Move Lithium-specific logic from AbstractNormalizedNodeDataOutput
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / messaging / AbortSlicing.java
1 /*
2  * Copyright (c) 2017 Inocybe Technologies 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 package org.opendaylight.controller.cluster.messaging;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.io.Externalizable;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import java.io.Serializable;
17 import org.opendaylight.yangtools.concepts.Identifier;
18
19 /**
20  * Message sent to abort slicing.
21  *
22  * @author Thomas Pantelis
23  */
24 class AbortSlicing implements Serializable {
25     private static final long serialVersionUID = 1L;
26
27     private final Identifier identifier;
28
29     AbortSlicing(final Identifier identifier) {
30         this.identifier = requireNonNull(identifier);
31     }
32
33     Identifier getIdentifier() {
34         return identifier;
35     }
36
37     @Override
38     public String toString() {
39         return "AbortSlicing [identifier=" + identifier + "]";
40     }
41
42     private Object writeReplace() {
43         return new Proxy(this);
44     }
45
46     private static class Proxy implements Externalizable {
47         private static final long serialVersionUID = 1L;
48
49         private AbortSlicing abortSlicing;
50
51         // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
52         // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
53         @SuppressWarnings("checkstyle:RedundantModifier")
54         public Proxy() {
55         }
56
57         Proxy(final AbortSlicing abortSlicing) {
58             this.abortSlicing = abortSlicing;
59         }
60
61         @Override
62         public void writeExternal(final ObjectOutput out) throws IOException {
63             out.writeObject(abortSlicing.identifier);
64         }
65
66         @Override
67         public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
68             abortSlicing = new AbortSlicing((Identifier) in.readObject());
69         }
70
71         private Object readResolve() {
72             return abortSlicing;
73         }
74     }
75 }