- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Actor Implementation with Jetlang
Sun, 2009-06-14, 20:39
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
* 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