Github user vanzin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1195#discussion_r14308906
  
    --- Diff: 
streaming/src/main/scala/org/apache/spark/streaming/receiver/BlockGenerator.scala
 ---
    @@ -134,9 +168,26 @@ private[streaming] class BlockGenerator(
         logError(message, t)
         listener.onError(message, t)
       }
    -  
    +
       private def pushBlock(block: Block) {
         listener.onPushBlock(block.id, block.buffer)
    +
    +    var callbackBufferOpt: Option[ArrayBuffer[Callback]] = None
    +    // Remove the buffer from the callbacks map. This must be synchronized 
to ensure no one else
    +    // is editing the buffer or the map at that time.
    +    synchronized {
    +      callbackBufferOpt = Option(callbacks.remove(block.id))
    +    }
    +
    +    // Call the callbacks
    +    callbackBufferOpt match {
    +      case Some(callbackBuffer) =>
    +        callbackBuffer.map(callback => {
    --- End diff --
    
    Using `map()` here is a little weird, and probably wasteful. Probably 
should use `foreach`.
    
    Also, you can make this nicer:
    
        callbackBufferOpt.foreach(cbList => cbList.foreach { cb =>
          cb.function(cb.arg)
          logDebug("blah")
          })
       
    (Previous comments about the Callback type notwithstanding. Also I'm never 
sure about what's the preferred syntax for the foreach argument - parentheses 
or braces.)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to