com.nextbreakpoint.flink.dummies.SampledTemperatureSource 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.api.connector.source.*;
import org.apache.flink.api.connector.source.lib.util.IteratorSourceEnumerator;
import org.apache.flink.api.connector.source.lib.util.IteratorSourceReader;
import org.apache.flink.core.io.SimpleVersionedSerializer;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
/*
* See documentation:
* https://nightlies.apache.org/flink/flink-docs-release-1.20/docs/dev/datastream/sources/
*/
public class SampledTemperatureSource implements Source> {
private final int maxCount;
private final long maxDelay;
private final List sensors;
public SampledTemperatureSource(int maxCount, long maxDelay, List sensors) {
this.maxCount = maxCount;
this.maxDelay = maxDelay;
this.sensors = Objects.requireNonNull(sensors);
}
@Override
public Boundedness getBoundedness() {
return Boundedness.CONTINUOUS_UNBOUNDED;
}
@Override
public SplitEnumerator> createEnumerator(SplitEnumeratorContext splitEnumeratorContext) {
// TODO handle parallelism
final List splits = List.of(new SampledTemperatureSplit("1", maxCount, maxDelay, sensors));
return new IteratorSourceEnumerator<>(splitEnumeratorContext, splits);
}
@Override
public SplitEnumerator> restoreEnumerator(SplitEnumeratorContext splitEnumeratorContext, Collection checkpoint) {
return new IteratorSourceEnumerator<>(splitEnumeratorContext, checkpoint);
}
@Override
public SimpleVersionedSerializer getSplitSerializer() {
return new SampledTemperatureSplitSerializer();
}
@Override
public SimpleVersionedSerializer> getEnumeratorCheckpointSerializer() {
return new SampledTemperatureSplitCheckpointSerializer();
}
@Override
public SourceReader createReader(SourceReaderContext sourceReaderContext) {
return new IteratorSourceReader<>(sourceReaderContext);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy