From 54a706f3f652778a3119926105bcd01920a4680f Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Sun, 24 May 2009 12:14:15 +0000 Subject: Fixed partest build problem. --- .../scala/actors/DefaultExecutorScheduler.scala | 10 +++-- src/actors/scala/actors/ExecutorScheduler.scala | 22 +++++++++-- src/actors/scala/actors/Scheduler.scala | 44 ++++++++++++++++------ src/actors/scala/actors/SchedulerService.scala | 12 +++--- 4 files changed, 62 insertions(+), 26 deletions(-) (limited to 'src/actors') diff --git a/src/actors/scala/actors/DefaultExecutorScheduler.scala b/src/actors/scala/actors/DefaultExecutorScheduler.scala index 22da121bbc..71e405d975 100644 --- a/src/actors/scala/actors/DefaultExecutorScheduler.scala +++ b/src/actors/scala/actors/DefaultExecutorScheduler.scala @@ -23,7 +23,7 @@ import java.util.concurrent.{ThreadPoolExecutor, TimeUnit, LinkedBlockingQueue} * * @author Philipp Haller */ -class DefaultExecutorScheduler extends { +class DefaultExecutorScheduler extends ExecutorScheduler { private val rt = Runtime.getRuntime() private val minNumThreads = 4 @@ -69,6 +69,8 @@ class DefaultExecutorScheduler extends { 50L, TimeUnit.MILLISECONDS, workQueue) - } with ExecutorScheduler(threadPool) { - override val CHECK_FREQ = 50 - } + + executor = threadPool + + override val CHECK_FREQ = 50 +} diff --git a/src/actors/scala/actors/ExecutorScheduler.scala b/src/actors/scala/actors/ExecutorScheduler.scala index 98bd953118..4b4204543d 100644 --- a/src/actors/scala/actors/ExecutorScheduler.scala +++ b/src/actors/scala/actors/ExecutorScheduler.scala @@ -10,7 +10,7 @@ package scala.actors -import java.util.concurrent.ExecutorService +import java.util.concurrent.{ExecutorService, RejectedExecutionException} /** * The ExecutorScheduler class uses an @@ -18,14 +18,28 @@ import java.util.concurrent.ExecutorService * * @author Philipp Haller */ -class ExecutorScheduler(executor: ExecutorService) extends SchedulerService { +class ExecutorScheduler(var executor: ExecutorService) extends SchedulerService { + + /* This constructor (and the var above) is currently only used to work + * around a bug in scaladoc, which cannot deal with early initializers + * (to be used in subclasses such as DefaultExecutorScheduler) properly. + */ + def this() { + this(null) + } /** Submits a Runnable for execution. * * @param task the task to be executed */ - def execute(task: Runnable): Unit = - executor execute task + def execute(task: Runnable) { + try { + executor execute task + } catch { + case ree: RejectedExecutionException => + Debug.info("caught "+ree) + } + } /** This method is called when the SchedulerService * shuts down. diff --git a/src/actors/scala/actors/Scheduler.scala b/src/actors/scala/actors/Scheduler.scala index d16107fdb2..1d87c7a3c2 100644 --- a/src/actors/scala/actors/Scheduler.scala +++ b/src/actors/scala/actors/Scheduler.scala @@ -50,21 +50,41 @@ object Scheduler extends IScheduler { } else error("snapshot operation not supported.") - /* Creates an instance of class FJTaskScheduler2 - * and submits tasks for execution. + /** Shuts down the current scheduler and creates and starts a new scheduler. + * + * If the current scheduler is an FJTaskScheduler2 + * a new scheduler of the same class is created. In that case, + * tasks resulting from a snapshot are + * submitted for execution. + * + * If the current scheduler is not an FJTaskScheduler2, + * a DefaultExecutorScheduler is created. */ def restart(): Unit = synchronized { - sched = { - val s = new FJTaskScheduler2 - actorGC.setPendingCount(pendingCount) - s.start() - s - } - if (tasks != null) - while (!tasks.isEmpty()) { - sched.execute(tasks.take().asInstanceOf[FJTask]) + // 1. shut down current scheduler + sched.shutdown() + + // 2. create and start new scheduler + if (sched.isInstanceOf[FJTaskScheduler2]) { + sched = { + val s = new FJTaskScheduler2 + actorGC.setPendingCount(pendingCount) + s.start() + s + } + if (tasks != null) { + while (!tasks.isEmpty()) { + sched.execute(tasks.take().asInstanceOf[FJTask]) + } + tasks = null } - tasks = null + } else { + sched = { + val s = new DefaultExecutorScheduler + s.start() + s + } + } } def execute(task: Runnable) { diff --git a/src/actors/scala/actors/SchedulerService.scala b/src/actors/scala/actors/SchedulerService.scala index 7b0640896a..5c177ba233 100644 --- a/src/actors/scala/actors/SchedulerService.scala +++ b/src/actors/scala/actors/SchedulerService.scala @@ -53,22 +53,22 @@ abstract class SchedulerService(daemon: Boolean) extends Thread with IScheduler override def run() { try { - while (!terminating) { + while (true) { this.synchronized { try { wait(CHECK_FREQ) } catch { case _: InterruptedException => - if (terminating) throw new QuitException } + if (terminating) + throw new QuitException actorGC.gc() - if (actorGC.allTerminated) { + if (actorGC.allTerminated) throw new QuitException - } - } // sync - } // while (!terminating) + } + } } catch { case _: QuitException => Debug.info(this+": initiating shutdown...") -- cgit v1.2.3