2009-08-17 20:46:05 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright 2007 WorldWide Conferencing, LLC
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
2010-05-21 08:18:56 +02:00
|
|
|
*
|
|
|
|
|
* Rework of David Pollak's ActorPing class in the Lift Project
|
|
|
|
|
* which is licensed under the Apache 2 License.
|
2009-08-17 20:46:05 +02:00
|
|
|
*/
|
2010-10-26 12:49:25 +02:00
|
|
|
package akka.actor
|
2009-08-17 18:42:41 +02:00
|
|
|
|
2011-07-11 15:21:29 +02:00
|
|
|
import java.util.concurrent._
|
2011-10-17 18:34:34 +02:00
|
|
|
import akka.util.Duration
|
2011-11-09 15:25:14 +01:00
|
|
|
import akka.AkkaException
|
2009-08-17 18:42:41 +02:00
|
|
|
|
2011-10-17 18:34:34 +02:00
|
|
|
case class SchedulerException(msg: String, e: Throwable) extends AkkaException(msg, e) {
|
|
|
|
|
def this(msg: String) = this(msg, null)
|
|
|
|
|
}
|
2010-05-21 20:08:49 +02:00
|
|
|
|
2011-10-17 18:34:34 +02:00
|
|
|
trait JScheduler {
|
2011-11-10 11:53:36 +01:00
|
|
|
def schedule(receiver: ActorRef, message: Any, initialDelay: Long, delay: Long, timeUnit: TimeUnit): Cancellable
|
|
|
|
|
def scheduleOnce(runnable: Runnable, delay: Long, timeUnit: TimeUnit): Cancellable
|
|
|
|
|
def scheduleOnce(receiver: ActorRef, message: Any, delay: Long, timeUnit: TimeUnit): Cancellable
|
2011-10-17 18:34:34 +02:00
|
|
|
}
|
2010-05-21 08:18:56 +02:00
|
|
|
|
2011-10-17 18:34:34 +02:00
|
|
|
abstract class Scheduler extends JScheduler {
|
2011-11-10 11:53:36 +01:00
|
|
|
def schedule(f: () ⇒ Unit, initialDelay: Long, delay: Long, timeUnit: TimeUnit): Cancellable
|
2011-10-17 18:34:34 +02:00
|
|
|
|
2011-11-10 11:53:36 +01:00
|
|
|
def scheduleOnce(f: () ⇒ Unit, delay: Long, timeUnit: TimeUnit): Cancellable
|
2011-10-17 18:34:34 +02:00
|
|
|
|
2011-11-10 11:53:36 +01:00
|
|
|
def schedule(receiver: ActorRef, message: Any, initialDelay: Duration, delay: Duration): Cancellable =
|
2011-10-17 18:34:34 +02:00
|
|
|
schedule(receiver, message, initialDelay.toNanos, delay.toNanos, TimeUnit.NANOSECONDS)
|
|
|
|
|
|
2011-11-10 11:53:36 +01:00
|
|
|
def schedule(f: () ⇒ Unit, initialDelay: Duration, delay: Duration): Cancellable =
|
2011-10-17 18:34:34 +02:00
|
|
|
schedule(f, initialDelay.toNanos, delay.toNanos, TimeUnit.NANOSECONDS)
|
|
|
|
|
|
2011-11-10 11:53:36 +01:00
|
|
|
def scheduleOnce(receiver: ActorRef, message: Any, delay: Duration): Cancellable =
|
2011-10-17 18:34:34 +02:00
|
|
|
scheduleOnce(receiver, message, delay.length, delay.unit)
|
2010-08-06 17:13:31 +02:00
|
|
|
|
2011-11-10 11:53:36 +01:00
|
|
|
def scheduleOnce(f: () ⇒ Unit, delay: Duration): Cancellable =
|
2011-10-17 18:34:34 +02:00
|
|
|
scheduleOnce(f, delay.length, delay.unit)
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-10 11:53:36 +01:00
|
|
|
trait Cancellable {
|
|
|
|
|
def cancel(): Unit
|
|
|
|
|
|
|
|
|
|
def isCancelled: Boolean
|
2011-11-09 15:25:14 +01:00
|
|
|
}
|