Skip to content

Instantly share code, notes, and snippets.


Johan Andrén johanandren

Block or report user

Report or block johanandren

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
johanandren /
Created Jan 2, 2020
Java mock actor child
class MyActor extends AbstractActor {
public Receive createReceive() {
return receiveBuilder()
.match(Request.class, this::onRequest)
private void onRequest(Request request) {
ActorRef child = createChildForRequest(request);
johanandren / ProgrammaticJoin.scala
Created Oct 4, 2018
Three node Akka cluster in one JVM with minimal fuzz
View ProgrammaticJoin.scala
import akka.cluster.Cluster
import com.typesafe.config.ConfigFactory
object ProgrammaticJoin extends App {
val commonConfig = ConfigFactory.parseString(
akka {
actor.provider = cluster
remote.artery.enabled = true
View PartitionOnType.scala
import akka.NotUsed
import{GraphDSL, Partition, Sink, Source}
import{ActorMaterializer, SinkShape}
import scala.reflect.ClassTag
object PartitionOnType extends App {
implicit val system = ActorSystem()
import akka.NotUsed;
import akka.http.javadsl.ConnectHttp;
import akka.http.javadsl.Http;
import akka.http.javadsl.model.HttpRequest;
import akka.http.javadsl.model.HttpResponse;
import akka.http.javadsl.server.Route;
johanandren / MultipleUnmarshallers.scala
Created Oct 13, 2017
Combining multiple unmarshallers for different dataformats for one path
View MultipleUnmarshallers.scala
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.ContentTypes
import akka.http.scaladsl.unmarshalling.{FromEntityUnmarshaller, Unmarshaller}
object MultipleUnmarshallers extends App {
implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()
johanandren / RateLimit.scala
Created Jul 14, 2017
Sample for a custom rate limiting directive for Akka HTTP
View RateLimit.scala
* Copyright (C) 2009-2017 Lightbend Inc. <>
package http
import java.util.concurrent.atomic.AtomicInteger
import{Actor, ActorRef, ActorSystem, Props}
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{HttpResponse, StatusCodes, Uri}
View TypedAndUnionTypes.scala
import akka.typed.Behavior
import akka.typed.scaladsl.Actor._
sealed trait LifecycleCommand
object Stop extends LifecycleCommand
val lifecycleBehavior: Behavior[LifecycleCommand] =
immutable[LifecycleCommand]((ctx, msg) =>
msg match {
case Stop =>
View SerializerAndPathDependentTypes.scala
package basics
import{ActorSystem, ExtendedActorSystem}
import akka.serialization.{JavaSerializer, SerializationExtension}
import com.typesafe.config.ConfigFactory
trait MyPayload
trait OtherPayload
trait PersistentExecutorProtocol extends Serializable {
View StashFailApp.scala
import{Actor, ActorSystem, Props, Stash}
class MyActor extends Actor with Stash {
def receive = {
case _ =>
println("after unstashAll")
johanandren /
Last active Apr 28, 2017
Trying to reproduce a problem with FSM
public class FSMTestActor extends AbstractFSM<String, String> {
public final static String A = "A";
static class Event {
public final int n;
You can’t perform that action at this time.