2 * Copyright (c) 2017 Brocade Communications Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.datastore.persisted;
10 import static java.util.Objects.requireNonNull;
12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13 import java.io.Externalizable;
14 import java.io.IOException;
15 import java.io.ObjectInput;
16 import java.io.ObjectOutput;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
21 * Encapsulates the snapshot State for a Shard.
23 * @author Thomas Pantelis
25 public class ShardSnapshotState implements Snapshot.State {
26 private static final long serialVersionUID = 1L;
28 private static final class Proxy implements Externalizable {
29 private static final long serialVersionUID = 1L;
31 private ShardSnapshotState snapshotState;
33 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
34 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
35 @SuppressWarnings("checkstyle:RedundantModifier")
40 Proxy(final ShardSnapshotState snapshotState) {
41 this.snapshotState = snapshotState;
45 public void writeExternal(final ObjectOutput out) throws IOException {
46 snapshotState.snapshot.serialize(out);
50 public void readExternal(final ObjectInput in) throws IOException {
51 snapshotState = new ShardSnapshotState(ShardDataTreeSnapshot.deserialize(in));
54 private Object readResolve() {
59 @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but this class "
60 + "implements writeReplace to delegate serialization to a Proxy class and thus instances of this class "
61 + "aren't serialized. FindBugs does not recognize this.")
62 private final ShardDataTreeSnapshot snapshot;
64 public ShardSnapshotState(final @NonNull ShardDataTreeSnapshot snapshot) {
65 this.snapshot = requireNonNull(snapshot);
68 public @NonNull ShardDataTreeSnapshot getSnapshot() {
72 private Object writeReplace() {
73 return new Proxy(this);