Skip to content

Instantly share code, notes, and snippets.

@alextkachman
Created October 11, 2010 12:25
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alextkachman/620439 to your computer and use it in GitHub Desktop.
Save alextkachman/620439 to your computer and use it in GitHub Desktop.
@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
Copy link

alanland 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