alpinegizmo commented on a change in pull request #40:
URL: https://github.com/apache/flink-training/pull/40#discussion_r701932435



##########
File path: 
common/src/main/java/org/apache/flink/training/exercises/common/sources/TaxiFareGenerator.java
##########
@@ -29,15 +33,25 @@
 public class TaxiFareGenerator implements SourceFunction<TaxiFare> {
 
     private volatile boolean running = true;
+    private Instant limitingTimestamp = Instant.MAX;
+
+    /** Create a bounded TaxiFareGenerator that runs only for the specified 
duration. */
+    public static TaxiFareGenerator runFor(Duration duration) {
+        TaxiFareGenerator generator = new TaxiFareGenerator();
+        generator.limitingTimestamp = DataGenerator.BEGINNING.plus(duration);
+        return generator;
+    }
 
     @Override
     public void run(SourceContext<TaxiFare> ctx) throws Exception {
 
         long id = 1;
+        Instant latestTimestamp = Instant.MIN;
 
-        while (running) {
+        while (running && (latestTimestamp.compareTo(limitingTimestamp) < 0)) {
             TaxiFare fare = new TaxiFare(id);
             id += 1;
+            latestTimestamp = fare.startTime;
 
             ctx.collect(fare);

Review comment:
       Thank you. That is cleaner, and works better in the tests.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to