Merge branch 'master' of github.com:jboner/akka

This commit is contained in:
Jonas Bonér 2011-04-06 10:18:14 +02:00
commit eb5a38cd69
46 changed files with 71 additions and 46 deletions

View file

@ -5,25 +5,33 @@
package akka
import akka.actor.newUuid
import java.io.{StringWriter, PrintWriter}
import java.net.{InetAddress, UnknownHostException}
/**
* Akka base Exception. Each Exception gets:
* <ul>
* <li>a UUID for tracking purposes</li>
* <li>a message including exception name, uuid, original message and the stacktrace</li>
* <li>a method 'log' that will log the exception once and only once</li>
* <li>a uuid for tracking purposes</li>
* <li>toString that includes exception name, message, uuid, and the stacktrace</li>
* </ul>
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
@serializable abstract class AkkaException(message: String = "") extends {
val exceptionName = getClass.getName
class AkkaException(message: String = "") extends RuntimeException(message) with Serializable {
val uuid = "%s_%s".format(AkkaException.hostname, newUuid)
} with RuntimeException(message) {
override lazy val toString = "%s\n\t[%s]\n\t%s".format(exceptionName, uuid, message)
override lazy val toString = {
val name = getClass.getName
val trace = stackTraceToString
"%s: %s\n[%s]\n%s".format(name, message, uuid, trace)
}
def stackTraceToString = {
val trace = getStackTrace
val sb = new StringBuffer
for (i <- 0 until trace.length)
sb.append("\tat %s\n" format trace(i))
sb.toString
}
}
object AkkaException {

View file

@ -116,18 +116,18 @@ class ExecutorBasedEventDrivenDispatcher(
override def mailboxSize(actorRef: ActorRef) = getMailbox(actorRef).size
def createMailbox(actorRef: ActorRef): AnyRef = mailboxType match {
case b: UnboundedMailbox if b.blocking =>
new DefaultUnboundedMessageQueue(true) with ExecutableMailbox {
final def dispatcher = ExecutorBasedEventDrivenDispatcher.this
case b: UnboundedMailbox =>
if (b.blocking) {
new DefaultUnboundedMessageQueue(true) with ExecutableMailbox {
final def dispatcher = ExecutorBasedEventDrivenDispatcher.this
}
} else { //If we have an unbounded, non-blocking mailbox, we can go lockless
new ConcurrentLinkedQueue[MessageInvocation] with MessageQueue with ExecutableMailbox {
final def dispatcher = ExecutorBasedEventDrivenDispatcher.this
final def enqueue(m: MessageInvocation) = this.add(m)
final def dequeue(): MessageInvocation = this.poll()
}
}
case b: UnboundedMailbox if !b.blocking => //If we have an unbounded, non-blocking mailbox, we can go lockless
new ConcurrentLinkedQueue[MessageInvocation] with MessageQueue with ExecutableMailbox {
final def dispatcher = ExecutorBasedEventDrivenDispatcher.this
final def enqueue(m: MessageInvocation) = this.add(m)
final def dequeue(): MessageInvocation = this.poll()
}
case b: BoundedMailbox =>
new DefaultBoundedMessageQueue(b.capacity, b.pushTimeOut, b.blocking) with ExecutableMailbox {
final def dispatcher = ExecutorBasedEventDrivenDispatcher.this

View file

@ -95,14 +95,14 @@ class ClientInitiatedRemoteActorSpec extends AkkaRemoteTest {
"shouldSendBangBangMessageAndReceiveReply" in {
val actor = remote.actorOf[RemoteActorSpecActorBidirectional](host,port).start
val result = actor !! "Hello"
val result = actor !! ("Hello", 10000)
"World" must equal (result.get.asInstanceOf[String])
actor.stop
}
"shouldSendBangBangMessageAndReceiveReplyConcurrently" in {
val actors = (1 to 10).map(num => { remote.actorOf[RemoteActorSpecActorBidirectional](host,port).start }).toList
actors.map(_ !!! "Hello") foreach { future =>
actors.map(_ !!! ("Hello", 10000)) foreach { future =>
"World" must equal (future.await.result.asInstanceOf[Option[String]].get)
}
actors.foreach(_.stop)

View file

@ -4,13 +4,18 @@
package akka.tutorial.java.first;
import akka.actor.*;
import static akka.actor.Actors.*;
import akka.routing.*;
import static akka.routing.Routing.Broadcast;
import static akka.actor.Actors.actorOf;
import static akka.actor.Actors.poisonPill;
import static java.util.Arrays.asList;
import akka.actor.ActorRef;
import akka.actor.UntypedActor;
import akka.actor.UntypedActorFactory;
import akka.routing.CyclicIterator;
import akka.routing.InfiniteIterator;
import akka.routing.Routing.Broadcast;
import akka.routing.UntypedLoadBalancer;
import java.util.concurrent.CountDownLatch;
/**
@ -80,7 +85,7 @@ public class Pi {
// define the work
private double calculatePiFor(int arg, int nrOfElements) {
double acc = 0.0D;
double acc = 0.0;
for (int i = arg * nrOfElements; i <= ((arg + 1) * nrOfElements - 1); i++) {
acc += 4 * Math.pow(-1, i) / (2 * i + 1);
}
@ -90,7 +95,7 @@ public class Pi {
// message handler
public void onReceive(Object message) {
if (message instanceof Work) {
Work work = (Work)message;
Work work = (Work) message;
getContext().replyUnsafe(new Result(calculatePiFor(work.getArg(), work.getNrOfElements()))); // perform the work
} else throw new IllegalArgumentException("Unknown message [" + message + "]");
}
@ -100,7 +105,6 @@ public class Pi {
// ===== Master =====
// ==================
static class Master extends UntypedActor {
private final int nrOfWorkers;
private final int nrOfMessages;
private final int nrOfElements;
private final CountDownLatch latch;
@ -124,7 +128,6 @@ public class Pi {
}
public Master(int nrOfWorkers, int nrOfMessages, int nrOfElements, CountDownLatch latch) {
this.nrOfWorkers = nrOfWorkers;
this.nrOfMessages = nrOfMessages;
this.nrOfElements = nrOfElements;
this.latch = latch;
@ -161,7 +164,7 @@ public class Pi {
} else if (message instanceof Result) {
// handle result from the worker
Result result = (Result)message;
Result result = (Result) message;
pi += result.getValue();
nrOfResults += 1;
if (nrOfResults == nrOfMessages) getContext().stop();

View file

@ -179,12 +179,13 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
// -------------------------------------------------------------------------------------------------------------------
lazy val akka_actor = project("akka-actor", "akka-actor", new AkkaActorProject(_))
lazy val akka_testkit = project("akka-testkit", "akka-testkit", new AkkaTestkitProject(_), akka_actor)
lazy val akka_actor_tests = project("akka-actor-tests", "akka-actor-tests", new AkkaActorTestsProject(_), akka_testkit)
lazy val akka_stm = project("akka-stm", "akka-stm", new AkkaStmProject(_), akka_actor)
lazy val akka_typed_actor = project("akka-typed-actor", "akka-typed-actor", new AkkaTypedActorProject(_), akka_stm)
lazy val akka_typed_actor = project("akka-typed-actor", "akka-typed-actor", new AkkaTypedActorProject(_), akka_stm, akka_actor_tests)
lazy val akka_remote = project("akka-remote", "akka-remote", new AkkaRemoteProject(_), akka_typed_actor)
lazy val akka_http = project("akka-http", "akka-http", new AkkaHttpProject(_), akka_actor)
lazy val akka_samples = project("akka-samples", "akka-samples", new AkkaSamplesParentProject(_))
lazy val akka_testkit = project("akka-testkit", "akka-testkit", new AkkaTestkitProject(_), akka_actor)
lazy val akka_slf4j = project("akka-slf4j", "akka-slf4j", new AkkaSlf4jProject(_), akka_actor)
lazy val akka_tutorials = project("akka-tutorials", "akka-tutorials", new AkkaTutorialsParentProject(_), akka_actor)
@ -287,16 +288,7 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
// -------------------------------------------------------------------------------------------------------------------
class AkkaActorProject(info: ProjectInfo) extends AkkaDefaultProject(info, distPath) {
// testing
val junit = Dependencies.junit
val scalatest = Dependencies.scalatest
val multiverse_test = Dependencies.multiverse_test // StandardLatch
override def bndExportPackage = super.bndExportPackage ++ Seq("com.eaio.*;version=3.2")
// some tests depend on testkit, so include that and make sure it's compiled
override def testClasspath = super.testClasspath +++ akka_testkit.path("target") / "classes"
override def testCompileAction = super.testCompileAction dependsOn (akka_testkit.compile)
}
// -------------------------------------------------------------------------------------------------------------------
@ -441,6 +433,17 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
class AkkaTestkitProject(info: ProjectInfo) extends AkkaDefaultProject(info, distPath)
// -------------------------------------------------------------------------------------------------------------------
// akka-actor-tests subproject
// -------------------------------------------------------------------------------------------------------------------
class AkkaActorTestsProject(info: ProjectInfo) extends AkkaDefaultProject(info, distPath) {
// testing
val junit = Dependencies.junit
val scalatest = Dependencies.scalatest
val multiverse_test = Dependencies.multiverse_test // StandardLatch
}
// -------------------------------------------------------------------------------------------------------------------
// akka-slf4j subproject
// -------------------------------------------------------------------------------------------------------------------

View file

@ -1,4 +1,15 @@
#!/bin/bash
cat <<'EOT'
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ This command rewrites GIT history like git-rebase. Beware never to rewrite @
@ trees which are already published, as that would deeply upset all cloning @
@ repos. For more details see 'git help rebase'. Tread carefully! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
EOT
read -p "I know what I am doing: " answer
test "$answer" = yes || exit 1
set -o errexit
# Author: David Underhill
@ -7,7 +18,7 @@ set -o errexit
# you want to delete, e.g., git-delete-history path1 path2
if [ $# -eq 0 ]; then
exit 0are still
exit 0
fi
# make sure we're at the root of git repo
@ -21,4 +32,4 @@ files=$@
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $files" HEAD
# remove the temporary history git-filter-branch otherwise leaves behind for a long time
rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune
rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune