title: In Spark Streaming, is there a way to detect when a batch has finished?
body: <p>I use Spark 1.6.0 with Cloudera 5.8.3.<br>
  I have a <code>DStream</code> object and plenty of transformations defined on top of it,</p>
  
  <pre><code>val stream = KafkaUtils.createDirectStream[...](...)
  val mappedStream = stream.transform { ... }.map { ... }
  mappedStream.foreachRDD { ... }
  mappedStream.foreachRDD { ... }
  mappedStream.map { ... }.foreachRDD { ... }
  </code></pre>
  
  <p>Is there a way to register a last <code>foreachRDD</code> that is guaranteed to be executed last and only if the above <code>foreachRDD</code>s finished executing?<br>
  In other words, when the Spark UI shows that the job was complete - that's when I want to execute a lightweight function.  </p>
  
  <p>Is there something in the API that allows me to achieve that?</p>
  
  <p>Thanks</p>