f1a3a3b923cab4bd370511316663ce74e20d402e
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / persisted / NoopPayload.java
1 /*
2  * Copyright (c) 2016 Brocade Communications 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 package org.opendaylight.controller.cluster.raft.persisted;
9
10 import akka.dispatch.ControlMessage;
11 import java.io.Serializable;
12 import org.apache.commons.lang3.SerializationUtils;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.controller.cluster.raft.messages.Payload;
15
16 /**
17  * Payload used for no-op log entries that are put into the journal by the PreLeader in order to commit
18  * entries from the prior term.
19  *
20  * @author Thomas Pantelis
21  */
22 // FIXME: do not implement MigratedSerializable once Proxy is gone
23 public final class NoopPayload extends Payload implements ControlMessage, MigratedSerializable {
24     // There is no need for Externalizable
25     @Deprecated(since = "7.0.0", forRemoval = true)
26     private static final class Proxy implements Serializable {
27         @java.io.Serial
28         private static final long serialVersionUID = 1L;
29         private static final @NonNull NoopPayload INSTANCE = new NoopPayload(true);
30
31         @java.io.Serial
32         private Object readResolve() {
33             return INSTANCE;
34         }
35     }
36
37     @java.io.Serial
38     private static final long serialVersionUID = 1L;
39     private static final @NonNull NP PROXY = new NP();
40     // Estimate to how big the proxy is. Note this includes object stream overhead, so it is a bit conservative
41     private static final int PROXY_SIZE = SerializationUtils.serialize(PROXY).length;
42
43     public static final @NonNull NoopPayload INSTANCE = new NoopPayload(false);
44
45     private final boolean migrated;
46
47     private NoopPayload(final boolean migrated) {
48         this.migrated = migrated;
49     }
50
51     @Override
52     public int size() {
53         return 0;
54     }
55
56     @Override
57     public int serializedSize() {
58         return PROXY_SIZE;
59     }
60
61     @Override
62     public boolean isMigrated() {
63         return migrated;
64     }
65
66     // FIXME: protected once not MigratedSerializable
67     @Override
68     public Object writeReplace() {
69         return PROXY;
70     }
71 }