Skip to content
Snippets Groups Projects
Commit c590b339 authored by Manos Koukoutos's avatar Manos Koukoutos
Browse files

Fix ugliness in InterruptManager

parent 284bdf34
No related branches found
No related tags found
No related merge requests found
...@@ -5,36 +5,32 @@ package utils ...@@ -5,36 +5,32 @@ package utils
import scala.collection.JavaConversions._ import scala.collection.JavaConversions._
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.{AtomicLong, AtomicBoolean}
import sun.misc.{Signal, SignalHandler} import sun.misc.{Signal, SignalHandler}
import java.util.WeakHashMap import java.util.WeakHashMap
class InterruptManager(reporter: Reporter) extends Interruptible { class InterruptManager(reporter: Reporter) extends Interruptible {
private[this] val interruptibles = new WeakHashMap[Interruptible, Boolean]() private[this] val interruptibles = new WeakHashMap[Interruptible, Boolean]()
private[this] val sigINT = new Signal("INT") private[this] val sigINT = new Signal("INT")
private[this] val withinTimeout: AtomicBoolean = new AtomicBoolean(false)
private[this] val lastTimestamp = new AtomicLong(0L)
private val exitWindow = 1000L
private[this] val handler = new SignalHandler { private[this] val handler = new SignalHandler {
def handle(sig: Signal) { def handle(sig: Signal) {
println() def now(): Long = System.currentTimeMillis()
if (withinTimeout.get()) { reporter.info("")
if (now() - lastTimestamp.get < exitWindow) {
reporter.warning("Aborting Leon...") reporter.warning("Aborting Leon...")
System.exit(1) System.exit(1)
} }
else { else {
reporter.warning("Interrupted...") reporter.warning("Interrupted...")
setTimeout() lastTimestamp.set(now())
interrupt() interrupt()
} }
} }
} }
private val exitWindow = 1000
private[this] def setTimeout() = {
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
withinTimeout.set(true)
Future { Thread.sleep(exitWindow) } onComplete { _ => withinTimeout.set(false) }
()
}
val interrupted: AtomicBoolean = new AtomicBoolean(false) val interrupted: AtomicBoolean = new AtomicBoolean(false)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment