com.nextbreakpoint.flink.dummies.SampledTemperatureSplitCheckpointSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.nextbreakpoint.flink.dummies Show documentation
Show all versions of com.nextbreakpoint.flink.dummies Show documentation
Collection of dummy jobs for Apache Flink
/*
* This file is part of Flink Dummies
* https://github.com/nextbreakpoint/flink-dummies
*/
package com.nextbreakpoint.flink.dummies;
import org.apache.flink.core.io.SimpleVersionedSerializer;
import org.apache.flink.core.memory.DataInputDeserializer;
import org.apache.flink.core.memory.DataOutputSerializer;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
public class SampledTemperatureSplitCheckpointSerializer implements SimpleVersionedSerializer> {
private static final int CURRENT_VERSION = 1;
@Override
public int getVersion() {
return CURRENT_VERSION;
}
@Override
public byte[] serialize(Collection checkpoint) throws IOException {
final int total = checkpoint.stream().mapToInt(split -> split.getSensors().size()).sum();
final DataOutputSerializer out = new DataOutputSerializer((8 + 4) * total + 4);
out.writeInt(checkpoint.size());
for (SampledTemperatureSplit split : checkpoint) {
SampledTemperatureSplitSerializer.serializeV1(out, split);
}
return out.getCopyOfBuffer();
}
@Override
public Collection deserialize(int version, byte[] bytes) throws IOException {
if (version != CURRENT_VERSION) {
throw new IOException("Unrecognized version: " + version);
}
final DataInputDeserializer in = new DataInputDeserializer(bytes);
final int num = in.readInt();
final ArrayList result = new ArrayList<>(num);
for (int remaining = num; remaining > 0; remaining--) {
result.add(SampledTemperatureSplitSerializer.deserializeV1(in));
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy