Skip to content

Commit

Permalink
create cinnamon examples for akka actors
Browse files Browse the repository at this point in the history
  • Loading branch information
harmeetsingh0013 committed Jul 2, 2017
1 parent 28afb63 commit 94b0239
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
.idea/
target/
25 changes: 25 additions & 0 deletions build.sbt
@@ -0,0 +1,25 @@

name := "akka-cinammon"

version := "1.0"

scalaVersion := "2.11.8"

val akkaVersion = "2.4.17"

lazy val `akka-cinammon` = project in file(".") enablePlugins (Cinnamon)

// Add the Cinnamon Agent for run and test
cinnamon in run := true
cinnamon in test := true

// Set the Cinnamon Agent log level
cinnamonLogLevel := "INFO"

libraryDependencies ++= Seq(
Cinnamon.library.cinnamonCHMetrics,
Cinnamon.library.cinnamonAkka,
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion,
"org.scalatest" %% "scalatest" % "3.0.1"
)
1 change: 1 addition & 0 deletions project/build.properties
@@ -0,0 +1 @@
sbt.version = 0.13.13
8 changes: 8 additions & 0 deletions project/plugins.sbt
@@ -0,0 +1,8 @@
credentials += Credentials(Path.userHome / ".lightbend" / "commercial.credentials")

resolvers += Resolver.url("lightbend-commercial",
url("https://repo.lightbend.com/commercial-releases"))(Resolver.ivyStylePatterns)

addSbtPlugin("com.lightbend.cinnamon" % "sbt-cinnamon" % "2.4.2")

addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-RC6")
10 changes: 10 additions & 0 deletions src/main/resources/application.conf
@@ -0,0 +1,10 @@
cinnamon.akka {
actors {
"/user/*" {
report-by = instance
}
}
}
cinnamon.chmetrics {
reporters += "console-reporter"
}
23 changes: 23 additions & 0 deletions src/main/scala/com/harmeetsingh13/actors/HelloWorldActor.scala
@@ -0,0 +1,23 @@
package com.harmeetsingh13.actors

import akka.actor.{Actor, ActorLogging, ActorSystem, Props}

/**
* Created by Harmeet Singh(Taara) on 1/7/17.
*/
class HelloWorldActor extends Actor with ActorLogging {

override def receive: Receive = {
case any =>
Thread.sleep(1000)
log.info(s"Hello $any")
}
}

object HelloWorldActor extends App {

val system = ActorSystem("HelloWorldSystem")
val ref1 = system.actorOf(Props[HelloWorldSelectionActor])

for (i <- 1 to 10000) ref1 ! "James"
}
23 changes: 23 additions & 0 deletions src/main/scala/com/harmeetsingh13/actors/HelloWorldPoolActor.scala
@@ -0,0 +1,23 @@
package com.harmeetsingh13.actors

import akka.actor.{Actor, ActorLogging, ActorSystem, Props}
import akka.routing.RoundRobinPool

/**
* Created by Harmeet Singh(Taara) on 1/7/17.
*/
class HelloWorldPoolActor extends Actor with ActorLogging {

override def receive: Receive = {
case any =>
Thread.sleep(1000)
log.info(s"Hello $any")
}
}

object HelloWorldPoolActor extends App {
val system = ActorSystem("HelloWorldPoolSystem")
val ref1 = system.actorOf(RoundRobinPool(5).props(Props[HelloWorldPoolActor]), "HelloPool")

for (i <- 1 to 10000) ref1 ! "James"
}
@@ -0,0 +1,36 @@
package com.harmeetsingh13.actors

import akka.actor.{Actor, ActorLogging, ActorSystem, Props}
import akka.util.Timeout

import scala.concurrent.duration.DurationInt
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

/**
* Created by Harmeet Singh(Taara) on 1/7/17.
*/
class HelloWorldSelectionActor extends Actor with ActorLogging {

override def receive: Receive = {
case any =>
Thread.sleep(1000)
log.info(s"Hello $any")
}
}

object HelloWorldSelectionActor extends App {

val system = ActorSystem("HelloWorldSelectionSystem")
val ref1 = system.actorOf(Props[HelloWorldSelectionActor])
val ref2 = system.actorSelection(ref1.path)
val ref3 = system.actorSelection(ref1.path)
val ref4 = system.actorSelection(ref1.path)
val ref5 = system.actorSelection(ref1.path)

Future { for (i <- 1 to 10000) ref1 ! "James" }
Future { for (i <- 1 to 10000) ref2 ! "Jimmy" }
Future { for (i <- 1 to 10000) ref3 ! "Foo" }
Future { for (i <- 1 to 10000) ref4 ! "Bar" }
Future { for (i <- 1 to 10000) ref5 ! "FooBar" }
}

0 comments on commit 94b0239

Please sign in to comment.