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