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.DataInput;
13 import java.io.IOException;
14 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
19 * Payload persisted when a local history is created. It contains a {@link LocalHistoryIdentifier}.
21 * @author Robert Varga
23 public final class CreateLocalHistoryPayload extends AbstractIdentifiablePayload<LocalHistoryIdentifier> {
24 private static final class Proxy extends AbstractProxy<LocalHistoryIdentifier> {
25 private static final long serialVersionUID = 1L;
27 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
28 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
29 @SuppressWarnings("checkstyle:RedundantModifier")
34 Proxy(final byte[] serialized) {
39 protected LocalHistoryIdentifier readIdentifier(final DataInput in) throws IOException {
40 return LocalHistoryIdentifier.readFrom(in);
44 protected CreateLocalHistoryPayload createObject(final LocalHistoryIdentifier identifier,
45 final byte[] serialized) {
46 return new CreateLocalHistoryPayload(identifier, serialized);
50 private static final Logger LOG = LoggerFactory.getLogger(CreateLocalHistoryPayload.class);
51 private static final long serialVersionUID = 1L;
53 CreateLocalHistoryPayload(final LocalHistoryIdentifier historyId, final byte[] serialized) {
54 super(historyId, serialized);
57 public static CreateLocalHistoryPayload create(final LocalHistoryIdentifier historyId,
58 final int initialSerializedBufferCapacity) {
59 final ByteArrayDataOutput out = ByteStreams.newDataOutput(initialSerializedBufferCapacity);
61 historyId.writeTo(out);
62 } catch (IOException e) {
63 // This should never happen
64 LOG.error("Failed to serialize {}", historyId, e);
65 throw new RuntimeException("Failed to serialize " + historyId, e);
67 return new CreateLocalHistoryPayload(historyId, out.toByteArray());
71 protected Proxy externalizableProxy(final byte[] serialized) {
72 return new Proxy(serialized);