├── Example_01
├── project
│ ├── plugins.sbt
│ └── build.properties
├── .idea
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── markdown-navigator
│ │ └── profiles_settings.xml
│ ├── scala_compiler.xml
│ ├── modules.xml
│ ├── libraries
│ │ ├── SBT__com_typesafe_config_1_3_0_jar.xml
│ │ ├── SBT__com_typesafe_akka_akka_actor_2_11_2_4_16_jar.xml
│ │ ├── SBT__org_scala_lang_modules_scala_java8_compat_2_11_0_7_0_jar.xml
│ │ └── SBT__org_scala_lang_scala_library_2_11_8_jar.xml
│ ├── compiler.xml
│ ├── sbt.xml
│ ├── modules
│ │ ├── example_01.iml
│ │ └── example_01-build.iml
│ └── misc.xml
├── build.sbt
└── src
│ └── main
│ └── scala
│ └── Example_01.scala
├── Example_02
├── project
│ ├── plugins.sbt
│ └── build.properties
├── .idea
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── markdown-navigator
│ │ └── profiles_settings.xml
│ ├── scala_compiler.xml
│ ├── modules.xml
│ ├── libraries
│ │ ├── SBT__com_typesafe_config_1_3_0_jar.xml
│ │ ├── SBT__com_typesafe_akka_akka_actor_2_11_2_4_16_jar.xml
│ │ ├── SBT__org_scala_lang_modules_scala_java8_compat_2_11_0_7_0_jar.xml
│ │ └── SBT__org_scala_lang_scala_library_2_11_8_jar.xml
│ ├── compiler.xml
│ ├── sbt.xml
│ ├── modules
│ │ ├── example_02.iml
│ │ └── example_02-build.iml
│ └── misc.xml
├── build.sbt
└── src
│ └── main
│ ├── resources
│ └── application.conf
│ └── scala
│ └── Example_02.scala
├── Example_03
├── project
│ ├── plugins.sbt
│ └── build.properties
├── .idea
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── markdown-navigator
│ │ └── profiles_settings.xml
│ ├── scala_compiler.xml
│ ├── modules.xml
│ ├── libraries
│ │ ├── SBT__com_typesafe_config_1_3_0_jar.xml
│ │ ├── SBT__org_scala_lang_scala_reflect_2_11_8_jar.xml
│ │ ├── SBT__org_scalactic_scalactic_2_11_3_0_0_jar.xml
│ │ ├── SBT__org_scalatest_scalatest_2_11_3_0_0_jar.xml
│ │ ├── SBT__com_typesafe_akka_akka_actor_2_11_2_4_16_jar.xml
│ │ ├── SBT__com_typesafe_akka_akka_testkit_2_11_2_4_16_jar.xml
│ │ ├── SBT__org_scala_lang_modules_scala_xml_2_11_1_0_5_jar.xml
│ │ ├── SBT__org_scala_lang_modules_scala_java8_compat_2_11_0_7_0_jar.xml
│ │ ├── SBT__org_scala_lang_modules_scala_parser_combinators_2_11_1_0_4_jar.xml
│ │ └── SBT__org_scala_lang_scala_library_2_11_8_jar.xml
│ ├── compiler.xml
│ ├── sbt.xml
│ ├── modules
│ │ ├── example_03.iml
│ │ └── example_03-build.iml
│ └── misc.xml
├── build.sbt
└── src
│ ├── main
│ └── scala
│ │ ├── FaultHandlingDocSample.scala
│ │ ├── Counter.scala
│ │ ├── Storage.scala
│ │ ├── guardian
│ │ └── Guardian.scala
│ │ ├── Worker.scala
│ │ └── CounterService.scala
│ └── test
│ └── scala
│ └── guardian
│ └── GuardianSpec.scala
├── Example_04
├── project
│ ├── plugins.sbt
│ └── build.properties
├── .idea
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── dictionaries
│ │ └── panguansen.xml
│ ├── markdown-navigator
│ │ └── profiles_settings.xml
│ ├── scala_compiler.xml
│ ├── modules.xml
│ ├── compiler.xml
│ ├── sbt.xml
│ ├── libraries
│ │ └── SBT__org_scala_lang_scala_library_2_11_8_jar.xml
│ ├── modules
│ │ ├── example_04.iml
│ │ └── example_04-build.iml
│ └── misc.xml
├── build.sbt
└── src
│ └── main
│ ├── java
│ └── futures
│ │ ├── CallableTask.java
│ │ └── Test.java
│ └── scala
│ └── futures
│ ├── FutureSequence.scala
│ ├── FutureFlatMap.scala
│ ├── TestScalaFuture.scala
│ ├── FutureTraverse.scala
│ ├── FutureForYield.scala
│ ├── FutureAwait.scala
│ └── FutureReduce.scala
├── Example_05
├── project
│ ├── plugins.sbt
│ └── build.properties
├── build.sbt
└── src
│ └── main
│ ├── scala
│ ├── PersitienceQueryTest.scala
│ └── LotteryActor.scala
│ └── resources
│ └── application.conf
├── Example_06
├── project
│ ├── plugins.sbt
│ └── build.properties
├── remote
│ ├── project
│ │ └── build.properties
│ └── src
│ │ └── main
│ │ ├── java
│ │ ├── RemoteRmi.java
│ │ ├── JoinRmiEvt.java
│ │ ├── RemoteRmiImpl.java
│ │ └── RemoteRMIServer.java
│ │ ├── scala-2.11
│ │ ├── RemoteDemo.scala
│ │ └── RemoteActor.scala
│ │ └── resources
│ │ └── application.conf
├── src
│ └── main
│ │ └── scala
│ │ └── Test.scala
├── local
│ └── src
│ │ └── main
│ │ ├── java
│ │ ├── RemoteRmi.java
│ │ ├── JoinRmiEvt.java
│ │ └── RemoteRmiClient.java
│ │ ├── scala-2.11
│ │ ├── LocalDemo.scala
│ │ └── LocalActor.scala
│ │ └── resources
│ │ └── application.conf
└── build.sbt
├── Example_07
├── project
│ ├── plugins.sbt
│ └── build.properties
├── frontend
│ ├── project
│ │ └── build.properties
│ └── src
│ │ └── main
│ │ ├── scala-2.11
│ │ └── sample
│ │ │ └── cluster
│ │ │ └── transformation
│ │ │ └── frontend
│ │ │ ├── TransformationFrontendApp.scala
│ │ │ └── TransformationFrontend.scala
│ │ └── resources
│ │ └── application.conf
├── src
│ └── main
│ │ ├── scala-2.11
│ │ ├── Send.scala
│ │ ├── DemoClient.scala
│ │ └── ClientJobTransformationSendingActor.scala
│ │ └── resources
│ │ └── application.conf
├── Images.docx
├── common
│ └── src
│ │ └── main
│ │ └── scala-2.11
│ │ └── sample
│ │ └── cluster
│ │ └── transformation
│ │ └── TransformationMessages.scala
├── backend
│ └── src
│ │ └── main
│ │ ├── resources
│ │ └── application.conf
│ │ └── scala-2.11
│ │ └── sample
│ │ └── cluster
│ │ └── transformation
│ │ └── backend
│ │ ├── TransformationBackendApp.scala
│ │ └── TransformationBackend.scala
├── README.txt
└── build.sbt
├── .gitignore
└── README.md
/Example_01/project/plugins.sbt:
--------------------------------------------------------------------------------
1 | logLevel := Level.Warn
--------------------------------------------------------------------------------
/Example_02/project/plugins.sbt:
--------------------------------------------------------------------------------
1 | logLevel := Level.Warn
--------------------------------------------------------------------------------
/Example_03/project/plugins.sbt:
--------------------------------------------------------------------------------
1 | logLevel := Level.Warn
--------------------------------------------------------------------------------
/Example_04/project/plugins.sbt:
--------------------------------------------------------------------------------
1 | logLevel := Level.Warn
--------------------------------------------------------------------------------
/Example_05/project/plugins.sbt:
--------------------------------------------------------------------------------
1 | logLevel := Level.Warn
--------------------------------------------------------------------------------
/Example_06/project/plugins.sbt:
--------------------------------------------------------------------------------
1 | logLevel := Level.Warn
--------------------------------------------------------------------------------
/Example_07/project/plugins.sbt:
--------------------------------------------------------------------------------
1 | logLevel := Level.Warn
--------------------------------------------------------------------------------
/Example_01/project/build.properties:
--------------------------------------------------------------------------------
1 | sbt.version = 0.13.8
--------------------------------------------------------------------------------
/Example_02/project/build.properties:
--------------------------------------------------------------------------------
1 | sbt.version = 0.13.8
--------------------------------------------------------------------------------
/Example_03/project/build.properties:
--------------------------------------------------------------------------------
1 | sbt.version = 0.13.8
--------------------------------------------------------------------------------
/Example_04/project/build.properties:
--------------------------------------------------------------------------------
1 | sbt.version = 0.13.8
--------------------------------------------------------------------------------
/Example_05/project/build.properties:
--------------------------------------------------------------------------------
1 | sbt.version = 0.13.15
--------------------------------------------------------------------------------
/Example_06/project/build.properties:
--------------------------------------------------------------------------------
1 | sbt.version = 0.13.15
--------------------------------------------------------------------------------
/Example_07/project/build.properties:
--------------------------------------------------------------------------------
1 | sbt.version = 0.13.15
--------------------------------------------------------------------------------
/Example_06/remote/project/build.properties:
--------------------------------------------------------------------------------
1 | sbt.version=0.13.15
2 |
--------------------------------------------------------------------------------
/Example_07/frontend/project/build.properties:
--------------------------------------------------------------------------------
1 | sbt.version=0.13.15
2 |
--------------------------------------------------------------------------------
/Example_07/src/main/scala-2.11/Send.scala:
--------------------------------------------------------------------------------
1 | case class Send(count:Int)
2 |
--------------------------------------------------------------------------------
/Example_07/Images.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/godpan/akka-demo/HEAD/Example_07/Images.docx
--------------------------------------------------------------------------------
/Example_01/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Example_02/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Example_03/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Example_04/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Example_06/src/main/scala/Test.scala:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by panguansen on 17/8/9.
3 | */
4 | object Test extends App {
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/Example_04/.idea/dictionaries/panguansen.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Example_01/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Example_02/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Example_03/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Example_04/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Example_02/build.sbt:
--------------------------------------------------------------------------------
1 | name := "Example_02"
2 |
3 | scalaVersion := "2.11.8"
4 |
5 | val akkaVersion = "2.4.16"
6 |
7 | libraryDependencies +=
8 | "com.typesafe.akka" %% "akka-actor" % akkaVersion
9 |
10 |
--------------------------------------------------------------------------------
/Example_01/.idea/scala_compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Example_02/.idea/scala_compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Example_03/.idea/scala_compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Example_04/.idea/scala_compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Example_01/build.sbt:
--------------------------------------------------------------------------------
1 | name := "Example_01"
2 |
3 | version := "1.0"
4 |
5 | scalaVersion := "2.11.8"
6 |
7 | val akkaVersion = "2.4.16"
8 |
9 | libraryDependencies +=
10 | "com.typesafe.akka" %% "akka-actor" % akkaVersion
11 |
--------------------------------------------------------------------------------
/Example_04/build.sbt:
--------------------------------------------------------------------------------
1 | name := "Example_04"
2 |
3 | version := "1.0"
4 |
5 | scalaVersion := "2.11.8"
6 |
7 | //libraryDependencies += "junit" %% "junit" % "4.12"
8 | libraryDependencies += "org.scala-lang.modules" %% "scala-async" % "0.9.6"
9 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 | *.log
3 |
4 | # sbt specific
5 | .cache
6 | .history
7 | .lib/
8 | dist/*
9 | target/
10 | lib_managed/
11 | src_managed/
12 | project/boot/
13 | project/plugins/project/
14 | *.idea/
15 | # Scala-IDE specific
16 | .scala_dependencies
17 | .worksheet
18 |
--------------------------------------------------------------------------------
/Example_03/build.sbt:
--------------------------------------------------------------------------------
1 | name := "Example_03"
2 |
3 | version := "1.0"
4 |
5 | scalaVersion := "2.11.8"
6 |
7 | val akkaVersion = "2.4.16"
8 |
9 | libraryDependencies ++= Seq(
10 | "com.typesafe.akka" %% "akka-actor" % akkaVersion,
11 | "com.typesafe.akka" %% "akka-testkit" % akkaVersion,
12 | "org.scalatest" %% "scalatest" % "3.0.0"
13 | )
14 |
15 |
--------------------------------------------------------------------------------
/Example_07/common/src/main/scala-2.11/sample/cluster/transformation/TransformationMessages.scala:
--------------------------------------------------------------------------------
1 | package sample.cluster.transformation
2 |
3 | final case class TransformationJob(text: String) // 任务内容
4 | final case class TransformationResult(text: String) // 执行任务结果
5 | final case class JobFailed(reason: String, job: TransformationJob) //任务失败相应原因
6 | case object BackendRegistration // 后台具体执行任务节点注册事件
7 |
--------------------------------------------------------------------------------
/Example_06/local/src/main/java/RemoteRmi.java:
--------------------------------------------------------------------------------
1 | import java.rmi.Remote;
2 | import java.rmi.RemoteException;
3 |
4 | /**
5 | * Created by panguansen on 17/8/24.
6 | */
7 | public interface RemoteRmi extends Remote {
8 | public void sendNoReturn(String message) throws RemoteException, InterruptedException;
9 | public String sendHasReturn(JoinRmiEvt joinRmiEvt) throws RemoteException;
10 | }
11 |
--------------------------------------------------------------------------------
/Example_06/remote/src/main/java/RemoteRmi.java:
--------------------------------------------------------------------------------
1 | import java.rmi.Remote;
2 | import java.rmi.RemoteException;
3 |
4 | /**
5 | * Created by panguansen on 17/8/24.
6 | */
7 | public interface RemoteRmi extends Remote {
8 | public void sendNoReturn(String message) throws RemoteException, InterruptedException;
9 | public String sendHasReturn(JoinRmiEvt joinRmiEvt) throws RemoteException;
10 | }
11 |
--------------------------------------------------------------------------------
/Example_06/remote/src/main/scala-2.11/RemoteDemo.scala:
--------------------------------------------------------------------------------
1 | import akka.actor.{Props, ActorSystem}
2 |
3 | import scala.io.StdIn
4 |
5 | object RemoteDemo extends App {
6 | val system = ActorSystem("RemoteDemoSystem")
7 | val remoteActor = system.actorOf(Props[RemoteActor], name = "RemoteActor")
8 | remoteActor ! "The RemoteActor is alive"
9 | StdIn.readLine()
10 | system.terminate()
11 | StdIn.readLine()
12 | }
13 |
--------------------------------------------------------------------------------
/Example_06/remote/src/main/scala-2.11/RemoteActor.scala:
--------------------------------------------------------------------------------
1 | import akka.actor.Actor
2 |
3 | case class JoinEvt(
4 | id: Long,
5 | name: String
6 | )
7 |
8 | class RemoteActor extends Actor {
9 | def receive = {
10 | case j: JoinEvt => sender() ! s"the ${j.name} has Join"
11 | case msg: String =>
12 | println(s"RemoteActor received message '$msg'")
13 | sender ! "Hello from the RemoteActor"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Example_04/src/main/java/futures/CallableTask.java:
--------------------------------------------------------------------------------
1 | package futures;
2 |
3 | import java.util.concurrent.Callable;
4 |
5 | /**
6 | * Created by panguansen on 17/5/14.
7 | */
8 | public class CallableTask implements Callable{
9 | @Override
10 | public Object call() throws Exception {
11 | System.out.println("lalala");
12 | Thread.sleep(1000);
13 | throw new Exception("error");
14 | // return "hello world";
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Example_01/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Example_02/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Example_03/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Example_04/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Example_01/.idea/libraries/SBT__com_typesafe_config_1_3_0_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example_02/.idea/libraries/SBT__com_typesafe_config_1_3_0_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example_03/.idea/libraries/SBT__com_typesafe_config_1_3_0_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example_02/src/main/resources/application.conf:
--------------------------------------------------------------------------------
1 | akka {
2 |
3 | # Log level used by the configured loggers (see "loggers") as soon
4 | # as they have been started; before that, see "stdout-loglevel"
5 | # Options: OFF, ERROR, WARNING, INFO, DEBUG
6 | loglevel = "DEBUG"
7 |
8 | # Log level for the very basic logger activated during ActorSystem startup.
9 | # This logger prints the log messages to stdout (System.out).
10 | # Options: OFF, ERROR, WARNING, INFO, DEBUG
11 | stdout-loglevel = "INFO"
12 | }
--------------------------------------------------------------------------------
/Example_03/.idea/libraries/SBT__org_scala_lang_scala_reflect_2_11_8_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example_03/.idea/libraries/SBT__org_scalactic_scalactic_2_11_3_0_0_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example_03/.idea/libraries/SBT__org_scalatest_scalatest_2_11_3_0_0_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example_05/build.sbt:
--------------------------------------------------------------------------------
1 | name := "Example_05"
2 |
3 | version := "1.0"
4 |
5 | scalaVersion := "2.11.8"
6 |
7 | libraryDependencies ++= Seq(
8 | "com.typesafe.akka" %% "akka-actor" % "2.4.16",
9 | "com.typesafe.akka" %% "akka-persistence" % "2.4.16",
10 | "org.iq80.leveldb" % "leveldb" % "0.7",
11 | "org.fusesource.leveldbjni" % "leveldbjni-all" % "1.8",
12 | "com.twitter" %% "chill-akka" % "0.8.0",
13 | "com.typesafe.akka" %% "akka-persistence-query" % "2.5.3"
14 | )
15 |
--------------------------------------------------------------------------------
/Example_01/.idea/libraries/SBT__com_typesafe_akka_akka_actor_2_11_2_4_16_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example_02/.idea/libraries/SBT__com_typesafe_akka_akka_actor_2_11_2_4_16_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example_03/.idea/libraries/SBT__com_typesafe_akka_akka_actor_2_11_2_4_16_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example_03/.idea/libraries/SBT__com_typesafe_akka_akka_testkit_2_11_2_4_16_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example_03/.idea/libraries/SBT__org_scala_lang_modules_scala_xml_2_11_1_0_5_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example_06/remote/src/main/resources/application.conf:
--------------------------------------------------------------------------------
1 | akka {
2 | actor {
3 | provider = "akka.remote.RemoteActorRefProvider"
4 | serializers {
5 | kryo = "com.twitter.chill.akka.AkkaSerializer"
6 | }
7 | serialization-bindings {
8 | // "java.io.Serializable" = none
9 | "scala.Product" = kryo
10 | }
11 | }
12 | remote {
13 | enabled-transports = ["akka.remote.netty.tcp"]
14 | netty.tcp {
15 | hostname = "127.0.0.1"
16 | port = 4444
17 | }
18 | log-sent-messages = on
19 | log-received-messages = on
20 | }
21 | }
--------------------------------------------------------------------------------
/Example_07/src/main/resources/application.conf:
--------------------------------------------------------------------------------
1 | akka {
2 | loglevel = "ERROR"
3 | actor {
4 | provider = "akka.cluster.ClusterActorRefProvider"
5 | serializers {
6 | kryo = "com.twitter.chill.akka.AkkaSerializer"
7 | }
8 | serialization-bindings {
9 | "java.io.Serializable" = none
10 | "scala.Product" = kryo
11 | }
12 | }
13 |
14 | remote {
15 | transport = "akka.remote.netty.NettyRemoteTransport"
16 | log-remote-lifecycle-events = off
17 | netty.tcp {
18 | hostname = "127.0.0.1"
19 | port = 5000
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/Example_01/.idea/libraries/SBT__org_scala_lang_modules_scala_java8_compat_2_11_0_7_0_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example_02/.idea/libraries/SBT__org_scala_lang_modules_scala_java8_compat_2_11_0_7_0_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example_03/.idea/libraries/SBT__org_scala_lang_modules_scala_java8_compat_2_11_0_7_0_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example_04/src/main/scala/futures/FutureSequence.scala:
--------------------------------------------------------------------------------
1 | package futures
2 |
3 | import scala.concurrent.Future
4 | import scala.concurrent.ExecutionContext.Implicits.global
5 |
6 | /**
7 | * Created by panguansen on 17/5/17.
8 | */
9 | object FutureSequence extends App {
10 |
11 | // 理想情况: 列表中的Future全部都成功
12 | val listF: Seq[Future[Int]] = for (i <- 0 until 10) yield Future { i * i }
13 | // sequence: 完成 Seq[Future[Int]] => Future[Seq[Int]] 的转换
14 | val fList: Future[Seq[Int]] = Future.sequence(listF)
15 |
16 | for {
17 | r <- fList
18 | } yield println(r)
19 |
20 | Thread.sleep(1000)
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/Example_03/.idea/libraries/SBT__org_scala_lang_modules_scala_parser_combinators_2_11_1_0_4_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example_04/src/main/scala/futures/FutureFlatMap.scala:
--------------------------------------------------------------------------------
1 | package futures
2 |
3 | import scala.concurrent.Future
4 | import scala.concurrent.ExecutionContext.Implicits.global
5 |
6 | /**
7 | * Created by panguansen on 17/5/17.
8 | */
9 | object FutureFlatMap extends App{
10 |
11 | val fut1 = Future {
12 | println("enter task1")
13 | Thread.sleep(2000)
14 | 1 + 1
15 | }
16 |
17 | val fut2 = Future {
18 | println("enter task2")
19 | Thread.sleep(1000)
20 | 2 + 2
21 | }
22 |
23 | fut1.flatMap { v1 =>
24 | fut2.map { v2 =>
25 | println(s"the result is ${v1 + v2}")
26 | }
27 | }
28 | Thread.sleep(2500)
29 | }
30 |
--------------------------------------------------------------------------------
/Example_06/local/src/main/scala-2.11/LocalDemo.scala:
--------------------------------------------------------------------------------
1 | import akka.actor.{ActorSystem, Props}
2 |
3 | import scala.io.StdIn
4 |
5 | object LocalDemo extends App {
6 |
7 | implicit val system = ActorSystem("LocalDemoSystem")
8 |
9 | //val localActorUsingIdentity = system.actorOf(Props[LocalActorUsingIdentity], name = "LocalActorUsingIdentity")
10 | val localActor = system.actorOf(Props[LocalActor], name = "LocalActor")
11 |
12 | localActor ! Init
13 | localActor ! SendNoReturn
14 | // localActor ! SendHasReturn
15 | localActor ! SendSerialization
16 |
17 | // StdIn.readLine()
18 | // system.terminate()
19 | // StdIn.readLine()
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/Example_06/local/src/main/resources/application.conf:
--------------------------------------------------------------------------------
1 | akka {
2 | actor {
3 | provider = "akka.remote.RemoteActorRefProvider"
4 | serializers {
5 | kryo = "com.twitter.chill.akka.AkkaSerializer"
6 | }
7 | serialization-bindings {
8 | // "java.io.Serializable" = none
9 | "scala.Product" = kryo
10 | }
11 | }
12 | remote {
13 | enabled-transports = ["akka.remote.netty.tcp"]
14 | netty.tcp {
15 | hostname = "127.0.0.1"
16 | port = 0
17 | }
18 | }
19 | }
20 |
21 | remote {
22 | actor {
23 | name {
24 | test = "akka.tcp://RemoteDemoSystem@127.0.0.1:4444/user/RemoteActor"
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/Example_04/src/main/scala/futures/TestScalaFuture.scala:
--------------------------------------------------------------------------------
1 | package futures
2 |
3 | import scala.concurrent.Future
4 | import scala.util.Success
5 | import scala.concurrent.ExecutionContext.Implicits.global
6 |
7 | /**
8 | * Created by panguansen on 17/5/17.
9 | */
10 | object TestScalaFuture extends App {
11 |
12 | val fut = Future {
13 | Thread.sleep(1000)
14 | 1 + 1
15 | }
16 |
17 | fut onComplete {
18 | case Success(r) => println(s"the result is ${r}")
19 | case _ => println("some Exception")
20 | }
21 | // fut onComplete {
22 | // case Success(r) => println(r+2)
23 | // case _ => println("some Exception")
24 | // }
25 |
26 | println("I am working")
27 | Thread.sleep(2000)
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/Example_06/build.sbt:
--------------------------------------------------------------------------------
1 | import sbt._
2 | import sbt.Keys._
3 |
4 | lazy val AllLibraryDependencies =
5 | Seq(
6 | "com.typesafe.akka" %% "akka-actor" % "2.5.3",
7 | "com.typesafe.akka" %% "akka-remote" % "2.5.3",
8 | "com.twitter" %% "chill-akka" % "0.8.4"
9 | )
10 |
11 | lazy val commonSettings = Seq(
12 | name := "AkkaRemoting",
13 | version := "1.0",
14 | scalaVersion := "2.11.11",
15 | libraryDependencies := AllLibraryDependencies
16 | )
17 |
18 | lazy val remote = (project in file("remote"))
19 | .settings(commonSettings: _*)
20 | .settings(
21 | // other settings
22 | )
23 |
24 | lazy val local = (project in file("local"))
25 | .settings(commonSettings: _*)
26 | .settings(
27 | // other settings
28 | )
29 |
--------------------------------------------------------------------------------
/Example_07/backend/src/main/resources/application.conf:
--------------------------------------------------------------------------------
1 | #//#snippet
2 | akka {
3 | actor {
4 | provider = "akka.cluster.ClusterActorRefProvider"
5 | }
6 | remote {
7 | log-remote-lifecycle-events = off
8 | netty.tcp {
9 | hostname = "127.0.0.1"
10 | port = 0
11 | }
12 | }
13 |
14 | cluster {
15 | seed-nodes = [
16 | "akka.tcp://ClusterSystem@127.0.0.1:2551"]
17 |
18 | roles = [backend]
19 | #//#snippet
20 | # excluded from snippet
21 | auto-down-unreachable-after = 10s
22 | #//#snippet
23 | # auto downing is NOT safe for production deployments.
24 | # you may want to use it during development, read more about it in the docs.
25 | #
26 | }
27 |
28 | }
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Example_06/local/src/main/java/JoinRmiEvt.java:
--------------------------------------------------------------------------------
1 | import java.io.Serializable;
2 | import java.rmi.Remote;
3 |
4 | /**
5 | * Created by panguansen on 17/8/24.
6 | */
7 | public class JoinRmiEvt implements Remote , Serializable{
8 | private static final long serialVersionUID = 1L;
9 | private Long id;
10 | private String name;
11 |
12 | public JoinRmiEvt(Long id, String name) {
13 | this.id = id;
14 | this.name = name;
15 | }
16 |
17 | public Long getId() {
18 | return id;
19 | }
20 |
21 | public void setId(Long id) {
22 | this.id = id;
23 | }
24 |
25 | public String getName() {
26 | return name;
27 | }
28 |
29 | public void setName(String name) {
30 | this.name = name;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Example_06/remote/src/main/java/JoinRmiEvt.java:
--------------------------------------------------------------------------------
1 | import java.io.Serializable;
2 | import java.rmi.Remote;
3 |
4 | /**
5 | * Created by panguansen on 17/8/24.
6 | */
7 | public class JoinRmiEvt implements Remote , Serializable{
8 | private static final long serialVersionUID = 1L;
9 | private Long id;
10 | private String name;
11 |
12 | public JoinRmiEvt(Long id, String name) {
13 | this.id = id;
14 | this.name = name;
15 | }
16 |
17 | public Long getId() {
18 | return id;
19 | }
20 |
21 | public void setId(Long id) {
22 | this.id = id;
23 | }
24 |
25 | public String getName() {
26 | return name;
27 | }
28 |
29 | public void setName(String name) {
30 | this.name = name;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Example_01/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Example_02/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Example_03/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Example_04/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Example_07/backend/src/main/scala-2.11/sample/cluster/transformation/backend/TransformationBackendApp.scala:
--------------------------------------------------------------------------------
1 | package sample.cluster.transformation.backend
2 |
3 | import language.postfixOps
4 | import scala.concurrent.duration._
5 | import akka.actor.ActorSystem
6 | import akka.actor.Props
7 | import com.typesafe.config.ConfigFactory
8 |
9 | object TransformationBackendApp {
10 | def main(args: Array[String]): Unit = {
11 | // Override the configuration of the port when specified as program argument
12 | val port = if (args.isEmpty) "2553" else args(0)
13 | val config = ConfigFactory.parseString(s"akka.remote.netty.tcp.port=$port").
14 | withFallback(ConfigFactory.load())
15 |
16 | val system = ActorSystem("ClusterSystem", config)
17 | system.actorOf(Props[TransformationBackend], name = "backend")
18 | }
19 | }
--------------------------------------------------------------------------------
/Example_04/src/main/scala/futures/FutureTraverse.scala:
--------------------------------------------------------------------------------
1 | package futures
2 |
3 | import scala.concurrent.Future
4 | import scala.concurrent.ExecutionContext.Implicits.global
5 |
6 | /**
7 | * Created by panguansen on 17/5/17.
8 | */
9 | object FutureTraverse extends App {
10 |
11 | val list = List(1, 2, 3, 4, 5)
12 |
13 | // 这种方式会使用list的size个工作线程,这里是使用了5个线程
14 | val listFutures: List[Future[Int]] = list map (num => Future(num * num))
15 | listFutures.foreach { case future =>
16 | future foreach {
17 | num => println(s"num in future is $num")
18 | }
19 | }
20 |
21 | // 这种方式只会使用一个工作线程
22 | val futureList: Future[List[Int]] = Future.traverse(list)(num => Future(num * num))
23 | futureList.foreach{ case listNum =>
24 | listNum foreach {
25 | num => println(s"num in list is $num")
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Example_07/frontend/src/main/scala-2.11/sample/cluster/transformation/frontend/TransformationFrontendApp.scala:
--------------------------------------------------------------------------------
1 | package sample.cluster.transformation.frontend
2 |
3 | import language.postfixOps
4 | import akka.actor.ActorSystem
5 | import akka.actor.Props
6 | import com.typesafe.config.ConfigFactory
7 | import akka.cluster.client.ClusterClientReceptionist
8 |
9 |
10 |
11 | object TransformationFrontendApp {
12 |
13 | def main(args: Array[String]): Unit = {
14 |
15 | val port = if (args.isEmpty) "0" else args(0)
16 | val config = ConfigFactory.parseString(s"akka.remote.netty.tcp.port=$port").
17 | withFallback(ConfigFactory.load())
18 |
19 | val system = ActorSystem("ClusterSystem", config)
20 | val frontend = system.actorOf(Props[TransformationFrontend], name = "frontend")
21 | ClusterClientReceptionist(system).registerService(frontend)
22 | }
23 |
24 | }
--------------------------------------------------------------------------------
/Example_01/.idea/sbt.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
20 |
21 |
--------------------------------------------------------------------------------
/Example_02/.idea/sbt.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Example_03/.idea/sbt.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Example_04/.idea/sbt.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Example_06/remote/src/main/java/RemoteRmiImpl.java:
--------------------------------------------------------------------------------
1 | import java.rmi.RemoteException;
2 | import java.rmi.server.UnicastRemoteObject;
3 |
4 | /**
5 | * Created by panguansen on 17/8/24.
6 | */
7 | public class RemoteRmiImpl extends UnicastRemoteObject implements RemoteRmi {
8 |
9 | private static final long serialVersionUID = 1L;
10 |
11 | public RemoteRmiImpl() throws RemoteException {};
12 |
13 | @Override
14 | public void sendNoReturn(String message) throws RemoteException, InterruptedException {
15 | Thread.sleep(2000);
16 | // throw new RemoteException();
17 | }
18 |
19 | @Override
20 | public String sendHasReturn(JoinRmiEvt joinRmiEvt) throws RemoteException {
21 | if (joinRmiEvt.getId() >= 0)
22 | return new StringBuilder("the").append(joinRmiEvt.getName()).append("has join").toString();
23 | else return null;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Example_07/frontend/src/main/resources/application.conf:
--------------------------------------------------------------------------------
1 | #//#snippet
2 | akka {
3 | actor {
4 | provider = "akka.cluster.ClusterActorRefProvider"
5 | }
6 | remote {
7 | log-remote-lifecycle-events = off
8 | netty.tcp {
9 | hostname = "127.0.0.1"
10 | port = 0
11 | }
12 | }
13 |
14 | cluster {
15 | seed-nodes = [
16 | "akka.tcp://ClusterSystem@127.0.0.1:2551"]
17 |
18 | roles = [frontend]
19 |
20 | #//#snippet
21 | # excluded from snippet
22 | auto-down-unreachable-after = 10s
23 | #//#snippet
24 | # auto downing is NOT safe for production deployments.
25 | # you may want to use it during development, read more about it in the docs.
26 | #
27 | # auto-down-unreachable-after = 10s
28 | }
29 |
30 | # enable receptionist at start
31 | extensions = ["akka.cluster.client.ClusterClientReceptionist"]
32 |
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/Example_05/src/main/scala/PersitienceQueryTest.scala:
--------------------------------------------------------------------------------
1 | import akka.NotUsed
2 | import akka.actor.ActorSystem
3 | import akka.persistence.query.{EventEnvelope, PersistenceQuery}
4 | import akka.persistence.query.journal.leveldb.scaladsl.LeveldbReadJournal
5 | import akka.stream.ActorMaterializer
6 | import akka.stream.scaladsl.Source
7 | /**
8 | * Created by panguansen on 17/7/23.
9 | */
10 | object PersistenceQueryTest extends App {
11 | val system = ActorSystem("example-05")
12 | implicit val mat = ActorMaterializer()(system)
13 | val queries = PersistenceQuery(system).readJournalFor[LeveldbReadJournal](
14 | LeveldbReadJournal.Identifier)
15 |
16 | val src: Source[EventEnvelope, NotUsed] =
17 | queries.eventsByPersistenceId("lottery-actor-2", 0L, Long.MaxValue)
18 |
19 | src.runForeach { event => println("Event: " + event) }
20 | Thread.sleep(3000)
21 | system.terminate()
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/Example_06/remote/src/main/java/RemoteRMIServer.java:
--------------------------------------------------------------------------------
1 | import java.net.MalformedURLException;
2 | import java.rmi.AlreadyBoundException;
3 | import java.rmi.Naming;
4 | import java.rmi.RemoteException;
5 | import java.rmi.registry.LocateRegistry;
6 |
7 | /**
8 | * Created by panguansen on 17/8/24.
9 | */
10 | public class RemoteRMIServer {
11 | public static void main(String[] args) throws RemoteException, AlreadyBoundException, MalformedURLException, InterruptedException {
12 | System.out.println("the RemoteRMIServer is Starting ...");
13 | RemoteRmiImpl remoteRmi = new RemoteRmiImpl();
14 | System.out.println("Binding server implementation to registry");
15 | LocateRegistry.createRegistry(2553);
16 | Naming.bind("rmi://127.0.0.1:2553/remote_rmi",remoteRmi);
17 | System.out.println("the RemoteRMIServer is Started");
18 | Thread.sleep(10000000);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | some demo for learning akka
2 |
3 | akka series article
4 |
5 | - [Akka系列(一):Akka简介与Actor模型](http://www.godpan.me/2017/03/18/learning-akka-1.html)
6 | - [Akka系列(二):Akka中的Actor系统](http://www.godpan.me/2017/04/02/learning-akka-2.html)
7 | - [Akka系列(三):监管与容错](http://www.godpan.me/2017/04/15/learning-akka-3.html)
8 | - [Akka系列(四):Akka中的共享内存模型](http://www.godpan.me/2017/05/01/learning-akka-4.html)
9 | - [Akka系列(五):Java和Scala中的Future](http://www.godpan.me/2017/05/15/learning-akka-5.html)
10 | - [Akka系列(六):Actor解决了什么问题?](http://www.godpan.me/2017/07/10/learning-akka-6.html)
11 | - [Akka系列(七):Actor持久化之Akka persistence](http://www.godpan.me/2017/07/25/learning-akka-7.html)
12 | - [Akka系列(八):Akka persistence设计理念之CQRS](http://www.godpan.me/2017/07/29/learning-akka-8.html)
13 | - [Akka系列(九):Akka分布式之Akka Remote](http://www.godpan.me/2017/08/10/learning-akka-9.html)
14 | - [Akka系列(十):Akka集群之Akka Cluster](http://www.godpan.me/2017/09/05/learning-akka-10.html)
--------------------------------------------------------------------------------
/Example_04/src/main/java/futures/Test.java:
--------------------------------------------------------------------------------
1 | package futures;
2 |
3 | import java.util.concurrent.*;
4 |
5 | /**
6 | * Created by panguansen on 17/5/14.
7 | */
8 | public class Test {
9 | public static void main(String[] args) {
10 | ExecutorService es = Executors.newSingleThreadExecutor();
11 | Future f = es.submit(() -> {
12 | System.out.println("execute call");
13 | Thread.sleep(1000);
14 | return 5;
15 | });
16 | try {
17 | System.out.println(f.isDone());
18 | System.out.println(f.get(2000, TimeUnit.MILLISECONDS));
19 | System.out.println(f.isDone());
20 | } catch (InterruptedException e) {
21 | e.printStackTrace();
22 | } catch (ExecutionException e) {
23 | e.printStackTrace();
24 | } catch (TimeoutException e) {
25 | e.printStackTrace();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Example_03/src/main/scala/FaultHandlingDocSample.scala:
--------------------------------------------------------------------------------
1 | //import akka.actor._
2 | //import com.typesafe.config.ConfigFactory
3 | //
4 | ///**
5 | // * Created by panguansen on 17/3/26.
6 | // */
7 | // object FaultHandlingDocSample extends App {
8 | // import Worker._
9 | //
10 | // val config = ConfigFactory.parseString("""
11 | // akka.loglevel = "DEBUG"
12 | // akka.actor.debug {
13 | // receive = on
14 | // lifecycle = on
15 | // }
16 | // """)
17 | //
18 | // val system = ActorSystem("FaultToleranceSample", config)
19 | // val worker = system.actorOf(Props[Worker], name = "worker")
20 | // val listener = system.actorOf(Props[Listener], name = "listener")
21 | // // start the work and listen on progress
22 | // // note that the listener is used as sender of the tell,
23 | // // i.e. it will receive replies from the worker
24 | // worker.tell(Start, sender = listener)
25 | // }
26 | //
27 |
--------------------------------------------------------------------------------
/Example_07/README.txt:
--------------------------------------------------------------------------------
1 | In order to run this you should run thins in the following order
2 |
3 | 1. sample.cluster.transformation.frontend.TransformationFrontendApp command line arg 2551
4 | 2. sample.cluster.transformation.backend.TransformationBackendApp command line arg 2552
5 | 3. sample.cluster.transformation.backend.TransformationBackendApp
6 | 4. sample.cluster.transformation.backend.TransformationBackendApp
7 | 5. sample.cluster.transformation.frontend.TransformationFrontendApp
8 |
9 |
10 |
11 | ClusterClient
12 |
13 | https://groups.google.com/forum/#!topic/akka-user/rqSqh82fimE
14 | Future