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-10-26 12:49:25 +02:00
|
|
|
package akka.actor
|
2009-08-17 18:42:41 +02:00
|
|
|
|
2011-10-17 18:34:34 +02:00
|
|
|
import akka.util.Duration
|
2011-12-13 01:44:18 +01:00
|
|
|
//#scheduler
|
2011-12-06 16:27:10 +01:00
|
|
|
/**
|
|
|
|
|
* An Akka scheduler service. This one needs one special behavior: if
|
|
|
|
|
* Closeable, it MUST execute all outstanding tasks upon .close() in order
|
|
|
|
|
* to properly shutdown all dispatchers.
|
|
|
|
|
*
|
|
|
|
|
* Furthermore, this timer service MUST throw IllegalStateException if it
|
|
|
|
|
* cannot schedule a task. Once scheduled, the task MUST be executed. If
|
|
|
|
|
* executed upon close(), the task may execute before its timeout.
|
|
|
|
|
*/
|
2011-11-23 11:07:16 +01:00
|
|
|
trait Scheduler {
|
2011-11-23 15:15:44 +01:00
|
|
|
/**
|
2011-12-15 14:26:17 +01:00
|
|
|
* Schedules a message to be sent repeatedly with an initial delay and
|
|
|
|
|
* frequency. E.g. if you would like a message to be sent immediately and
|
2012-01-18 13:26:11 +01:00
|
|
|
* thereafter every 500ms you would set delay=Duration.Zero and
|
|
|
|
|
* frequency=Duration(500, TimeUnit.MILLISECONDS)
|
2011-12-13 01:44:18 +01:00
|
|
|
*
|
|
|
|
|
* Java & Scala API
|
2011-11-23 15:15:44 +01:00
|
|
|
*/
|
2011-12-15 14:26:17 +01:00
|
|
|
def schedule(
|
|
|
|
|
initialDelay: Duration,
|
|
|
|
|
frequency: Duration,
|
|
|
|
|
receiver: ActorRef,
|
|
|
|
|
message: Any): Cancellable
|
2011-11-23 15:15:44 +01:00
|
|
|
|
|
|
|
|
/**
|
2011-12-15 14:26:17 +01:00
|
|
|
* Schedules a function to be run repeatedly with an initial delay and a
|
|
|
|
|
* frequency. E.g. if you would like the function to be run after 2 seconds
|
|
|
|
|
* and thereafter every 100ms you would set delay = Duration(2, TimeUnit.SECONDS)
|
|
|
|
|
* and frequency = Duration(100, TimeUnit.MILLISECONDS)
|
2011-12-13 01:44:18 +01:00
|
|
|
*
|
|
|
|
|
* Scala API
|
2011-11-23 15:15:44 +01:00
|
|
|
*/
|
2011-12-15 14:26:17 +01:00
|
|
|
def schedule(
|
|
|
|
|
initialDelay: Duration, frequency: Duration)(f: ⇒ Unit): Cancellable
|
2011-11-23 15:15:44 +01:00
|
|
|
|
2011-12-14 00:06:36 +01:00
|
|
|
/**
|
2011-12-15 14:26:17 +01:00
|
|
|
* Schedules a function to be run repeatedly with an initial delay and
|
|
|
|
|
* a frequency. E.g. if you would like the function to be run after 2
|
|
|
|
|
* seconds and thereafter every 100ms you would set delay = Duration(2,
|
|
|
|
|
* TimeUnit.SECONDS) and frequency = Duration(100, TimeUnit.MILLISECONDS)
|
2011-12-14 00:06:36 +01:00
|
|
|
*
|
|
|
|
|
* Java API
|
|
|
|
|
*/
|
2011-12-15 14:26:17 +01:00
|
|
|
def schedule(
|
|
|
|
|
initialDelay: Duration, frequency: Duration, runnable: Runnable): Cancellable
|
2011-12-14 00:06:36 +01:00
|
|
|
|
2011-11-23 15:15:44 +01:00
|
|
|
/**
|
2011-12-15 14:26:17 +01:00
|
|
|
* Schedules a Runnable to be run once with a delay, i.e. a time period that
|
|
|
|
|
* has to pass before the runnable is executed.
|
2011-12-13 01:44:18 +01:00
|
|
|
*
|
|
|
|
|
* Java & Scala API
|
2011-11-23 15:15:44 +01:00
|
|
|
*/
|
2011-12-02 17:13:46 +01:00
|
|
|
def scheduleOnce(delay: Duration, runnable: Runnable): Cancellable
|
2011-11-23 15:15:44 +01:00
|
|
|
|
|
|
|
|
/**
|
2011-12-15 14:26:17 +01:00
|
|
|
* Schedules a message to be sent once with a delay, i.e. a time period that has
|
|
|
|
|
* to pass before the message is sent.
|
2011-12-13 01:44:18 +01:00
|
|
|
*
|
|
|
|
|
* Java & Scala API
|
2011-11-23 15:15:44 +01:00
|
|
|
*/
|
2011-12-02 17:13:46 +01:00
|
|
|
def scheduleOnce(delay: Duration, receiver: ActorRef, message: Any): Cancellable
|
2011-11-23 15:15:44 +01:00
|
|
|
|
|
|
|
|
/**
|
2011-12-15 14:26:17 +01:00
|
|
|
* Schedules a function to be run once with a delay, i.e. a time period that has
|
|
|
|
|
* to pass before the function is run.
|
2011-12-13 01:44:18 +01:00
|
|
|
*
|
|
|
|
|
* Scala API
|
2011-11-23 15:15:44 +01:00
|
|
|
*/
|
2011-12-02 17:13:46 +01:00
|
|
|
def scheduleOnce(delay: Duration)(f: ⇒ Unit): Cancellable
|
2011-10-17 18:34:34 +02:00
|
|
|
}
|
2011-12-13 01:44:18 +01:00
|
|
|
//#scheduler
|
2011-10-17 18:34:34 +02:00
|
|
|
|
2011-12-13 01:44:18 +01:00
|
|
|
//#cancellable
|
|
|
|
|
/**
|
|
|
|
|
* Signifies something that can be cancelled
|
|
|
|
|
* There is no strict guarantee that the implementation is thread-safe,
|
|
|
|
|
* but it should be good practice to make it so.
|
|
|
|
|
*/
|
2011-11-10 11:53:36 +01:00
|
|
|
trait Cancellable {
|
2011-11-23 15:15:44 +01:00
|
|
|
/**
|
2011-12-13 01:44:18 +01:00
|
|
|
* Cancels this Cancellable
|
|
|
|
|
*
|
|
|
|
|
* Java & Scala API
|
2011-11-23 15:15:44 +01:00
|
|
|
*/
|
2011-11-10 11:53:36 +01:00
|
|
|
def cancel(): Unit
|
2011-11-23 15:15:44 +01:00
|
|
|
|
|
|
|
|
/**
|
2011-12-13 01:44:18 +01:00
|
|
|
* Returns whether this Cancellable has been cancelled
|
|
|
|
|
*
|
|
|
|
|
* Java & Scala API
|
2011-11-23 15:15:44 +01:00
|
|
|
*/
|
2011-11-10 11:53:36 +01:00
|
|
|
def isCancelled: Boolean
|
2011-12-13 01:44:18 +01:00
|
|
|
}
|
2011-12-15 14:26:17 +01:00
|
|
|
//#cancellable
|