summaryrefslogtreecommitdiff
path: root/src/actors
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2009-05-24 12:14:15 +0000
committerPhilipp Haller <hallerp@gmail.com>2009-05-24 12:14:15 +0000
commit54a706f3f652778a3119926105bcd01920a4680f (patch)
treecf11595523783f44e52b2982b1c2d54665c118a8 /src/actors
parent618fadfcfd9b9d295fb21c24df185e4216b89fe4 (diff)
downloadscala-54a706f3f652778a3119926105bcd01920a4680f.tar.gz
scala-54a706f3f652778a3119926105bcd01920a4680f.tar.bz2
scala-54a706f3f652778a3119926105bcd01920a4680f.zip
Fixed partest build problem.
Diffstat (limited to 'src/actors')
-rw-r--r--src/actors/scala/actors/DefaultExecutorScheduler.scala10
-rw-r--r--src/actors/scala/actors/ExecutorScheduler.scala22
-rw-r--r--src/actors/scala/actors/Scheduler.scala44
-rw-r--r--src/actors/scala/actors/SchedulerService.scala12
4 files changed, 62 insertions, 26 deletions
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 <code>ExecutorScheduler</code> 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 <code>Runnable</code> 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 <code>SchedulerService</code>
* 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 <code>FJTaskScheduler2</code>
- * and submits <code>tasks</code> for execution.
+ /** Shuts down the current scheduler and creates and starts a new scheduler.
+ *
+ * If the current scheduler is an <code>FJTaskScheduler2</code>
+ * a new scheduler of the same class is created. In that case,
+ * tasks resulting from a <code>snapshot</code> are
+ * submitted for execution.
+ *
+ * If the current scheduler is not an <code>FJTaskScheduler2</code>,
+ * a <code>DefaultExecutorScheduler</code> 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...")