Skip to content

Instantly share code, notes, and snippets.

View jboner's full-sized avatar

Jonas Bonér jboner

View GitHub Profile
@havocp
havocp / SafeActor.scala
Created April 23, 2012 14:02
Use actor state from Future callbacks
package com.ometer.akka
import akka.actor.Actor
import akka.dispatch.ExecutionContext
import akka.actor.ActorRef
import akka.dispatch.Promise
import akka.dispatch.Future
import akka.dispatch.DefaultPromise
class Example extends SafeActor {
@jamie-allen
jamie-allen / IoManagerBootstrap.scala
Created August 10, 2012 20:37
Simple example of how to use Akka IOManager Iteratee and exporting work to another actor
import akka.actor._
import akka.pattern.ask
import akka.util._
import akka.util.duration._
import scala.util.control.Exception._
/**
* To test, execute this code and use this command in a shell: "telnet localhost 8080"
* At the prompt, type in numbers and press enter, and they will be accumulated, returning
* the total value each time.
@patriknw
patriknw / RouterPerf.scala
Created September 14, 2012 08:07
Microbenchmark of akka routers
package perf
import akka.actor.ActorSystem
import akka.actor.Actor
import akka.actor.Props
import scala.concurrent.forkjoin.ThreadLocalRandom
import akka.routing.ConsistentHashingRouter
import akka.routing.ConsistentHashingRouter.ConsistentHashableEnvelope
import scala.util.Random
import akka.routing.Broadcast
@timyates
timyates / fridayfun.groovy
Last active October 10, 2015 16:58
A Ping-Pong HotSwapped Untyped Akka Actor in Groovy
@Grab( 'com.typesafe.akka:akka-actor_2.10:2.3.2' )
@Grab( 'com.typesafe:config:1.2.0' )
import akka.actor.UntypedActor
import akka.japi.Procedure
import akka.actor.ActorSystem
import akka.actor.Props
import com.typesafe.config.ConfigFactory
class PingPongActor extends UntypedActor {
static final String PING = 'PING'
@patriknw
patriknw / ConsistentHashingRouterSpotlight.scala
Created October 3, 2012 12:16
Spotlight for ConsistentHashingRouter
import akka.routing.ConsistentHashingRouter
import akka.routing.ConsistentHashingRouter.ConsistentHashMapping
import akka.actor.Actor
import akka.pattern.ask
case class Entry(key: String, value: String)
class Cache extends Actor {
var cache = Map.empty[String, String]
@patriknw
patriknw / ClusterRouter.conf
Created October 8, 2012 12:15
Spotlight for Cluster Aware Routers
akka.actor.deployment {
/statsService/workerRouter {
router = round-robin
nr-of-instances = 100
cluster {
enabled = on
routees-path = "/user/statsWorker"
}
}
}
@patriknw
patriknw / ClusterListener.scala
Created October 8, 2012 12:48
Spotlight for Cluster Membership
import akka.cluster.Cluster
import akka.cluster.ClusterEvent._
val clusterListener = system.actorOf(Props(new Actor with ActorLogging {
def receive = {
case state: CurrentClusterState ⇒
log.info("Current members: {}", state.members)
case MemberUp(member) ⇒
log.info("Member is up: {}", member)
// send a message to the "world" actor running at the member node
@patriknw
patriknw / ClusterWatch.scala
Created October 8, 2012 13:12
Spotlight for Cluster Death Watch
case object BackendRegistration
case class Job(text: String)
class Frontend extends Actor {
var backends = IndexedSeq.empty[ActorRef]
var jobCounter = 0
def receive = {
case job: Job if backends.isEmpty =>
@patriknw
patriknw / PeekMailbox.scala
Created November 21, 2012 14:20
PeekMailbox example
package example
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentLinkedQueue
import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory
import akka.actor.Actor
import akka.actor.ActorContext
import akka.actor.ActorRef
import akka.actor.ActorSystem
@rkuhn
rkuhn / count-repl-session.txt
Created December 9, 2012 20:13
too simple benchmark
Welcome to Scala version 2.10.0-RC5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_07).
Type in expressions to have them evaluated.
Type :help for more information.
scala> system=ActorSystem("repl",ConfigFactory.parseString("pinned{type=PinnedDispatcher;executor=thread-pool-executor}").withFallback(config))
[DEBUG] [12/09/2012 21:23:23.535] [run-main] [EventStream(akka://repl)] logger log1-Logging$DefaultLogger started
[DEBUG] [12/09/2012 21:23:23.535] [run-main] [EventStream(akka://repl)] Default Loggers started
system: akka.actor.ActorSystem = akka://repl
scala> case class Add(x: Int)