Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.biplob.thesis.streamReader;
- import java.io.BufferedReader;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction;
- import org.biplob.thesis.DataTypes.Point;
- public class DataStreamGenerator extends RichParallelSourceFunction<Point> {
- private String filePath;
- private float streamSpeed;
- private volatile boolean running = true;
- public DataStreamGenerator()
- {
- filePath = "default file location";
- streamSpeed = 1.0f;
- }
- public DataStreamGenerator(String filePath, float streamSpeed)
- {
- this.filePath = filePath;
- this.streamSpeed = streamSpeed;
- }
- public void run(SourceContext<Point> ctx) throws IOException
- {
- //read dataset
- String record;
- long timeStamp = System.nanoTime();
- FileInputStream fis = new FileInputStream(filePath);
- BufferedReader br = new BufferedReader(new InputStreamReader(fis));
- try
- {
- while((record = br.readLine())!= null && running == true)
- {
- RecordReader recordObject = RecordReader.parseRecord(record, timestamp);
- Point readPoint = new Point(recordObject.getItems());
- ctx.collect(readPoint);
- Thread.sleep(100);
- timestamp = System.nanoTime();
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- @Override
- public void cancel() {
- running = false;
- }
- }
Add Comment
Please, Sign In to add comment