Fix intermittent testOwnerChangesOnPeerAvailabilityChanges failure
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / behaviors / FollowerIdentifier.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.raft.behaviors;
9
10 import java.io.Externalizable;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import org.opendaylight.yangtools.util.AbstractStringIdentifier;
15
16 /**
17  * An Identifier for a follower.
18  *
19  * @author Thomas Pantelis
20  */
21 class FollowerIdentifier extends AbstractStringIdentifier<FollowerIdentifier> {
22     private static final long serialVersionUID = 1L;
23
24     FollowerIdentifier(String followerId) {
25         super(followerId);
26     }
27
28     private Object writeReplace() {
29         return new Proxy(this);
30     }
31
32     private static class Proxy implements Externalizable {
33         private static final long serialVersionUID = 1L;
34
35         private FollowerIdentifier identifier;
36
37         // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
38         // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
39         @SuppressWarnings("checkstyle:RedundantModifier")
40         public Proxy() {
41         }
42
43         Proxy(FollowerIdentifier identifier) {
44             this.identifier = identifier;
45         }
46
47         @Override
48         public void writeExternal(ObjectOutput out) throws IOException {
49             out.writeObject(identifier.getValue());
50         }
51
52         @Override
53         public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
54             identifier = new FollowerIdentifier((String) in.readObject());
55         }
56
57         private Object readResolve() {
58             return identifier;
59         }
60     }
61 }