Skip to content

Commit

Permalink
Update to Akka 2.5.13 and cleanup unused things
Browse files Browse the repository at this point in the history
  • Loading branch information
patriknw committed Jul 12, 2018
1 parent 2972940 commit 5afafaf
Show file tree
Hide file tree
Showing 37 changed files with 78 additions and 210 deletions.
50 changes: 22 additions & 28 deletions akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
val akkaV = "2.4.3"

resolvers ++= Seq("Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/")
val akkaVersion = "2.5.13"
val akkaHttpVersion = "10.1.3"

val Frontend = config("frontend") extend(Compile)
val Backend = config("backend") extend(Compile)
Expand All @@ -12,31 +11,26 @@ def customAssemblySettings =
inTask(assembly)(mainClass := Some("sample.cluster.factorial.FactorialBackend")) ++
inTask(assembly)(assemblyJarName := "akka-sample-backend.jar"))

val project = Project(
id = "akka-sample-cluster-scala",
base = file("."),
settings = customAssemblySettings ++ Defaults.coreDefaultSettings ++ Seq(
name := """akka-sample-cluster""",
scalaVersion := "2.11.8",
// scalaVersion := provided by Typesafe Reactive Platform
scalacOptions in Compile ++= Seq("-encoding", "UTF-8", "-target:jvm-1.6", "-deprecation", "-feature", "-unchecked", "-Xlog-reflective-calls", "-Xlint"),
javacOptions in Compile ++= Seq("-source", "1.6", "-target", "1.6", "-Xlint:unchecked", "-Xlint:deprecation"),

lazy val `akka-sample-cluster-scala` = project
.in(file("."))
.settings(
customAssemblySettings,
name := "akka-sample-cluster",
scalaVersion := "2.12.6",
scalacOptions in Compile ++= Seq("-deprecation", "-feature", "-unchecked", "-Xlog-reflective-calls", "-Xlint"),
javacOptions in Compile ++= Seq("-Xlint:unchecked", "-Xlint:deprecation"),
javaOptions in run ++= Seq("-Xms128m", "-Xmx1024m"),
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-cluster" % akkaV,
"com.typesafe.akka" %% "akka-multi-node-testkit" % akkaV,
"com.typesafe.akka" %% "akka-http-experimental" % akkaV,
"com.typesafe.akka" %% "akka-http-spray-json-experimental" % akkaV,
"com.typesafe.akka" %% "akka-contrib" % akkaV,
"org.scalaj" %% "scalaj-http" % "2.3.0",
"com.typesafe.play" %% "play-json" % "2.3.4",
"org.scalatest" %% "scalatest" % "2.2.1" % "test"//,
/*"org.fusesource" % "sigar" % "1.6.4"*/),
javaOptions in run ++= Seq(
//"-Djava.library.path=./sigar",
"-Xms128m", "-Xmx1024m"),
Keys.fork in run := true,
mainClass in (Compile, run) := Some("sample.cluster.simple.SimpleClusterApp"),
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
"com.typesafe.akka" %% "akka-remote" % akkaVersion,
"com.typesafe.akka" %% "akka-cluster" % akkaVersion,
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion,
"org.scalatest" %% "scalatest" % "3.0.1" % Test),
fork in run := true,
mainClass in (Compile, run) := Some("sample.cluster.factorial.FactorialApp"),
parallelExecution in Test := false,
mainClass in assembly := Some("sample.cluster.factorial.FactorialApp")
mainClass in assembly := Some("sample.cluster.factorial.FactorialApp"),
licenses := Seq(("CC0", url("http://creativecommons.org/publicdomain/zero/1.0")))
)
)
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.3")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.7")
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#Activator-generated Properties
#Fri Aug 26 13:05:39 EDT 2016
template.uuid=472c6099-8b2b-4aee-a669-dbaab0c53138
sbt.version=0.13.7
sbt.version=1.1.6
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@

resolvers += Classpaths.typesafeReleases

addSbtPlugin("com.typesafe.sbt" % "sbt-multi-jvm" % "0.3.8")

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,34 @@ clustering {

akka {
actor {
provider = "akka.cluster.ClusterActorRefProvider"
provider = cluster
}
coordinated-shutdown.exit-jvm = on
remote {
log-remote-lifecycle-events = off
netty.tcp {
hostname = ${clustering.ip}
port = ${clustering.port}
bind-hostname=0.0.0.0
}
artery {
# enabled = on
transport = tcp
canonical.hostname = ${clustering.ip}
canonical.port = ${clustering.port}
bind.hostname=0.0.0.0
}
}

cluster {
# change 'akka.tcp' to 'akka' if artery is enabled
seed-nodes = [
"akka.tcp://"${clustering.name}"@"${clustering.seed-host}":"${clustering.seed-port}]

# auto downing is NOT safe for production deployments.
# you may want to use it during development, read more about it in the docs.
auto-down-unreachable-after = 10s
}

}


Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
include "application"

# //#min-nr-of-members
akka.cluster.min-nr-of-members = 2
# //#min-nr-of-members

# //#role-min-nr-of-members
akka.cluster.role {
frontend.min-nr-of-members = 1
backend.min-nr-of-members = 1
}
# //#role-min-nr-of-members

# //#adaptive-router
akka.actor.deployment {
/factorialFrontend/factorialBackendRouter = {
router = round-robin-group # adaptive-group
# metrics-selector = heap
# metrics-selector = load
# metrics-selector = cpu
# metrics-selector = mix
nr-of-instances = 4
router = round-robin-group
routees.paths = ["/user/factorialBackend"]
cluster {
enabled = on
Expand All @@ -28,4 +18,3 @@ akka.actor.deployment {
}
}
}
# //#adaptive-router

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object FactorialApp {
// starting 3 backend nodes and 1 frontend node
FactorialBackend.main(Seq("2551").toArray)
FactorialBackend.main(Seq("2552").toArray)
FactorialBackend.main(Array.empty)
FactorialBackend.main(Seq("2553").toArray)
FactorialFrontend.main(Array.empty)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ import akka.actor.Actor
import akka.actor.ActorLogging
import akka.actor.ActorSystem
import akka.actor.Props
import akka.http.scaladsl.Http
import akka.pattern.pipe

//#backend
class FactorialBackend extends Actor with ActorLogging {

import context.dispatcher

def receive = {
case (n: Int) =>
case n: Int =>
Future(factorial(n)) map { result => (n, result) } pipeTo sender()
}

Expand All @@ -29,7 +27,6 @@ class FactorialBackend extends Actor with ActorLogging {
}

}
//#backend

object FactorialBackend {

Expand All @@ -50,12 +47,22 @@ object FactorialBackend {
val internalSeedPort = appConfig.getString("clustering.seed-port")


val config = ConfigFactory.parseString("akka.cluster.roles = [backend]").
withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.hostname=$internalIp")).
withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.port=$port")).
withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.bind-hostname=0.0.0.0")).
withFallback(NetworkConfig.seedsConfig(clusterName, internalSeedHostname, internalSeedPort)).
withFallback(appConfig)
val config = ConfigFactory.parseString(s"""
akka.cluster.roles = [backend]
akka.remote {
netty.tcp {
hostname=$internalIp
port=$port
}
}

akka.remote.artery {
canonical.hostname=$internalIp
canonical.port=$port
}
""")
.withFallback(NetworkConfig.seedsConfig(clusterName, internalSeedHostname, internalSeedPort))
.withFallback(appConfig)

val system = ActorSystem(clusterName, config)
system.actorOf(Props[FactorialBackend], name = "factorialBackend")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import scala.concurrent.duration._
case object GetInfo
case class Info(completed: Long, n: Int, factorial: BigInt)

//#frontend
class FactorialFrontend(upToN: Int, repeat: Boolean) extends Actor with ActorLogging {

val backend = context.actorOf(FromConfig.props(),
Expand Down Expand Up @@ -56,7 +55,6 @@ class FactorialFrontend(upToN: Int, repeat: Boolean) extends Actor with ActorLog
1 to upToN foreach { backend ! _ }
}
}
//#frontend

object FactorialFrontend extends SprayJsonSupport with DefaultJsonProtocol {

Expand Down Expand Up @@ -107,7 +105,6 @@ object FactorialFrontend extends SprayJsonSupport with DefaultJsonProtocol {
val minMembers = appConfig.getNumber("akka.cluster.min-nr-of-members")

val config = ConfigFactory.parseString("akka.cluster.roles = [frontend]").
withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.bind-hostname=0.0.0.0")).
withFallback(NetworkConfig.seedsConfig(clusterName, internalSeedHostname, internalSeedPort)).
withFallback(appConfig)

Expand All @@ -116,24 +113,12 @@ object FactorialFrontend extends SprayJsonSupport with DefaultJsonProtocol {
implicit val timeout = Timeout(5.seconds)
implicit val executor = system.dispatcher
system.log.info(s"Factorials will start when $minMembers backend members in the cluster.")
//#registerOnUp

Cluster(system) registerOnMemberUp {
val frontend = system.actorOf(Props(classOf[FactorialFrontend], upToN, repeat), name = "factorialFrontend")
Http().bindAndHandle(routes(system, frontend, timeout), serverHost, serverPort)
}
//#registerOnUp

//#registerOnRemoved
Cluster(system).registerOnMemberRemoved {
// exit JVM when ActorSystem has been terminated
system.registerOnTermination(System.exit(-1))
// in case ActorSystem shutdown takes longer than 10 seconds,
// exit the JVM forcefully anyway
system.scheduler.scheduleOnce(10.seconds)(System.exit(-1))(system.dispatcher)
// shut down ActorSystem
system.terminate()
}
//#registerOnRemoved


}
}

This file was deleted.

Loading

0 comments on commit 5afafaf

Please sign in to comment.