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



##########
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:
       This will actually put a TaxiFare on the output that has a timestamp 
later than `limitingTimestamp`. If you want to avoid this (not sure what the 
guarantees are that you want to provide), you can do something like this 
instead:
   ```suggestion
   
           while (running) {
               TaxiFare fare = new TaxiFare(id);
               if (fare.startTime.compareTo(limitingTimestamp) >= 0) {
                   break;
               }
   
               ++id;
               ctx.collect(fare);
   ```




-- 
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