Fix sonar warnings in sal-distributed-datastore
[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 javax.annotation.Nonnull;
12 import javax.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(@Nonnull final 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     @Nonnull
48     abstract 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     @Nullable
56     abstract T toSnapshot();
57
58     // Lifecycle events
59
60     abstract void onTransactionAborted(TransactionIdentifier txId);
61
62     abstract void onTransactionCommitted(TransactionIdentifier txId);
63
64     abstract void onTransactionPurged(TransactionIdentifier txId);
65
66     abstract void onHistoryCreated(LocalHistoryIdentifier historyId);
67
68     abstract void onHistoryClosed(LocalHistoryIdentifier historyId);
69
70     abstract void onHistoryPurged(LocalHistoryIdentifier historyId);
71
72 }