2 * Copyright (c) 2015 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.messages;
10 import java.io.ByteArrayInputStream;
11 import java.io.IOException;
12 import java.io.ObjectInputStream;
13 import java.util.ArrayList;
14 import java.util.List;
15 import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot;
16 import org.opendaylight.controller.cluster.datastore.persisted.ShardManagerSnapshot;
17 import org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState;
18 import org.opendaylight.controller.cluster.raft.Snapshot;
19 import org.opendaylight.controller.cluster.raft.persisted.EmptyState;
22 * Stores a list of DatastoreSnapshot instances.
24 * @deprecated Use {@link org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshotList} instead.
27 public class DatastoreSnapshotList extends ArrayList<DatastoreSnapshot> {
28 private static final long serialVersionUID = 1L;
30 public DatastoreSnapshotList() {
33 public DatastoreSnapshotList(List<DatastoreSnapshot> snapshots) {
37 private Object readResolve() throws IOException, ClassNotFoundException {
38 List<org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot> snapshots =
39 new ArrayList<>(size());
40 for (DatastoreSnapshot legacy: this) {
41 snapshots.add(new org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot(
42 legacy.getType(), deserializeShardManagerSnapshot(legacy.getShardManagerSnapshot()),
43 fromLegacy(legacy.getShardSnapshots())));
46 return new org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshotList(snapshots);
49 private static org.opendaylight.controller.cluster.datastore.persisted.ShardManagerSnapshot
50 deserializeShardManagerSnapshot(byte [] bytes) throws IOException, ClassNotFoundException {
55 try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes))) {
56 return (ShardManagerSnapshot) ois.readObject();
60 private static List<org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot.ShardSnapshot>
61 fromLegacy(List<DatastoreSnapshot.ShardSnapshot> from) throws IOException, ClassNotFoundException {
62 List<org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot.ShardSnapshot> snapshots =
63 new ArrayList<>(from.size());
64 for (DatastoreSnapshot.ShardSnapshot legacy: from) {
65 snapshots.add(new org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot.ShardSnapshot(
66 legacy.getName(), deserializeShardSnapshot(legacy.getSnapshot())));
72 private static org.opendaylight.controller.cluster.raft.persisted.Snapshot deserializeShardSnapshot(byte[] bytes)
73 throws IOException, ClassNotFoundException {
74 try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes))) {
75 Snapshot legacy = (Snapshot) ois.readObject();
77 org.opendaylight.controller.cluster.raft.persisted.Snapshot.State state = EmptyState.INSTANCE;
78 if (legacy.getState().length > 0) {
79 state = new ShardSnapshotState(ShardDataTreeSnapshot.deserializePreCarbon(legacy.getState()));
82 return org.opendaylight.controller.cluster.raft.persisted.Snapshot.create(
83 state, legacy.getUnAppliedEntries(), legacy.getLastIndex(),
84 legacy.getLastTerm(), legacy.getLastAppliedIndex(), legacy.getLastAppliedTerm(),
85 legacy.getElectionTerm(), legacy.getElectionVotedFor(), legacy.getServerConfiguration());