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.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;
18 * Payload persisted when a local history is created. It contains a {@link LocalHistoryIdentifier}.
20 * @author Robert Varga
22 public final class CreateLocalHistoryPayload extends AbstractIdentifiablePayload<LocalHistoryIdentifier> {
23 private static final Logger LOG = LoggerFactory.getLogger(CreateLocalHistoryPayload.class);
25 private static final long serialVersionUID = 1L;
26 private static final int PROXY_SIZE = externalizableProxySize(CH::new);
28 CreateLocalHistoryPayload(final LocalHistoryIdentifier historyId, final byte[] serialized) {
29 super(historyId, serialized);
32 public static CreateLocalHistoryPayload create(final LocalHistoryIdentifier historyId,
33 final int initialSerializedBufferCapacity) {
34 final ByteArrayDataOutput out = ByteStreams.newDataOutput(initialSerializedBufferCapacity);
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);
42 return new CreateLocalHistoryPayload(historyId, out.toByteArray());
46 protected CH externalizableProxy(final byte[] serialized) {
47 return new CH(serialized);
51 protected int externalizableProxySize() {