Merge branch 'master' of github.com:jboner/akka
This commit is contained in:
commit
eb5a38cd69
46 changed files with 71 additions and 46 deletions
|
|
@ -5,25 +5,33 @@
|
||||||
package akka
|
package akka
|
||||||
|
|
||||||
import akka.actor.newUuid
|
import akka.actor.newUuid
|
||||||
|
|
||||||
import java.io.{StringWriter, PrintWriter}
|
|
||||||
import java.net.{InetAddress, UnknownHostException}
|
import java.net.{InetAddress, UnknownHostException}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Akka base Exception. Each Exception gets:
|
* Akka base Exception. Each Exception gets:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>a UUID for tracking purposes</li>
|
* <li>a uuid for tracking purposes</li>
|
||||||
* <li>a message including exception name, uuid, original message and the stacktrace</li>
|
* <li>toString that includes exception name, message, uuid, and the stacktrace</li>
|
||||||
* <li>a method 'log' that will log the exception once and only once</li>
|
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
||||||
*/
|
*/
|
||||||
@serializable abstract class AkkaException(message: String = "") extends {
|
class AkkaException(message: String = "") extends RuntimeException(message) with Serializable {
|
||||||
val exceptionName = getClass.getName
|
|
||||||
val uuid = "%s_%s".format(AkkaException.hostname, newUuid)
|
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 {
|
object AkkaException {
|
||||||
|
|
|
||||||
|
|
@ -116,18 +116,18 @@ class ExecutorBasedEventDrivenDispatcher(
|
||||||
override def mailboxSize(actorRef: ActorRef) = getMailbox(actorRef).size
|
override def mailboxSize(actorRef: ActorRef) = getMailbox(actorRef).size
|
||||||
|
|
||||||
def createMailbox(actorRef: ActorRef): AnyRef = mailboxType match {
|
def createMailbox(actorRef: ActorRef): AnyRef = mailboxType match {
|
||||||
case b: UnboundedMailbox if b.blocking =>
|
case b: UnboundedMailbox =>
|
||||||
new DefaultUnboundedMessageQueue(true) with ExecutableMailbox {
|
if (b.blocking) {
|
||||||
final def dispatcher = ExecutorBasedEventDrivenDispatcher.this
|
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 =>
|
case b: BoundedMailbox =>
|
||||||
new DefaultBoundedMessageQueue(b.capacity, b.pushTimeOut, b.blocking) with ExecutableMailbox {
|
new DefaultBoundedMessageQueue(b.capacity, b.pushTimeOut, b.blocking) with ExecutableMailbox {
|
||||||
final def dispatcher = ExecutorBasedEventDrivenDispatcher.this
|
final def dispatcher = ExecutorBasedEventDrivenDispatcher.this
|
||||||
|
|
|
||||||
|
|
@ -95,14 +95,14 @@ class ClientInitiatedRemoteActorSpec extends AkkaRemoteTest {
|
||||||
|
|
||||||
"shouldSendBangBangMessageAndReceiveReply" in {
|
"shouldSendBangBangMessageAndReceiveReply" in {
|
||||||
val actor = remote.actorOf[RemoteActorSpecActorBidirectional](host,port).start
|
val actor = remote.actorOf[RemoteActorSpecActorBidirectional](host,port).start
|
||||||
val result = actor !! "Hello"
|
val result = actor !! ("Hello", 10000)
|
||||||
"World" must equal (result.get.asInstanceOf[String])
|
"World" must equal (result.get.asInstanceOf[String])
|
||||||
actor.stop
|
actor.stop
|
||||||
}
|
}
|
||||||
|
|
||||||
"shouldSendBangBangMessageAndReceiveReplyConcurrently" in {
|
"shouldSendBangBangMessageAndReceiveReplyConcurrently" in {
|
||||||
val actors = (1 to 10).map(num => { remote.actorOf[RemoteActorSpecActorBidirectional](host,port).start }).toList
|
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)
|
"World" must equal (future.await.result.asInstanceOf[Option[String]].get)
|
||||||
}
|
}
|
||||||
actors.foreach(_.stop)
|
actors.foreach(_.stop)
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,18 @@
|
||||||
|
|
||||||
package akka.tutorial.java.first;
|
package akka.tutorial.java.first;
|
||||||
|
|
||||||
import akka.actor.*;
|
import static akka.actor.Actors.actorOf;
|
||||||
import static akka.actor.Actors.*;
|
import static akka.actor.Actors.poisonPill;
|
||||||
|
|
||||||
import akka.routing.*;
|
|
||||||
import static akka.routing.Routing.Broadcast;
|
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
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;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -80,7 +85,7 @@ public class Pi {
|
||||||
|
|
||||||
// define the work
|
// define the work
|
||||||
private double calculatePiFor(int arg, int nrOfElements) {
|
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++) {
|
for (int i = arg * nrOfElements; i <= ((arg + 1) * nrOfElements - 1); i++) {
|
||||||
acc += 4 * Math.pow(-1, i) / (2 * i + 1);
|
acc += 4 * Math.pow(-1, i) / (2 * i + 1);
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +95,7 @@ public class Pi {
|
||||||
// message handler
|
// message handler
|
||||||
public void onReceive(Object message) {
|
public void onReceive(Object message) {
|
||||||
if (message instanceof Work) {
|
if (message instanceof Work) {
|
||||||
Work work = (Work)message;
|
Work work = (Work) message;
|
||||||
getContext().replyUnsafe(new Result(calculatePiFor(work.getArg(), work.getNrOfElements()))); // perform the work
|
getContext().replyUnsafe(new Result(calculatePiFor(work.getArg(), work.getNrOfElements()))); // perform the work
|
||||||
} else throw new IllegalArgumentException("Unknown message [" + message + "]");
|
} else throw new IllegalArgumentException("Unknown message [" + message + "]");
|
||||||
}
|
}
|
||||||
|
|
@ -100,7 +105,6 @@ public class Pi {
|
||||||
// ===== Master =====
|
// ===== Master =====
|
||||||
// ==================
|
// ==================
|
||||||
static class Master extends UntypedActor {
|
static class Master extends UntypedActor {
|
||||||
private final int nrOfWorkers;
|
|
||||||
private final int nrOfMessages;
|
private final int nrOfMessages;
|
||||||
private final int nrOfElements;
|
private final int nrOfElements;
|
||||||
private final CountDownLatch latch;
|
private final CountDownLatch latch;
|
||||||
|
|
@ -124,7 +128,6 @@ public class Pi {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Master(int nrOfWorkers, int nrOfMessages, int nrOfElements, CountDownLatch latch) {
|
public Master(int nrOfWorkers, int nrOfMessages, int nrOfElements, CountDownLatch latch) {
|
||||||
this.nrOfWorkers = nrOfWorkers;
|
|
||||||
this.nrOfMessages = nrOfMessages;
|
this.nrOfMessages = nrOfMessages;
|
||||||
this.nrOfElements = nrOfElements;
|
this.nrOfElements = nrOfElements;
|
||||||
this.latch = latch;
|
this.latch = latch;
|
||||||
|
|
@ -161,7 +164,7 @@ public class Pi {
|
||||||
} else if (message instanceof Result) {
|
} else if (message instanceof Result) {
|
||||||
|
|
||||||
// handle result from the worker
|
// handle result from the worker
|
||||||
Result result = (Result)message;
|
Result result = (Result) message;
|
||||||
pi += result.getValue();
|
pi += result.getValue();
|
||||||
nrOfResults += 1;
|
nrOfResults += 1;
|
||||||
if (nrOfResults == nrOfMessages) getContext().stop();
|
if (nrOfResults == nrOfMessages) getContext().stop();
|
||||||
|
|
|
||||||
|
|
@ -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_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_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_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_http = project("akka-http", "akka-http", new AkkaHttpProject(_), akka_actor)
|
||||||
lazy val akka_samples = project("akka-samples", "akka-samples", new AkkaSamplesParentProject(_))
|
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_slf4j = project("akka-slf4j", "akka-slf4j", new AkkaSlf4jProject(_), akka_actor)
|
||||||
lazy val akka_tutorials = project("akka-tutorials", "akka-tutorials", new AkkaTutorialsParentProject(_), 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) {
|
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")
|
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)
|
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
|
// akka-slf4j subproject
|
||||||
// -------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,15 @@
|
||||||
#!/bin/bash
|
#!/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
|
set -o errexit
|
||||||
|
|
||||||
# Author: David Underhill
|
# Author: David Underhill
|
||||||
|
|
@ -7,7 +18,7 @@ set -o errexit
|
||||||
# you want to delete, e.g., git-delete-history path1 path2
|
# you want to delete, e.g., git-delete-history path1 path2
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
exit 0are still
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# make sure we're at the root of git repo
|
# make sure we're at the root of git repo
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue