Skip to content

Commit

Permalink
Typed actors first example.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabi Volpe committed Aug 4, 2016
0 parents commit 1bb29cb
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
*#
*.iml
*.ipr
*.iws
*.pyc
*.tm.epoch
*.vim
*/project/boot
*/project/build/target
*/project/project.target.config-classes
*-shim.sbt
*~
.#*
.*.swp
.DS_Store
.cache
.cache
.classpath
.codefellow
.ensime*
.eprj
.history
.idea
.manager
.multi-jvm
.project
.scala_dependencies
.scalastyle
.settings
.tags
.tags_sorted_by_file
.target
.worksheet
Makefile
TAGS
lib_managed
logs
project/boot/*
project/plugins/project
src_managed
target
tm*.lck
tm*.log
tm.out
worker*.log
/bin
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
typed-actors-demo
=================

Simple demo using [Typed Actors](https://github.com/knutwalker/typed-actors).
12 changes: 12 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name := """typed-actors-demo"""

version := "1.0"

scalaVersion := "2.11.8"

libraryDependencies ++= List(
"com.typesafe.akka" %% "akka-actor" % "2.4.9-RC1",
"de.knutwalker" %% "typed-actors" % "1.6.0",
"de.knutwalker" %% "typed-actors-creator" % "1.6.0"
)

1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.8
27 changes: 27 additions & 0 deletions src/main/scala/com/gvolpe/typed/Demo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.gvolpe.typed

import akka.actor._
import de.knutwalker.akka.typed._
import com.gvolpe.typed.actor.TypedActorExample
import com.gvolpe.typed.actor.TypedActorExample.{Bar, Foo}

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._

object Demo extends App {

implicit val system = ActorSystem("typed-actors-demo")

case object SomeOtherMessage

val actor = TypedActorExample.props

actor ! Foo("Hey you!")
actor ! Bar("What's the craic?")

// You'll get a compilation error!
//actor ! SomeOtherMessage

system.scheduler.scheduleOnce(2.seconds)(system.terminate())

}
20 changes: 20 additions & 0 deletions src/main/scala/com/gvolpe/typed/actor/TypedActorExample.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.gvolpe.typed.actor

import akka.actor.{Actor, ActorSystem}
import de.knutwalker.akka.typed._
import com.gvolpe.typed.actor.TypedActorExample._

object TypedActorExample {
sealed trait MyMessage
case class Foo(foo: String) extends MyMessage
case class Bar(bar: String) extends MyMessage

def props(implicit s: ActorSystem) = ActorOf(Props[MyMessage, TypedActorExample], name = "typed-actor")
}

class TypedActorExample extends Actor {
override def receive: Receive = {
case Foo(foo) => println(s"received a Foo: $foo")
case Bar(bar) => println(s"received a Bar: $bar")
}
}

0 comments on commit 1bb29cb

Please sign in to comment.