This file contains hidden or 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
type Curryable[-A,-B, +C] = { def curried: A => Function[B,C] } |
This file contains hidden or 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 com.covariantblabbering | |
package object rotatingmap { | |
type OnExpiration[K,V] = ((K,V)) => Unit | |
} |
This file contains hidden or 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 com.covariantblabbering.rotatingmap | |
import scala.annotation.tailrec | |
import scala.collection.immutable.HashMap | |
class RotatingMap[K, V](val numBuckets: Int, val expiredCallback: Option[OnExpiration[K, V]]) { | |
assert(numBuckets > 2, "Number of buckets must be greater or equal to 2") | |
private var _buckets: List[Map[K, V]] = (1 to numBuckets).foldRight(List.empty[Map[K, V]])((_, l) => new HashMap[K, V] :: l) |
This file contains hidden or 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.atomic.{ AtomicInteger, AtomicLong, AtomicBoolean } | |
import akka.AkkaException | |
import akka.actor.Scheduler | |
import akka.util.Unsafe | |
import scala.util.control.NoStackTrace | |
import java.util.concurrent.{ Callable, CopyOnWriteArrayList } | |
import scala.concurrent.{ ExecutionContext, Future, Promise, Await } | |
import scala.concurrent.duration._ | |
import scala.util.control.NonFatal | |
import scala.util.Success |
This file contains hidden or 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
/* | |
* Sentries | |
* Copyright (c) 2012-2013 Erik van Oosten All rights reserved. | |
* | |
* The primary distribution site is https://github.com/erikvanoosten/sentries | |
* | |
* This software is released under the terms of the BSD 2-Clause License. | |
* There is NO WARRANTY. See the file LICENSE for the full text. | |
*/ |
This file contains hidden or 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.atomic.AtomicReference | |
import java.util.concurrent.atomic.AtomicInteger | |
import java.util.concurrent.atomic.AtomicLong | |
class Configuration(val name: String, val timeout: Long = 2000, val failureThreshold: Int = 3) | |
class CircuitBreakerStillOpenException(msg: String) extends Exception(msg) | |
class CircuitBreaker(private val conf: Configuration) { | |
private object HalfOpen extends State { |
This file contains hidden or 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
def list: Parser[BList] = { | |
delimitedBy(LIST_BEGIN, LIST_END) { | |
rep(string | int | list | dict) | |
} ^^ (BList(_)) named ("list") | |
} | |
def dict: Parser[BDict] = { | |
delimitedBy(DICT_BEGIN, DICT_END) { | |
rep(string ~ (string | int | list | dict)) | |
} ^^ (_.map { case key ~ value => key -> value }) ^^ (l => BDict(l.toMap)) named ("dict") |
This file contains hidden or 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
def natural = rep1(single_digit) ^^ (_.mkString.toInt) named ("natural") | |
def signedInt = new Parser[Int] { | |
def apply(in: Input) = { | |
'-'(in) match { | |
case Success(_, rest) => natural(rest) map (_ * -1) | |
case _ => natural(in) | |
} | |
} | |
} named ("signed_int") |
This file contains hidden or 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
def ~> [U](q: => Parser[U]): Parser[U] = { lazy val p = q // lazy argument | |
(for(a <- this; b <- p) yield b).named("~>") | |
} |
This file contains hidden or 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
trait BencodeParser extends Parsers with BencodeConstants { | |
type Elem = Byte | |
implicit def charToParser(ch: Char) = elem(ch.toByte) | |
def delimitedBy[A](left: Parser[Byte], right: Parser[Byte])(p: Parser[A]): Parser[A] = left ~> p <~ right | |
def single_digit = new Parser[String] { |