Skip to content

Instantly share code, notes, and snippets.

@patriknw
patriknw / MaxStage.scala
Last active July 8, 2016 14:31
Blog: GraphStage emit and friends
package blog
import akka.stream.Attributes
import akka.stream.FlowShape
import akka.stream.Inlet
import akka.stream.Outlet
import akka.stream.stage.GraphStage
import akka.stream.stage.GraphStageLogic
import akka.stream.stage.InHandler
import akka.stream.stage.OutHandler
@patriknw
patriknw / gist:4bcec28b8d3e5c5e56cc
Created November 16, 2015 07:39
Cassandra materialized view
cqlsh:ks1> CREATE TABLE events (
... persistence_id text,
... partition_nr bigint,
... sequence_nr bigint,
... timestamp timeuuid,
... message text,
... tag text,
... used boolean static,
... PRIMARY KEY ((persistence_id, partition_nr), sequence_nr, timestamp)
... ) WITH CLUSTERING ORDER BY (sequence_nr ASC);
@patriknw
patriknw / gist:3feec3899cd8c9870d7d
Created September 22, 2014 06:48
akka-data-replication performance v0.6 vs v0.5

Results of running PerformanceSpec for version 0.6 and 0.5 of akka-data-replication

== Version 0.6 ==

500 ORSet Update WriteOne took 43 ms, 11627 TPS
500 ORSet Update WriteOne took 9 ms, 55555 TPS
500 ORSet Update WriteOne took 8 ms, 62500 TPS
500 ORSet Update WriteOne took 8 ms, 62500 TPS
500 ORSet Update WriteOne took 5 ms, 100000 TPS

500 ORSet Update WriteOne took 6 ms, 83333 TPS

/**
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.event.japi
/**
* Java API: See documentation for [[akka.event.EventBus]]
* E is the Event type
* S is the Subscriber type
* C is the Classifier type
@patriknw
patriknw / MyLoggingReceive.scala
Created December 20, 2013 12:33
Example of a custom LoggingReceive
import akka.actor.Actor.Receive
import akka.actor.ActorContext
import akka.actor.ActorLogging
import akka.actor.Actor
import akka.event.LoggingAdapter
object MyLoggingReceive {
def apply(log: LoggingAdapter)(r: Receive)(implicit context: ActorContext): Receive = r match {
case _: MyLoggingReceive ⇒ r
@patriknw
patriknw / ResolveManyCollector.scala
Created August 23, 2013 09:09
Identify actors matching wildcard ActorSelection.
/**
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.contrib.pattern
import akka.actor.ActorIdentity
import akka.actor.Props
import akka.actor.ActorSelection
import scala.concurrent.duration.Deadline
import akka.actor.ReceiveTimeout
@patriknw
patriknw / ClientSubscriber.scala
Created August 19, 2013 17:39
Client side subscriber
object TopicAssistant {
case class Subscribe(topic: String)
case object SubscribeAck
}
// Start this actor with name "topicAssistant" on each node in the cluster
class TopicAssistant extends Actor {
import TopicAssistant._
ClusterReceptionistExtension(context.system).registerService(self)
@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 / WatchSample.scala
Created July 9, 2013 06:03
Remote Watch Spotlight
case object Register
class Master extends Actor {
var workers = Set.empty[ActorRef]
def receive = {
case Register =>
workers += sender
context watch sender
case Terminated(ref) =>
@patriknw
patriknw / WatchActorSelectionSample.scala
Created July 8, 2013 06:55
Watch ActorSelection spotlight
val selection = context.actorSelection(
"akka.tcp://sys@10.0.0.1:2552/user/world")
selection ! Identify(None)
var ref: ActorRef = _
def receive = {
case ActorIdentity(_, Some(actorRef)) =>
ref = actorRef
context watch ref
case ActorIdentity(_, None) => // not alive