This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent._ | |
import akka.dispatch.{Dispatcher, ExecutorServiceDelegate} | |
import config.Config | |
import helpers.ScalaLogger | |
class ExecutionContextMonitor()(implicit metricsService: MetricsClient, config: Config) { | |
private val log = ScalaLogger.get(this.getClass) | |
private val scheduler = Executors.newSingleThreadScheduledExecutor() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.TimeUnit | |
import monix.execution.cancelables.MultiAssignmentCancelable | |
import monix.execution.{Cancelable, Scheduler} | |
import monix.execution.schedulers.{ExecutionModel, LocalBatchingExecutor} | |
import scala.concurrent.ExecutionContext | |
import scala.concurrent.duration.FiniteDuration | |
class AkkaToMonixScheduler( | |
akkaScheduler: akka.actor.Scheduler, | |
context: ExecutionContext, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait JobDescription | |
sealed trait HasN { | |
def n: Int | |
} | |
case class JobOne(n: Int) extends JobDescription with HasN | |
case object JobTwo extends JobDescription | |
case class JobThree(n: Int) extends JobDescription with HasN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example from Odersky et al http://infoscience.epfl.ch/record/215280/files/paper.pdf | |
object DT { | |
trait Key { type Value } | |
class Setting(val str: String) extends Key | |
val sort = new Setting("sort") { type Value = String } | |
val width = new Setting("width") { type Value = Int } | |
val params = HMap.empty.add(width)(120).add(sort)("time") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// immutable cycle | |
class Node[T]( val value: T, _next: => Node[T] ){ | |
lazy val next = _next | |
} | |
val cycle: Node[Int] = new Node( 1, new Node( 2, cycle ) ) | |
// prints List(1, 2, 1, 2, 1, 2, 1, 2, 1, 2) | |
println(cycle.iterator.take(10).map(_.value).toList) | |
implicit class NodeIterator[T](node: Node[T]){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class ReportInvalidJsonActorHolder(ref: ActorRef) | |
case class ReportUnhandledExceptionActorHolder(ref: ActorRef) | |
case class HeartbestProcessingActorHolder(ref: ActorRef) | |
case class DebugEmailActorHolder(ref: ActorRef) | |
object ReportInvalidJsonActor { | |
def props(debugEmailActorHolder: DebugEmailActorHolder) = | |
Props(classOf[ReportInvalidJsonActor], debugEmailActorHolder) | |
case class InvalidJsonMessage(content : String, exceptionMessage: String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package scalax.collection | |
import scala.collection.mutable.ListBuffer | |
/** FoldTransformers and the views based on them are a Scala | |
* adaptation, and to some degree an extension, of Rich Hickey's | |
* transducers for Clojure. They show that the concepts can be | |
* implemented in a type-safe way, and that the implementation is | |
* quite beautiful. | |
*/ | |
object FoldingViews { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Used as a term `the[T]` yields the unique implicit value of type `T` in the current | |
// implicit scope, if any. It is a compile time error if there is no such value. Its | |
// primary advantage over `Predef.implicitly` is that it will preserve any refinement that | |
// the implicit definition has, resulting in more precisely typed, and hence often more | |
// useful, values, | |
scala> trait Foo { type T ; val t: T } | |
defined trait Foo | |
scala> implicit val intFoo: Foo { type T = Int } = new Foo { type T = Int ; val t = 23 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How Akka maps to EAI Patterns | |
Might be up for debate or just plain wrong. Just some notes I scribbled down some time ago. | |
----------------------------------------------------------------------------------------------------------------- | |
EAI PATTERN AKKA PATTERN REFERENCE | |
----------------------------------------------------------------------------------------------------------------- | |
Point to Point Channel Regular Actor Communication http://www.eaipatterns.com/PointToPointChannel.html | |
Event-Driven Consumer Regular Actor Receive http://www.eaipatterns.com/EventDrivenConsumer.html | |
Message Selector Actor with Stash http://www.eaipatterns.com/MessageSelector.html |
NewerOlder