*/
package org.opendaylight.controller.cluster.datastore.persisted;
-import com.google.common.base.Throwables;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
-import java.io.DataInput;
import java.io.IOException;
import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
import org.slf4j.Logger;
* @author Robert Varga
*/
public final class PurgeTransactionPayload extends AbstractIdentifiablePayload<TransactionIdentifier> {
- private static final class Proxy extends AbstractProxy<TransactionIdentifier> {
- private static final long serialVersionUID = 1L;
-
- // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
- // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
- @SuppressWarnings("checkstyle:RedundantModifier")
- public Proxy() {
- // For Externalizable
- }
-
- Proxy(final byte[] serialized) {
- super(serialized);
- }
-
- @Override
- protected TransactionIdentifier readIdentifier(final DataInput in) throws IOException {
- return TransactionIdentifier.readFrom(in);
- }
-
- @Override
- protected PurgeTransactionPayload createObject(final TransactionIdentifier identifier,
- final byte[] serialized) {
- return new PurgeTransactionPayload(identifier, serialized);
- }
- }
-
private static final Logger LOG = LoggerFactory.getLogger(PurgeTransactionPayload.class);
+ @java.io.Serial
private static final long serialVersionUID = 1L;
+ private static final int PROXY_SIZE = externalizableProxySize(PT::new);
PurgeTransactionPayload(final TransactionIdentifier transactionId, final byte[] serialized) {
super(transactionId, serialized);
}
- public static PurgeTransactionPayload create(final TransactionIdentifier transactionId) {
- final ByteArrayDataOutput out = ByteStreams.newDataOutput();
+ public static PurgeTransactionPayload create(final TransactionIdentifier transactionId,
+ final int initialSerializedBufferCapacity) {
+ final ByteArrayDataOutput out = ByteStreams.newDataOutput(initialSerializedBufferCapacity);
try {
transactionId.writeTo(out);
} catch (IOException e) {
// This should never happen
LOG.error("Failed to serialize {}", transactionId, e);
- throw Throwables.propagate(e);
+ throw new IllegalStateException("Failed to serialize " + transactionId, e);
}
return new PurgeTransactionPayload(transactionId, out.toByteArray());
}
@Override
- protected Proxy externalizableProxy(final byte[] serialized) {
- return new Proxy(serialized);
+ protected PT externalizableProxy(final byte[] serialized) {
+ return new PT(serialized);
+ }
+
+ @Override
+ protected int externalizableProxySize() {
+ return PROXY_SIZE;
}
}