Fixing tickets #816, #814, #817 and Dereks fixes on #812

This commit is contained in:
Viktor Klang 2011-04-28 16:01:11 +02:00
parent c61f1a42dc
commit 4bedb4813d
5 changed files with 47 additions and 19 deletions

View file

@ -88,24 +88,36 @@ trait MessageDispatcher {
private[akka] final def dispatchFuture[T](block: () => T, timeout: Long): Future[T] = {
futures.getAndIncrement()
val future = new DefaultCompletableFuture[T](timeout)
if (active.isOff) { active.switchOn { start } }
executeFuture(FutureInvocation[T](future, block, futureCleanup))
future
try {
val future = new DefaultCompletableFuture[T](timeout)
if (active.isOff)
guard withGuard { if (active.isOff) active.switchOn { start } }
executeFuture(FutureInvocation[T](future, block, futureCleanup))
future
} catch {
case e =>
futures.decrementAndGet
throw e
}
}
private val futureCleanup: () => Unit = { () =>
if (futures.decrementAndGet() == 0) guard withGuard { if (uuids.isEmpty) {
shutdownSchedule match {
case UNSCHEDULED =>
shutdownSchedule = SCHEDULED
Scheduler.scheduleOnce(shutdownAction, timeoutMs, TimeUnit.MILLISECONDS)
case SCHEDULED =>
shutdownSchedule = RESCHEDULED
case RESCHEDULED => //Already marked for reschedule
private val futureCleanup: () => Unit =
() => if (futures.decrementAndGet() == 0) {
guard withGuard {
if (futures.get == 0 && uuids.isEmpty) {
shutdownSchedule match {
case UNSCHEDULED =>
shutdownSchedule = SCHEDULED
Scheduler.scheduleOnce(shutdownAction, timeoutMs, TimeUnit.MILLISECONDS)
case SCHEDULED =>
shutdownSchedule = RESCHEDULED
case RESCHEDULED => //Already marked for reschedule
}
}
}
}}
}
}
private[akka] def register(actorRef: ActorRef) {
if (actorRef.mailbox eq null)