14 Oct 02:17
Actor and blocking IO calls
From: hemant <gethemant <at> gmail.com>
Subject: Actor and blocking IO calls
Newsgroups: gmane.comp.lang.scala
Date: 2008-10-14 00:20:47 GMT
Subject: Actor and blocking IO calls
Newsgroups: gmane.comp.lang.scala
Date: 2008-10-14 00:20:47 GMT
The arrangement:
* Master Actor which start a server on given port
* DataActor (handles, certain type, but not all, incoming requests)
act() of DataActor looks like following. Also, there will be
only one instance of DataActor for this app.
loop = {
receiveWithin(10) {
case data: Foo => processFoo(data)
case bar: Bar => processBar(data)
case _ => doSomeHouseKeeping()
}
}
def processFoo(data: Foo) = {
// processing of foo usually needs another Actor, just for this session
val fooActor = allFooActors.getOrElseUpdate(data.session,new
FooActor())
}
* FooActor:
loop = {
receiveWithin(10) {
case data: Foo => openBlockingChannelForFoo()
case Actor.stop => stopThis()
case _ => readFromBlockingChannel()
}
}
def openBlockingChannel() = //opens a HttpURLConnection, which may block
(Continue reading)
RSS Feed