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.ShardSnapshotState;
17 import org.opendaylight.controller.cluster.raft.Snapshot;
18 import org.opendaylight.controller.cluster.raft.persisted.EmptyState;
21 * Stores a list of DatastoreSnapshot instances.
23 * @deprecated Use {@link org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshotList} instead.
26 public class DatastoreSnapshotList extends ArrayList<DatastoreSnapshot> {
27 private static final long serialVersionUID = 1L;
29 public DatastoreSnapshotList() {
32 public DatastoreSnapshotList(List<DatastoreSnapshot> snapshots) {
36 private Object readResolve() throws IOException, ClassNotFoundException {
37 List<org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot> snapshots =
38 new ArrayList<>(size());
39 for (DatastoreSnapshot legacy: this) {
40 snapshots.add(new org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot(
41 legacy.getType(), legacy.getShardManagerSnapshot(), fromLegacy(legacy.getShardSnapshots())));
44 return new org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshotList(snapshots);
47 private static List<org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot.ShardSnapshot>
48 fromLegacy(List<DatastoreSnapshot.ShardSnapshot> from) throws IOException, ClassNotFoundException {
49 List<org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot.ShardSnapshot> snapshots =
50 new ArrayList<>(from.size());
51 for (DatastoreSnapshot.ShardSnapshot legacy: from) {
52 snapshots.add(new org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot.ShardSnapshot(
53 legacy.getName(), deserialize(legacy.getSnapshot())));
59 private static org.opendaylight.controller.cluster.raft.persisted.Snapshot deserialize(byte[] bytes)
60 throws IOException, ClassNotFoundException {
61 try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes))) {
62 Snapshot legacy = (Snapshot) ois.readObject();
64 org.opendaylight.controller.cluster.raft.persisted.Snapshot.State state = EmptyState.INSTANCE;
65 if (legacy.getState().length > 0) {
66 state = new ShardSnapshotState(ShardDataTreeSnapshot.deserializePreCarbon(legacy.getState()));
69 return org.opendaylight.controller.cluster.raft.persisted.Snapshot.create(
70 state, legacy.getUnAppliedEntries(), legacy.getLastIndex(),
71 legacy.getLastTerm(), legacy.getLastAppliedIndex(), legacy.getLastAppliedTerm(),
72 legacy.getElectionTerm(), legacy.getElectionVotedFor(), legacy.getServerConfiguration());