Skip to content

Instantly share code, notes, and snippets.

@rkuhn
rkuhn / Timer.scala
Created January 11, 2013 22:47
draft of new lockless Timer implementation for Akka
/**
* Copyright (C) 2013 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.util
import java.util.concurrent.atomic.AtomicReferenceArray
import scala.annotation.tailrec
import scala.concurrent.ExecutionContext
@rkuhn
rkuhn / FullSample.scala
Last active December 24, 2018 17:27
Sample code for the blog post about Typed Channels in Akka
/**
* Copyright (C) 2013 Typesafe Inc. <http://www.typesafe.com>
*/
package docs.channels
import akka.actor.{ Actor, ActorSystem }
import akka.channels._
import akka.util.Timeout
import scala.concurrent.duration._
@rkuhn
rkuhn / bad.java
Last active December 16, 2015 17:49
sample snippets for Props spotlight blogpost
final ActorRef child = getContext().actorOf(new Props(
new UntypedActorFactory() {
@Override public UntypedActor create() {
// getSender() will not yield what you think it should
return new OtherActor(getSender());
}
}))
@rkuhn
rkuhn / SupervisorLogging.java
Last active December 19, 2015 02:29
supervisorStrategy with adapted logging
private static SupervisorStrategy strategy =
new OneForOneStrategy(10, Duration.create("1 minute"),
new Function<Throwable, Directive>() {
@Override
public Directive apply(Throwable t) {
if (t instanceof ArithmeticException) {
return resume();
} else if (t instanceof NullPointerException) {
log.warning("restarting misbehaving child");
return restart();
@rkuhn
rkuhn / theVar.scala
Created July 23, 2013 11:26
“unbecoming” blog post races
var isDownloading = false
// set up a scheduler to sync the registry
system.scheduler.schedule(0 millis, 3 hours) {
if(!isDownloading) {
system.actorOf(Props[Downloader]) ! Download
}
}
/*
package demo
class TopLevel extends Actor {
val db = context.actorOf(Props[Database])
context.watch(db)
val web = context.actorOf(Props[WebServer])
web ! Start(database = db)
override val supervisorStrategy = OneForOneStrategy() {
@rkuhn
rkuhn / Build.scala
Created August 24, 2013 10:38
A small experiment to integrate akka.Main with sbt-start-script (applying https://github.com/sbt/sbt-start-script/pull/43). sbt> start-script will generate a runner which executes the Actor `org.example.Main`
import sbt._
import sbt.Keys._
import com.typesafe.sbt.SbtStartScript.{startScriptForClassesSettings => startScript}
import com.typesafe.sbt.SbtStartScript.StartScriptKeys._
object AkkaProjectInScalaBuild extends Build {
lazy val akkaProjectInScala = Project(
id = "akka-project-in-scala",
base = file("."),
@rkuhn
rkuhn / WatcherForwarder.java
Created October 1, 2013 09:36
Staying in Contact with an Actor’s Acquaintances
import java.util.concurrent.TimeUnit;
import scala.concurrent.duration.Duration;
import akka.actor.ActorIdentity;
import akka.actor.ActorPath;
import akka.actor.ActorRef;
import akka.actor.Identify;
import akka.actor.ReceiveTimeout;
import akka.actor.Terminated;
import akka.actor.UntypedActorWithStash;
@rkuhn
rkuhn / Bounded.scala
Created July 12, 2014 12:34
Performance assessment of bounded vs unbounded requests across an asynchronous boundary
package rs
import org.openjdk.jmh.annotations._
import org.reactivestreams.Publisher
import org.reactivestreams.Subscriber
import org.reactivestreams.Subscription
import java.util.concurrent.atomic.AtomicLong
import java.util.Queue
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
rk:~ rkuhn$ tracert.pl youtube.com
traceroute: Warning: youtube.com has multiple addresses; using 173.194.113.136
traceroute to youtube.com (173.194.113.136), 64 hops max, 52 byte packets
1 fritz.box (192.168.178.1 [PRIVATE-ADDRESS-CBLK-RFC1918-IANA-RESERVED]) 0.933 ms 0.772 ms 0.707 ms
2 213.191.89.55 (213.191.89.55 [HANSENET]) 25.085 ms 25.208 ms 25.241 ms
3 62.53.12.0 (62.53.12.0 [DE-MEDIAWAYS-970527]) 25.232 ms 25.375 ms 26.425 ms
4 ge8-0.br50.fra.de.hansenet.net (62.109.70.21 [DE-HANSENET-20010803]) 25.899 ms 25.569 ms 40.448 ms
5 de-cix10.net.google.com (80.81.192.108 [DE-CIX-FRA-IXP]) 26.053 ms 25.781 ms 25.564 ms
6 209.85.240.64 (209.85.240.64 [GOOGLE]) 34.697 ms 26.763 ms
209.85.241.110 (209.85.241.110 [GOOGLE]) 26.022 ms