diff options
Diffstat (limited to 'src/compiler/scala/tools/util/Signallable.scala')
-rw-r--r-- | src/compiler/scala/tools/util/Signallable.scala | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/util/Signallable.scala b/src/compiler/scala/tools/util/Signallable.scala index 2979e196e3..af98bfac83 100644 --- a/src/compiler/scala/tools/util/Signallable.scala +++ b/src/compiler/scala/tools/util/Signallable.scala @@ -6,11 +6,17 @@ package scala.tools package util +import java.security.AccessControlException + /** A class for things which are signallable. */ abstract class Signallable[T] private (val signal: String, val description: String) { private var last: Option[T] = None - private def lastString = last filterNot (_ == ()) map (_.toString) getOrElse "" + private def lastString = last match { + case Some(()) => "" + case Some(x) => "" + x + case _ => "" + } /** The most recent result from the signal handler. */ def lastResult: Option[T] = last @@ -29,8 +35,9 @@ abstract class Signallable[T] private (val signal: String, val description: Stri object Signallable { /** Same as the other apply, but an open signal is found for you. */ - def apply[T](description: String)(body: => T): Signallable[T] = + def apply[T](description: String)(body: => T): Signallable[T] = wrap { apply(SignalManager.findOpenSignal().name, description)(body) + } /** Given a signal name, a description, and a handler body, this * registers a signal handler and returns the Signallable instance. @@ -38,16 +45,21 @@ object Signallable { * SignalManager.info(), or sending SIGINFO to the manager will * dump it to console. */ - def apply[T](signal: String, description: String)(body: => T): Signallable[T] = { - val result = new Signallable[T](signal, description) { - def onSignal(): T = { + def apply[T](signal: String, description: String)(body: => T): Signallable[T] = wrap { + val result = create[T](signal, description, body) + SignalManager.public(signal, description)(result.onSignal()) + result + } + + private def wrap[T](body: => Signallable[T]): Signallable[T] = + try body catch { case _: AccessControlException => null } + + private def create[T](signal: String, description: String, body: => T): Signallable[T] = + new Signallable[T](signal, description) { + def onSignal = { val result = body last = Some(result) result } } - SignalManager.public(signal, description)(result.onSignal()) - result - } } - |