This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Actor Implementation with Jetlang

No replies
Mike Rettig
Joined: 2009-06-14,
User offline. Last seen 42 years 45 weeks ago.
I implemented the basic Scala Actor functionality using Jetlang.  In a ~100 lines of code, I was able to create basic actors with the following features:
* Pattern Matching* Actors with Dedicated Threads * Actors using a thread pool* Out of Order Delivery* Request/Reply Support
Of course, there's more functionality available with scala actors, but I implemented the commonly used features.  The code isn't robust or idiomatic but it demonstrates how Jetlang and Scala can be integrated.
I also was able to improve upon the scala actor design in several ways
* Better performance* Identical syntax for threaded and pooled actors - traits are used to determine the backing implementation * More concise syntax
Example Actors
object PingActor extends JetlangActor with ThreadedFiber {
def act() = {
case Ping => PongActor ! Pong
}
} object PongActor extends JetlangActor with PooledFiber {
var count = 0

def act() = {
case Pong => {
count = count + 1;
if (count == 1000000)
JetlangPing.decrementLatch
else
sender ! Ping
}
}
} You can find the full source here: http://code.google.com/p/jetlang/source/browse/#svn/scala

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland