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 com.google.common.base.Preconditions;
11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import java.io.Externalizable;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import javax.annotation.Nonnull;
17 import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
20 * Encapsulates the snapshot State for a Shard.
22 * @author Thomas Pantelis
24 public class ShardSnapshotState implements Snapshot.State {
25 private static final long serialVersionUID = 1L;
27 private static final class Proxy implements Externalizable {
28 private static final long serialVersionUID = 1L;
30 private ShardSnapshotState snapshotState;
32 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
33 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
34 @SuppressWarnings("checkstyle:RedundantModifier")
39 Proxy(final ShardSnapshotState snapshotState) {
40 this.snapshotState = snapshotState;
44 public void writeExternal(final ObjectOutput out) throws IOException {
45 snapshotState.snapshot.serialize(out);
49 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
50 snapshotState = new ShardSnapshotState(ShardDataTreeSnapshot.deserialize(in));
53 private Object readResolve() {
58 @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but this class "
59 + "implements writeReplace to delegate serialization to a Proxy class and thus instances of this class "
60 + "aren't serialized. FindBugs does not recognize this.")
61 private final ShardDataTreeSnapshot snapshot;
63 public ShardSnapshotState(@Nonnull final ShardDataTreeSnapshot snapshot) {
64 this.snapshot = Preconditions.checkNotNull(snapshot);
68 public ShardDataTreeSnapshot getSnapshot() {
72 private Object writeReplace() {
73 return new Proxy(this);