2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.datastore.persisted;
10 import com.google.common.base.Verify;
11 import java.io.Externalizable;
12 import java.io.Serializable;
13 import javax.annotation.Nonnull;
16 * Base class for various bits of metadata attached to a {@link MetadataShardDataTreeSnapshot}. This class is not
17 * an interface because we want to make sure all subclasses implement the externalizable proxy pattern, for which
18 * we need to force {@link #writeReplace()} to be abstract. We do that by making it final and exposing a protected
19 * {@link #externalizableProxy()} method.
21 * All concrete subclasses of this class should be final so as to form a distinct set of possible metadata. Since
22 * metadata is serialized along with {@link MetadataShardDataTreeSnapshot}, this set is part of the serialization format
23 * guarded by {@link PayloadVersion}.
25 * If a new metadata type is introduced or a type is removed, {@link PayloadVersion} needs to be bumped to ensure
28 * @author Robert Varga
30 public abstract class ShardDataTreeSnapshotMetadata<T extends ShardDataTreeSnapshotMetadata<T>>
31 implements Serializable {
32 private static final long serialVersionUID = 1L;
34 ShardDataTreeSnapshotMetadata() {
35 // Prevent subclassing from outside of this package
38 final Object writeReplace() {
39 return Verify.verifyNotNull(externalizableProxy(), "Null externalizable proxy from %s", getClass());
43 * Return an Externalizable proxy.
45 * @return Externalizable proxy, may not be null
47 protected abstract @Nonnull Externalizable externalizableProxy();
49 public abstract Class<T> getType();