Skip to content

Commit

Permalink
Merge pull request #176 from dragos/issue/robust-worksheets-manager
Browse files Browse the repository at this point in the history
More robust WorksheetsManager: don't die on unhandled exceptions.
  • Loading branch information
dragos committed Feb 11, 2014
2 parents 825cf19 + 31f85c5 commit 4bba2e6
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import scala.tools.eclipse.logging.HasLogger
import scala.actors.AbstractActor
import org.eclipse.core.runtime.IPath
import scala.actors.UncaughtException
import scala.util.Try

object WorksheetsManager {
lazy val Instance: Actor = {
Expand Down Expand Up @@ -41,18 +42,28 @@ private class WorksheetsManager private extends DaemonActor with HasLogger {
eclipseLog.error("Evaluator actor crashed " + reason)
evictEvaluator(actor)

case any => exit("Unsupported message " + any)
case any =>
// don't shutdown, this is a singleton instance and won't be restarted
logger.info("Unsupported message " + any)
}
}

override def exceptionHandler = {
case e: Exception =>
logger.info("UncaughtException: ", e)
}

private def evictEvaluator(actor: AbstractActor) {
worksheetEvaluator = worksheetEvaluator filterNot { case (_, a) => a == actor }
}

private def forwardIfEvaluatorExists(msg: StopRun): Unit = {
val scalaProject = msg.unit.scalaProject
for (evaluator <- worksheetEvaluator.get(scalaProject.underlying.getFullPath))
evaluator forward msg
// if the project is closed, `unit.scalaProject` throws NoSuchElementException
// TODO: ScalaPlugin.asScalaProject probably shouldn't filter out closed projects.
for {
scalaProject <- Try(msg.unit.scalaProject)
evaluator <- worksheetEvaluator.get(scalaProject.underlying.getFullPath)
} evaluator forward msg
}

private def obtainEvaluator(unit: ScriptCompilationUnit): Actor = {
Expand Down

0 comments on commit 4bba2e6

Please sign in to comment.