NormalizedNodeAggregator should also report empty
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / ShardDataTreeSnapshotMetadata.java
1 /*
2  * Copyright (c) 2016 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.persisted;
9
10 import static com.google.common.base.Verify.verifyNotNull;
11
12 import java.io.Externalizable;
13 import java.io.Serializable;
14 import org.eclipse.jdt.annotation.NonNull;
15
16 /**
17  * Base class for various bits of metadata attached to a {@link MetadataShardDataTreeSnapshot}. This class is not
18  * an interface because we want to make sure all subclasses implement the externalizable proxy pattern, for which
19  * we need to force {@link #writeReplace()} to be abstract. We do that by making it final and exposing a protected
20  * {@link #externalizableProxy()} method.
21  *
22  * <p>
23  * All concrete subclasses of this class should be final so as to form a distinct set of possible metadata. Since
24  * metadata is serialized along with {@link MetadataShardDataTreeSnapshot}, this set is part of the serialization format
25  * guarded by {@link PayloadVersion}.
26  *
27  * <p>
28  * If a new metadata type is introduced or a type is removed, {@link PayloadVersion} needs to be bumped to ensure
29  * compatibility.
30  *
31  * @author Robert Varga
32  */
33 public abstract class ShardDataTreeSnapshotMetadata<T extends ShardDataTreeSnapshotMetadata<T>>
34         implements Serializable {
35     private static final long serialVersionUID = 1L;
36
37     ShardDataTreeSnapshotMetadata() {
38         // Prevent subclassing from outside of this package
39     }
40
41     final Object writeReplace() {
42         return verifyNotNull(externalizableProxy(), "Null externalizable proxy from %s", getClass());
43     }
44
45     /**
46      * Return an Externalizable proxy.
47      *
48      * @return Externalizable proxy, may not be null
49      */
50     protected abstract @NonNull Externalizable externalizableProxy();
51
52     public abstract Class<T> getType();
53 }