Skip to content

Instantly share code, notes, and snippets.

@patriknw
patriknw / LoggingMailbox.scala
Last active January 5, 2023 08:12
Logs the mailbox size when exceeding the configured limit. Implemented in Scala and Java. Copy one of them to your project and define the configuration. This code is licensed under the Apache 2 license.
/**
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.contrib.mailbox
import scala.concurrent.duration._
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicLong
import com.typesafe.config.Config
import akka.actor.{ ActorContext, ActorRef, ActorSystem, ExtendedActorSystem }
@patriknw
patriknw / AtLeastOnceExample.scala
Created September 11, 2019 06:52
AtLeastOnceDelivery in Akka Typed
package docs.akka.persistence.typed
import scala.concurrent.duration.FiniteDuration
import akka.actor.typed.ActorRef
import akka.actor.typed.Behavior
import akka.actor.typed.scaladsl.Behaviors
import akka.actor.typed.scaladsl.LoggerOps
import akka.persistence.typed.PersistenceId
import akka.persistence.typed.RecoveryCompleted
@patriknw
patriknw / SimpleRouterApp.scala
Created July 27, 2013 07:26
Minimized sample of cluster router
package sample.cluster.simple
import scala.concurrent.duration._
import akka.actor._
import akka.cluster.Cluster
import akka.cluster.ClusterEvent._
import akka.routing.FromConfig
import com.typesafe.config.ConfigFactory
object SimpleRouterApp {
@patriknw
patriknw / Squarer.java
Created December 14, 2019 08:47
Methods delegation to actor
package squerer;
import akka.actor.typed.ActorRef;
import akka.actor.typed.Behavior;
import akka.actor.typed.Scheduler;
import akka.actor.typed.javadsl.AbstractBehavior;
import akka.actor.typed.javadsl.ActorContext;
import akka.actor.typed.javadsl.AskPattern;
import akka.actor.typed.javadsl.Behaviors;
import akka.actor.typed.javadsl.Receive;
@patriknw
patriknw / ClusterRegistrySpec.scala
Last active May 28, 2019 10:58
Example of how to implement a simple cluster wide actor registry.
/**
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.contrib.pattern
import language.postfixOps
import scala.concurrent.duration._
import com.typesafe.config.ConfigFactory
import akka.actor.Actor
import akka.actor.testkit.typed.scaladsl.BehaviorTestKit
import akka.actor.typed.Behavior
import akka.actor.typed.scaladsl.AbstractBehavior
import org.scalatest.Matchers
import org.scalatest.WordSpec
object SyncTestingFSMExampleSpec {
sealed trait Command
final case class Type(c: Char) extends Command
@patriknw
patriknw / LinearStageLogic.scala
Created June 13, 2018 15:22
Prototype LinearStage
/**
* Copyright (C) 2018 Lightbend Inc. <http://www.lightbend.com>
*/
package akka.stream.stage
import scala.collection.immutable
import scala.concurrent.duration.FiniteDuration
import akka.NotUsed
import akka.annotation.InternalApi
@patriknw
patriknw / ClusterDemoSpec.scala
Created July 6, 2012 09:59
Sample of akka cluster test
package akka.cluster
import com.typesafe.config.ConfigFactory
import akka.remote.testkit.MultiNodeConfig
import akka.remote.testkit.MultiNodeSpec
import akka.testkit._
import akka.util.duration._
import akka.cluster.MemberStatus._
object ClusterDemoMultiJvmSpec extends MultiNodeConfig {
@patriknw
patriknw / AccountExample1.scala
Last active May 23, 2018 09:51
Alternative implementation of PR 25051
object AccountExample1 {
sealed trait AccountCommand
case object CreateAccount extends AccountCommand
case class Deposit(amount: Double) extends AccountCommand
case class Withdraw(amount: Double) extends AccountCommand
case object CloseAccount extends AccountCommand
sealed trait AccountEvent
case object AccountCreated extends AccountEvent
@patriknw
patriknw / FlowControlSample.scala
Last active May 10, 2018 18:35
Illustrates Actor message flow control with "work pulling pattern". This code is licensed under the Apache 2 license.
package flowcontrol
import scala.concurrent.duration._
import akka.actor.typed.ActorRef
import akka.actor.typed.ActorSystem
import akka.actor.typed.Behavior
import akka.actor.typed.scaladsl.Behaviors
/**