BUG-5280: persist metadata in snaphots
[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.TransactionIdentifier;
14 import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshotMetadata;
15
16 abstract class ShardDataTreeMetadata<T extends ShardDataTreeSnapshotMetadata<T>> {
17     final void applySnapshot(@Nonnull final ShardDataTreeSnapshotMetadata<?> snapshot) {
18         Verify.verify(getSupportedType().isInstance(snapshot), "Snapshot %s misrouted to handler of %s", snapshot,
19             getSupportedType());
20         doApplySnapshot(getSupportedType().cast(snapshot));
21     }
22
23     abstract void reset();
24
25     abstract void doApplySnapshot(@Nonnull T snapshot);
26
27     abstract @Nonnull Class<T> getSupportedType();
28
29     abstract @Nullable T toStapshot();
30
31     // Lifecycle events
32     abstract void transactionCommitted(TransactionIdentifier txId);
33 }