Fix followerDistributedDataStore tear down
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / CloseLocalHistoryPayload.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 com.google.common.io.ByteArrayDataOutput;
11 import com.google.common.io.ByteStreams;
12 import java.io.IOException;
13 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 /**
18  * Payload persisted when a local history is closed cleanly. It contains a {@link LocalHistoryIdentifier}.
19  *
20  * @author Robert Varga
21  */
22 public final class CloseLocalHistoryPayload extends AbstractIdentifiablePayload<LocalHistoryIdentifier> {
23     private static final Logger LOG = LoggerFactory.getLogger(CloseLocalHistoryPayload.class);
24     @java.io.Serial
25     private static final long serialVersionUID = 1L;
26     private static final int PROXY_SIZE = externalizableProxySize(CH::new);
27
28     CloseLocalHistoryPayload(final LocalHistoryIdentifier historyId, final byte[] serialized) {
29         super(historyId, serialized);
30     }
31
32     public static CloseLocalHistoryPayload create(final LocalHistoryIdentifier historyId,
33             final int initialSerializedBufferCapacity) {
34         final ByteArrayDataOutput out = ByteStreams.newDataOutput(initialSerializedBufferCapacity);
35         try {
36             historyId.writeTo(out);
37         } catch (IOException e) {
38             // This should never happen
39             LOG.error("Failed to serialize {}", historyId, e);
40             throw new IllegalStateException("Failed to serialize " + historyId, e);
41         }
42         return new CloseLocalHistoryPayload(historyId, out.toByteArray());
43     }
44
45     @Override
46     protected DH externalizableProxy(final byte[] serialized) {
47         return new DH(serialized);
48     }
49
50     @Override
51     protected int externalizableProxySize() {
52         return PROXY_SIZE;
53     }
54 }