- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Changes in 2.8 actors
Sun, 2009-05-31, 15:44
Hi all,
There has been a lot of discussion lately on the design and
implementation of Scala's actors. In order to address the issues that
people have raised, I did some redesign and major refactorings, which
are ready for the Scala 2.8 preview release (they are already available
in trunk).
Here is the change log:
- Added Reactor trait:
. It implements the `OutputChannel` trait, that is, it provides
implementations for `!`, `send`, `forward`, and `receiver`, but
not more than that. If linking is needed, a regular `Actor` must
be used.
. It implements pure event-based actors, that is, it only supports
`react` for receiving messages. The usual control-flow operators
(`loop`, `andThen`, etc.) are also available.
. Optionally, it ignores senders. If the `ignoreSender` fields is
set to true, `send` ignores its second argument. Moreover, the `!`
and `forward` methods do not require `Actor.self` to be available.
- The Reactor trait introduces the `exceptionHandler` member
(inherited by Actor). It returns a `PartialFunction[Exception,
Unit]`, which is used to handle exceptions that are thrown during
message processing. It works well together with control-flow
combinators such as `loop`: after the exception is handled, the
actor simply continues executing with the closure that the
combinator has registered as continuation. This means that in a
`loop`, the actor simply continues with the next iteration after
handling the exception. (Inside an `Actor` exceptions not handled by
`exceptionHandler` are propagated using links as usual.)
- Message sends can no longer fail, except if the system runs out of
resources (such as `OutOfMemoryError`). Exceptions that are thrown
during the search for matching messages no longer propagate to the
sender. Instead, they may be handled using the new
`exceptionHandler` method of the receiving Actor. This addresses
ticket #2010.
- The default scheduler used to execute Actors is based on
`java.util.concurrent.ThreadPoolExecutor`.
- Added `DaemonScheduler` for actors with daemon semantics (#2015).
- Tasks that execute Actors no longer catch `Throwable`, but
`Exception`.
- Renamed `Future.ch` to `Future.inputChannel`.
- Several other issues have been fixed: #1794, #1999, #2000, #2009,
#2012
In the process of the refactoring, I added a number of new test cases.
Also, a couple of memory leak tests were run successfully over night
(for example, see `test/long-running/jvm/memleak2_actor.scala`). My
intention is to add more long-running tests that are run regularly.
Feedback is welcome, of course.
Thanks,
Philipp
PS: I'll be at JavaOne next week, so I may not be able to respond
immediately.