All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nextbreakpoint.flink.dummies.SampledTemperatureSplitCheckpointSerializer Maven / Gradle / Ivy

There is a newer version: 0.0.6
Show newest version
/*
 * 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