Github user JoshRosen commented on a diff in the pull request: https://github.com/apache/spark/pull/3710#discussion_r22263766 --- Diff: streaming/src/main/scala/org/apache/spark/streaming/scheduler/StreamingListenerBus.scala --- @@ -64,36 +71,40 @@ private[spark] class StreamingListenerBus() extends Logging { } def addListener(listener: StreamingListener) { - listeners += listener + listeners.add(listener) } def post(event: StreamingListenerEvent) { + if (stopped) { + // Drop further events to make `StreamingListenerShutdown` be delivered ASAP + logError("StreamingListenerBus has been stopped! Drop " + event) + return + } val eventAdded = eventQueue.offer(event) - if (!eventAdded && !queueFullErrorMessageLogged) { + if (!eventAdded && queueFullErrorMessageLogged.compareAndSet(false, true)) { logError("Dropping StreamingListenerEvent because no remaining room in event queue. " + "This likely means one of the StreamingListeners is too slow and cannot keep up with the " + "rate at which events are being started by the scheduler.") - queueFullErrorMessageLogged = true } } - /** - * Waits until there are no more events in the queue, or until the specified time has elapsed. - * Used for testing only. Returns true if the queue has emptied and false is the specified time - * elapsed before the queue emptied. - */ - def waitUntilEmpty(timeoutMillis: Int): Boolean = { - val finishTime = System.currentTimeMillis + timeoutMillis - while (!eventQueue.isEmpty) { - if (System.currentTimeMillis > finishTime) { - return false + def stop(): Unit = { + stopped = true + // Should not call `post`, or `StreamingListenerShutdown` may be dropped. + eventQueue.put(StreamingListenerShutdown) + listenerThread.join() + } + + private def foreachListener(f: StreamingListener => Unit): Unit = { + val iter = listeners.iterator --- End diff -- If this change is to avoid an implicit Java -> Scala collections conversion, why not replace the `JavaConversions` implicits with the more explicit `JavaConverters` instead, so that you have to manually write `.asJava` or `.asScala`? That, in addition to a comment, would make it more obvious if we're re-introducing those conversions.
--- 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. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org