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.collect.ImmutableList;
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 java.util.ArrayList;
17 import java.util.List;
18 import org.eclipse.jdt.annotation.NonNull;
21 * Represents the persisted snapshot state for the ShardManager.
23 * @author Thomas Pantelis
25 public final class ShardManagerSnapshot implements Serializable {
26 private static final class Proxy implements Externalizable {
27 private static final long serialVersionUID = 1L;
29 private ShardManagerSnapshot snapshot;
31 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
32 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
33 @SuppressWarnings("checkstyle:RedundantModifier")
38 Proxy(final ShardManagerSnapshot snapshot) {
39 this.snapshot = snapshot;
43 public void writeExternal(final ObjectOutput out) throws IOException {
44 out.writeInt(snapshot.shardList.size());
45 for (String shard: snapshot.shardList) {
46 out.writeObject(shard);
51 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
52 int size = in.readInt();
53 List<String> localShardList = new ArrayList<>(size);
54 for (int i = 0; i < size; i++) {
55 localShardList.add((String) in.readObject());
58 snapshot = new ShardManagerSnapshot(localShardList);
61 private Object readResolve() {
66 private static final long serialVersionUID = 1L;
68 private final List<String> shardList;
70 public ShardManagerSnapshot(final @NonNull List<String> shardList) {
71 this.shardList = ImmutableList.copyOf(shardList);
74 public List<String> getShardList() {
78 private Object writeReplace() {
79 return new Proxy(this);
83 public String toString() {
84 return "ShardManagerSnapshot [ShardList = " + shardList + " ]";