Speed up DatastoreContextIntrospector a bit
[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
17 abstract class ShardDataTreeMetadata<T extends ShardDataTreeSnapshotMetadata<T>> {
18     /**
19      * Apply a recovered metadata snapshot.
20      *
21      * @param snapshot Metadata snapshot
22      */
23     final void applySnapshot(final @NonNull ShardDataTreeSnapshotMetadata<?> snapshot) {
24         Verify.verify(getSupportedType().isInstance(snapshot), "Snapshot %s misrouted to handler of %s", snapshot,
25             getSupportedType());
26         doApplySnapshot(getSupportedType().cast(snapshot));
27     }
28
29     /**
30      * Reset metadata to empty state.
31      */
32     abstract void reset();
33
34     /**
35      * Apply a recovered metadata snapshot. This is not a public entrypoint, just an interface between the base class
36      * and its subclasses.
37      *
38      * @param snapshot Metadata snapshot
39      */
40     abstract void doApplySnapshot(@NonNull T snapshot);
41
42     /**
43      * Return the type of metadata snapshot this object supports.
44      *
45      * @return Metadata type
46      */
47     abstract @NonNull Class<T> getSupportedType();
48
49     /**
50      * Take a snapshot of current metadata state.
51      *
52      * @return Metadata snapshot, or null if the metadata is empty.
53      */
54     abstract @Nullable T toSnapshot();
55
56     // Lifecycle events
57
58     abstract void onTransactionAborted(TransactionIdentifier txId);
59
60     abstract void onTransactionCommitted(TransactionIdentifier txId);
61
62     abstract void onTransactionPurged(TransactionIdentifier txId);
63
64     abstract void onHistoryCreated(LocalHistoryIdentifier historyId);
65
66     abstract void onHistoryClosed(LocalHistoryIdentifier historyId);
67
68     abstract void onHistoryPurged(LocalHistoryIdentifier historyId);
69
70 }