diff --git a/akka-actor/src/main/java/akka/actor/Actors.java b/akka-actor/src/main/java/akka/actor/Actors.java index 86b1484d05..a5ec9f37dc 100644 --- a/akka-actor/src/main/java/akka/actor/Actors.java +++ b/akka-actor/src/main/java/akka/actor/Actors.java @@ -70,7 +70,6 @@ public class Actors { return Actor$.MODULE$.actorOf(type); } - /** * The message that is sent when an Actor gets a receive timeout. *
@@ -83,4 +82,27 @@ public class Actors {
public final static ReceiveTimeout$ receiveTimeout() {
return ReceiveTimeout$.MODULE$;
}
-}
\ No newline at end of file
+
+ /**
+ * The message that when sent to an Actor kills it by throwing an exception.
+ *
+ * actor.sendOneWay(kill());
+ *
+ * @return the single instance of Kill
+ */
+ public final static Kill$ kill() {
+ return Kill$.MODULE$;
+ }
+
+
+ /**
+ * The message that when sent to an Actor shuts it down by calling 'stop'.
+ *
+ * actor.sendOneWay(poisonPill());
+ *
+ * @return the single instance of PoisonPill
+ */
+ public final static PoisonPill$ poisonPill() {
+ return PoisonPill$.MODULE$;
+ }
+}
diff --git a/akka-actor/src/main/scala/akka/AkkaException.scala b/akka-actor/src/main/scala/akka/AkkaException.scala
index e60d2c448c..748df1ced0 100644
--- a/akka-actor/src/main/scala/akka/AkkaException.scala
+++ b/akka-actor/src/main/scala/akka/AkkaException.scala
@@ -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:
* + * $ cd akka-1.1 + * $ export AKKA_HOME=`pwd` + * $ javac -cp dist/akka-actor-1.1-SNAPSHOT.jar:scala-library.jar akka/tutorial/java/first/Pi.java + * $ java -cp dist/akka-actor-1.1-SNAPSHOT.jar:scala-library.jar:. akka.tutorial.java.first.Pi + * $ ... + *+ * + * Run it in Maven: + *
+ * $ mvn + * > scala:console + * > val pi = new akka.tutorial.java.first.Pi + * > pi.calculate(4, 10000, 10000) + * > ... + *+ * + * @author Jonas Bonér + */ +public class Pi { + + public static void main(String[] args) throws Exception { + Pi pi = new Pi(); + pi.calculate(4, 10000, 10000); + } + + // ==================== + // ===== Messages ===== + // ==================== + static class Calculate {} + + static class Work { + private final int arg; + private final int nrOfElements; + + public Work(int arg, int nrOfElements) { + this.arg = arg; + this.nrOfElements = nrOfElements; + } + + public int getArg() { return arg; } + public int getNrOfElements() { return nrOfElements; } + } + + static class Result { + private final double value; + + public Result(double value) { + this.value = value; + } + + public double getValue() { return value; } + } + + // ================== + // ===== Worker ===== + // ================== + static class Worker extends UntypedActor { + + // define the work + private double calculatePiFor(int arg, int nrOfElements) { + double acc = 0.0D; + for (int i = arg * nrOfElements; i <= ((arg + 1) * nrOfElements - 1); i++) { + acc += 4 * Math.pow(-1, i) / (2 * i + 1); + } + return acc; + } + + // message handler + public void onReceive(Object message) { + if (message instanceof Work) { + Work work = (Work)message; + getContext().replyUnsafe(new Result(calculatePiFor(work.getArg(), work.getNrOfElements()))); // perform the work + } else throw new IllegalArgumentException("Unknown message [" + message + "]"); + } + } + + // ================== + // ===== Master ===== + // ================== + static class Master extends UntypedActor { + private final int nrOfWorkers; + private final int nrOfMessages; + private final int nrOfElements; + private final CountDownLatch latch; + + private double pi; + private int nrOfResults; + private long start; + + private ActorRef router; + + static class PiRouter extends UntypedLoadBalancer { + private final InfiniteIterator
+ * $ cd akka-1.1 + * $ export AKKA_HOME=`pwd` + * $ scalac -cp dist/akka-actor-1.1-SNAPSHOT.jar Pi.scala + * $ java -cp dist/akka-actor-1.1-SNAPSHOT.jar:scala-library.jar:. akka.tutorial.scala.first.Pi + * $ ... + *+ * * Run it in SBT: *
* $ sbt * > update * > console - * > akka.tutorial.sbt.pi.Pi.calculate + * > akka.tutorial.scala.first.Pi.calculate(nrOfWorkers = 4, nrOfElements = 10000, nrOfMessages = 10000) * > ... * > :quit ** * @author Jonas Bonér */ -object Pi { +object Pi extends App { + + calculate(nrOfWorkers = 4, nrOfElements = 10000, nrOfMessages = 10000) // ==================== // ===== Messages ===== @@ -48,7 +58,10 @@ object Pi { // define the work val calculatePiFor = (arg: Int, nrOfElements: Int) => { val range = (arg * nrOfElements) to ((arg + 1) * nrOfElements - 1) - range map (j => 4 * math.pow(-1, j) / (2 * j + 1)) sum + var acc = 0.0D + range foreach (i => acc += 4 * math.pow(-1, i) / (2 * i + 1)) + acc + //range map (j => 4 * math.pow(-1, j) / (2 * j + 1)) sum } def receive = { @@ -94,7 +107,7 @@ object Pi { override def postStop = { // tell the world that the calculation is complete - EventHandler.info(this, "\n\tPi estimate: \t\t%s\n\tCalculation time: \t%s millis".format(pi, (now - start))) + println("\n\tPi estimate: \t\t%s\n\tCalculation time: \t%s millis".format(pi, (now - start))) latch.countDown } } @@ -102,10 +115,7 @@ object Pi { // ================== // ===== Run it ===== // ================== - def calculate = { - val nrOfWorkers = 4 - val nrOfMessages = 10000 - val nrOfElements = 10000 + def calculate(nrOfWorkers: Int, nrOfElements: Int, nrOfMessages: Int) { // this latch is only plumbing to know when the calculation is completed val latch = new CountDownLatch(1) diff --git a/akka-tutorials/akka-tutorial-pi-sbt/project/build/Project.scala b/akka-tutorials/akka-tutorial-pi-sbt/project/build/Project.scala deleted file mode 100644 index 5c47e66970..0000000000 --- a/akka-tutorials/akka-tutorial-pi-sbt/project/build/Project.scala +++ /dev/null @@ -1,3 +0,0 @@ -import sbt._ - -class PiTutorialProject(info: ProjectInfo) extends DefaultProject(info) with AkkaProject diff --git a/akka-tutorials/akka-tutorial-pi-sbt/project/plugins/project/build.properties b/akka-tutorials/akka-tutorial-pi-sbt/project/plugins/project/build.properties deleted file mode 100644 index 1a423f3870..0000000000 --- a/akka-tutorials/akka-tutorial-pi-sbt/project/plugins/project/build.properties +++ /dev/null @@ -1,3 +0,0 @@ -#Project properties -#Fri Apr 01 14:48:23 CEST 2011 -plugin.uptodate=true diff --git a/akka-tutorials/akka-tutorial-second/project/build.properties b/akka-tutorials/akka-tutorial-second/project/build.properties new file mode 100644 index 0000000000..0441806bca --- /dev/null +++ b/akka-tutorials/akka-tutorial-second/project/build.properties @@ -0,0 +1,5 @@ +project.organization=se.scalablesolutions.akka +project.name=Akka Tutorial 1 SBT +project.version=1.0 +build.scala.versions=2.9.0.RC1 +sbt.version=0.7.6.RC0 diff --git a/akka-tutorials/akka-tutorial-second/project/plugins/Plugins.scala b/akka-tutorials/akka-tutorial-second/project/plugins/Plugins.scala new file mode 100644 index 0000000000..74a3d6b705 --- /dev/null +++ b/akka-tutorials/akka-tutorial-second/project/plugins/Plugins.scala @@ -0,0 +1,6 @@ +import sbt._ + +class Plugins(info: ProjectInfo) extends PluginDefinition(info) { + val akkaRepo = "Akka Repo" at "http://akka.io/repository" + val akkaPlugin = "se.scalablesolutions.akka" % "akka-sbt-plugin" % "1.1-SNAPSHOT" +} diff --git a/akka-tutorials/akka-tutorial-pi-sbt/src/main/scala/Pi2.scala b/akka-tutorials/akka-tutorial-second/src/main/scala/Pi.scala similarity index 83% rename from akka-tutorials/akka-tutorial-pi-sbt/src/main/scala/Pi2.scala rename to akka-tutorials/akka-tutorial-second/src/main/scala/Pi.scala index 7bbcba96d5..d183566b74 100644 --- a/akka-tutorials/akka-tutorial-pi-sbt/src/main/scala/Pi2.scala +++ b/akka-tutorials/akka-tutorial-second/src/main/scala/Pi.scala @@ -2,34 +2,46 @@ * Copyright (C) 2009-2011 Scalable Solutions AB
+ * $ cd akka-1.1 + * $ export AKKA_HOME=`pwd` + * $ scalac -cp dist/akka-actor-1.1-SNAPSHOT.jar Pi.scala + * $ java -cp dist/akka-actor-1.1-SNAPSHOT.jar:scala-library.jar:. akka.tutorial.second.Pi + * $ ... + *+ * * Run it in SBT: *
* $ sbt * > update * > console - * > akka.tutorial.sbt.pi.Pi.calculate + * > akka.tutorial.second.Pi.calculate(nrOfWorkers = 4, nrOfElements = 10000, nrOfMessages = 10000) * > ... * > :quit ** * @author Jonas Bonér */ -object Pi2 { +object Pi extends App { + + calculate(nrOfWorkers = 4, nrOfElements = 10000, nrOfMessages = 10000) // ==================== // ===== Messages ===== @@ -46,7 +58,10 @@ object Pi2 { // define the work val calculatePiFor = (arg: Int, nrOfElements: Int) => { val range = (arg * nrOfElements) to ((arg + 1) * nrOfElements - 1) - range map (j => 4 * math.pow(-1, j) / (2 * j + 1)) sum + var acc = 0.0D + range foreach (i => acc += 4 * math.pow(-1, i) / (2 * i + 1)) + acc + //range map (j => 4 * math.pow(-1, j) / (2 * j + 1)) sum } def receive = { @@ -124,8 +139,3 @@ object Pi2 { } } } - -// To be able to run it as a main application -object Main extends App { - Pi2.calculate(nrOfWorkers = 4, nrOfElements = 10000, nrOfMessages = 10000) -} diff --git a/akka-typed-actor/src/main/scala/akka/actor/TypedActor.scala b/akka-typed-actor/src/main/scala/akka/actor/TypedActor.scala index 8829d692e0..813c26ab94 100644 --- a/akka-typed-actor/src/main/scala/akka/actor/TypedActor.scala +++ b/akka-typed-actor/src/main/scala/akka/actor/TypedActor.scala @@ -966,10 +966,10 @@ private[akka] abstract class ActorAspect { else if (TypedActor.returnsFuture_?(methodRtti)) future.get else { if (future.isDefined) { - future.get.await.resultOrException match { - case s: Some[AnyRef] => s.get - case None => throw new IllegalActorStateException("No result returned from call to [" + joinPoint + "]") - } + future.get.await + val result = future.get.resultOrException + if (result.isDefined) result.get + else throw new IllegalActorStateException("No result returned from call to [" + joinPoint + "]") } else throw new IllegalActorStateException("No future returned from call to [" + joinPoint + "]") } } diff --git a/project/build/AkkaProject.scala b/project/build/AkkaProject.scala index 08c1a1506a..658ef1f44b 100644 --- a/project/build/AkkaProject.scala +++ b/project/build/AkkaProject.scala @@ -408,13 +408,18 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) { // Tutorials // ------------------------------------------------------------------------------------------------------------------- - class AkkaTutorialPiSbtProject(info: ProjectInfo) extends AkkaDefaultProject(info, deployPath) + class AkkaTutorialFirstProject(info: ProjectInfo) extends AkkaDefaultProject(info, deployPath) + + class AkkaTutorialSecondProject(info: ProjectInfo) extends AkkaDefaultProject(info, deployPath) class AkkaTutorialsParentProject(info: ProjectInfo) extends ParentProject(info) { override def disableCrossPaths = true - lazy val akka_tutorial_pi_sbt = project("akka-tutorial-pi-sbt", "akka-tutorial-pi-sbt", - new AkkaTutorialPiSbtProject(_), akka_actor) + lazy val akka_tutorial_first = project("akka-tutorial-first", "akka-tutorial-first", + new AkkaTutorialFirstProject(_), akka_actor) + + lazy val akka_tutorial_second = project("akka-tutorial-second", "akka-tutorial-second", + new AkkaTutorialSecondProject(_), akka_actor) lazy val publishRelease = { val releaseConfiguration = new DefaultPublishConfiguration(localReleaseRepository, "release", false) @@ -477,7 +482,7 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) { def akkaArtifacts = descendents(info.projectPath / "dist", "*-" + version + ".jar") // ------------------------------------------------------------ - class AkkaDefaultProject(info: ProjectInfo, val deployPath: Path) extends DefaultProject(info) + class AkkaDefaultProject(info: ProjectInfo, val deployPath: Path) extends DefaultProject(info) with DeployProject with OSGiProject with McPom { override def disableCrossPaths = true @@ -546,12 +551,12 @@ trait McPom { self: DefaultProject => case u => u + "/" } - val oldRepos = - (node \\ "project" \ "repositories" \ "repository").map { n => + val oldRepos = + (node \\ "project" \ "repositories" \ "repository").map { n => cleanUrl((n \ "url").text) -> (n \ "name").text }.toList - val newRepos = + val newRepos = mcs.filter(_.resolver.isInstanceOf[MavenRepository]).map { m => val r = m.resolver.asInstanceOf[MavenRepository] cleanUrl(r.root) -> r.name diff --git a/scripts/git-remove-history.sh b/scripts/git-remove-history.sh new file mode 100755 index 0000000000..5daf35f5c5 --- /dev/null +++ b/scripts/git-remove-history.sh @@ -0,0 +1,35 @@ +#!/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 +# Script to permanently delete files/folders from your git repository. To use +# it, cd to your repository's root and then run the script with a list of paths +# you want to delete, e.g., git-delete-history path1 path2 + +if [ $# -eq 0 ]; then + exit 0 +fi + +# make sure we're at the root of git repo +if [ ! -d .git ]; then + echo "Error: must run this script from the root of a git repository" + exit 1 +fi + +# remove all paths passed as arguments from the history of the repo +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