Track skipped transactions
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ShardDataTreeMetadata.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore;
9
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;
16 import org.opendaylight.controller.cluster.datastore.utils.ImmutableUnsignedLongSet;
17
18 abstract class ShardDataTreeMetadata<T extends ShardDataTreeSnapshotMetadata<T>> {
19     /**
20      * Apply a recovered metadata snapshot.
21      *
22      * @param snapshot Metadata snapshot
23      */
24     final void applySnapshot(final @NonNull ShardDataTreeSnapshotMetadata<?> snapshot) {
25         Verify.verify(getSupportedType().isInstance(snapshot), "Snapshot %s misrouted to handler of %s", snapshot,
26             getSupportedType());
27         doApplySnapshot(getSupportedType().cast(snapshot));
28     }
29
30     /**
31      * Reset metadata to empty state.
32      */
33     abstract void reset();
34
35     /**
36      * Apply a recovered metadata snapshot. This is not a public entrypoint, just an interface between the base class
37      * and its subclasses.
38      *
39      * @param snapshot Metadata snapshot
40      */
41     abstract void doApplySnapshot(@NonNull T snapshot);
42
43     /**
44      * Return the type of metadata snapshot this object supports.
45      *
46      * @return Metadata type
47      */
48     abstract @NonNull Class<T> getSupportedType();
49
50     /**
51      * Take a snapshot of current metadata state.
52      *
53      * @return Metadata snapshot, or null if the metadata is empty.
54      */
55     abstract @Nullable T toSnapshot();
56
57     // Lifecycle events
58
59     abstract void onTransactionAborted(TransactionIdentifier txId);
60
61     abstract void onTransactionCommitted(TransactionIdentifier txId);
62
63     abstract void onTransactionPurged(TransactionIdentifier txId);
64
65     abstract void onTransactionsSkipped(LocalHistoryIdentifier historyId, ImmutableUnsignedLongSet txIds);
66
67     abstract void onHistoryCreated(LocalHistoryIdentifier historyId);
68
69     abstract void onHistoryClosed(LocalHistoryIdentifier historyId);
70
71     abstract void onHistoryPurged(LocalHistoryIdentifier historyId);
72
73 }