2 * Copyright (c) 2015 Cisco 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;
10 import com.google.common.base.Verify;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
14 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
15 import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshotMetadata;
17 abstract class ShardDataTreeMetadata<T extends ShardDataTreeSnapshotMetadata<T>> {
19 * Apply a recovered metadata snapshot.
21 * @param snapshot Metadata snapshot
23 final void applySnapshot(final @NonNull ShardDataTreeSnapshotMetadata<?> snapshot) {
24 Verify.verify(getSupportedType().isInstance(snapshot), "Snapshot %s misrouted to handler of %s", snapshot,
26 doApplySnapshot(getSupportedType().cast(snapshot));
30 * Reset metadata to empty state.
32 abstract void reset();
35 * Apply a recovered metadata snapshot. This is not a public entrypoint, just an interface between the base class
38 * @param snapshot Metadata snapshot
40 abstract void doApplySnapshot(@NonNull T snapshot);
43 * Return the type of metadata snapshot this object supports.
45 * @return Metadata type
47 abstract @NonNull Class<T> getSupportedType();
50 * Take a snapshot of current metadata state.
52 * @return Metadata snapshot, or null if the metadata is empty.
54 abstract @Nullable T toSnapshot();
58 abstract void onTransactionAborted(TransactionIdentifier txId);
60 abstract void onTransactionCommitted(TransactionIdentifier txId);
62 abstract void onTransactionPurged(TransactionIdentifier txId);
64 abstract void onHistoryCreated(LocalHistoryIdentifier historyId);
66 abstract void onHistoryClosed(LocalHistoryIdentifier historyId);
68 abstract void onHistoryPurged(LocalHistoryIdentifier historyId);