Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@Typed package org.mbte.akkatest
import se.scalablesolutions.akka.actor.*
import java.util.concurrent.TimeUnit
import java.util.concurrent.CountDownLatch
import se.scalablesolutions.akka.config.JavaConfig.AllForOne
import se.scalablesolutions.akka.config.JavaConfig.RestartStrategy
import se.scalablesolutions.akka.config.ScalaConfig.Server
class Akka {
static ActorRef actor(Function1 handler) {
UntypedActor.actorOf{{ msg -> handler(msg) }}
}
static ActorRef leftShift(ActorRef ref, msg) {
ref.sendOneWay msg
ref
}
static Supervisor leftShift(Supervisor supervisor, ActorRef ref) {
supervisor.link ref
supervisor
}
static Supervisor supervisor(RestartStrategy restart, Server [] servers) {
SupervisorFactory.apply([restart.transform(), scala.collection.immutable.List.fromIterator(scala.collection.JavaConversions.asIterator(servers.toList().iterator()))]).newInstance()
}
}
def start = System.currentTimeMillis()
def supervisor = Akka.supervisor([new AllForOne(), 3, 5000])
ActorRef prev
int nMessages = 500
int nActors = 10000
CountDownLatch cdl = [nActors*nMessages]
for (i in 0..<nActors) {
prev = Akka.actor{ o ->
if(prev)
prev << o
cdl.countDown()
}.start()
supervisor << prev
}
for(i in 0..<nMessages)
prev << "Hi"
assert cdl.await(60,TimeUnit.SECONDS)
supervisor.shutdown()
println("${System.currentTimeMillis()-start}")
@alanland

This comment has been minimized.

Copy link

commented May 6, 2013

Is there a groovy version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.