Skip to content

Instantly share code, notes, and snippets.

package ex1
import akka.actor.{Actor, ActorSystem, Props}
import akka.pattern.{CircuitBreaker, ask, pipe}
import akka.util.Timeout
import ex1.CircuitBreakerActor.{Broken, BreakState, Ok}
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scala.util.control.NonFatal
@matsu-chara
matsu-chara / SleepingActor.scala
Last active February 27, 2016 08:04
Pinnedなら3~4秒で終わる, min-parallel-dispatcherとかを使うと何倍もかかる
package ex1
import akka.actor.{Actor, ActorSystem, Props}
import akka.pattern.ask
import akka.util.Timeout
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
object Main3 {
package ex1
import java.util.concurrent.atomic.AtomicInteger
import akka.actor._
import akka.pattern.{Backoff, BackoffSupervisor}
import scala.concurrent.Await
import scala.concurrent.duration._
@matsu-chara
matsu-chara / BlockingNonBlockingSample.scala
Last active February 21, 2016 05:28
NonBlockingにしないとこうなる
package com.example
import akka.actor._
import akka.pattern._
import com.example.DbActor.Message.{BlockingRequest, NonBlockingRequest, Result}
import scala.concurrent.{ExecutionContext, Future}
object BlockingNonBlockingSample {
def main(args: Array[String]): Unit = {
@matsu-chara
matsu-chara / super.preRestart.scala
Last active December 8, 2016 09:37
super.preRestartの位置でライフサイクルの呼ばれる順番が変わる
import akka.actor.SupervisorStrategy.{Resume, Restart, Stop}
import akka.actor._
object PreRestart extends App {
val system = ActorSystem()
try {
val actor = system.actorOf(Props[SupervisorExceptionActor2])
actor ! 1
actor ! 2
actor ! 3
@matsu-chara
matsu-chara / primary_constructor.scala
Last active February 6, 2016 04:36
primary constructorの中身はRestartなら二回呼ばれる
import akka.actor.SupervisorStrategy.{Resume, Restart, Stop}
import akka.actor._
object Main extends App {
val system = ActorSystem()
try {
val actor = system.actorOf(Props[SupervisorExceptionActor])
actor ! 1
actor ! 2
actor ! 3
@matsu-chara
matsu-chara / deadlock.scala
Created February 2, 2016 13:43
1の処理が終わらないとkillされない予感
import akka.actor.SupervisorStrategy.{Restart, Stop}
import akka.actor._
object Main extends App {
val system = ActorSystem()
try {
val actor = system.actorOf(Props[SupervisorExceptionActor])
actor ! 1
actor ! 2
} finally {
def cont1(request: Int): Cont[Unit, Int] =
Cont((f: Int => Unit) => {
println("add 1")
f(request + 1)
println("added 1")
})
def cont2(request: Int): Cont[Unit, Int] =
Cont((f: Int => Unit) => {
println("add 2")
@matsu-chara
matsu-chara / x_print.scala
Created January 30, 2016 02:20
Xprintの例
$ scalac -Xprint:typer Foo.scala
[[syntax trees at end of typer]] // Foo.scala
package <empty> {
object Main extends AnyRef with App {
def <init>(): Main.type = {
Main.super.<init>();
()
};
def foo(x: Option[Int]): Unit = x match {
case (x: Int)Some[Int]((a @ _)) => scala.this.Predef.println(a)
@matsu-chara
matsu-chara / Vagrantfile
Last active December 12, 2015 07:07
ponyc build environment on ubuntu-14.04 (vagrant)
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at