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