Skip to content

Commit

Permalink
Add some logging when handling an operation times out
Browse files Browse the repository at this point in the history
The idea is to get more information for the error mentioned
in #101
  • Loading branch information
provegard committed May 17, 2019
1 parent 39ad5a4 commit f68708a
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import java.util.concurrent.{Executors, ThreadFactory}

import akka.actor.ActorSystem
import com.programmaticallyspeaking.ncd.infra.ExecutorProxy
import com.sun.jdi.event.EventQueue
import com.sun.jdi.event.{EventQueue, EventSet}
import com.sun.jdi.{VMDisconnectedException, VirtualMachine}
import org.slf4s.Logging

import scala.annotation.tailrec
import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.concurrent.{ExecutionContext, Future, Promise, TimeoutException}

class NashornDebuggerConnector(hostName: String, port: Int) extends Logging {
def connect(): Future[VirtualMachine] = {
Expand Down Expand Up @@ -72,6 +72,8 @@ class NashornDebugger(implicit executionContext: ExecutionContext) extends Loggi

// TODO: Daemon thread?
class NashornScriptHostInteractionThread(host: NashornScriptHost, initPromise: Promise[Unit]) extends Thread with Logging {
import scala.collection.JavaConverters._

override def run(): Unit = {
try {
host.initialize()
Expand All @@ -89,7 +91,18 @@ class NashornScriptHostInteractionThread(host: NashornScriptHost, initPromise: P

@tailrec
private def listenIndefinitely(queue: EventQueue): Unit = {
Option(queue.remove(1000)).foreach { es => host.handleOperation(NashornEventSet(es)) }
Option(queue.remove(1000)).foreach(handleOperation)
listenIndefinitely(queue)
}

private def handleOperation(es: EventSet): Unit = {
try {
host.handleOperation(NashornEventSet(es))
} catch {
case t: TimeoutException =>
val eventNames = es.asScala.toSeq.map(_.toString).mkString(", ")
log.warn(s"Timed out handling operation with the following events: $eventNames")
throw t
}
}
}

0 comments on commit f68708a

Please sign in to comment.