Created
October 11, 2010 21:50
-
-
Save alextkachman/621300 to your computer and use it in GitHub Desktop.
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 scala.collection.immutable.List as ScalaList | |
import scala.collection.JavaConversions | |
import se.scalablesolutions.akka.config.ScalaConfig.Supervise | |
import se.scalablesolutions.akka.config.JavaConfig.LifeCycle | |
import se.scalablesolutions.akka.config.ScalaConfig.RemoteAddress | |
import se.scalablesolutions.akka.config.JavaConfig.Permanent | |
class Akka { | |
static ActorRef leftShift(ActorRef ref, msg) { | |
ref.sendOneWay msg | |
ref | |
} | |
static class JavaSupervise { | |
Supervise substiute | |
JavaSupervise (ActorRef actorRef, LifeCycle lifeCycle = new Permanent(), RemoteAddress remoteAddress = null) { | |
substiute = [actorRef, lifeCycle.transform(), remoteAddress] | |
} | |
} | |
static Supervisor supervisor(RestartStrategy restart, JavaSupervise [] servers) { | |
SupervisorFactory.apply([restart.transform(), servers*.substiute.toScalaList()]).newInstance() | |
} | |
static <T> ScalaList<T> toScalaList(T [] array) { | |
ScalaList.fromIterator(JavaConversions.asIterator(array.iterator())) | |
} | |
} | |
def start = System.currentTimeMillis() | |
int nMessages = 500 | |
int nActors = 10000 | |
CountDownLatch cdl = [nActors*nMessages] | |
def supervisor = Akka.supervisor( | |
[new AllForOne(), 3, 5000], | |
[UntypedActor.actorOf{{ msg -> | |
println msg | |
ActorRef prev | |
for (i in 0..<nActors) { | |
prev = UntypedActor.actorOf{{ o -> | |
if(prev) | |
prev << o | |
cdl.countDown() | |
}}.start() | |
context.supervisor.link prev | |
} | |
for(i in 0..<nMessages) | |
prev << "Hi" | |
}}] | |
) | |
supervisor.children().head() << "Start" | |
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