This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a groovy version?