Skip to content

Instantly share code, notes, and snippets.

Some Dude ericacm

Block or report user

Report or block ericacm

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
ericacm / MessageSequence.scala
Last active Aug 22, 2017
Implements the Message Sequence pattern from EIP (
View MessageSequence.scala
package akka.contrib.pattern
import{Cancellable, ActorLogging, ActorRef, Actor}
import java.util
import akka.serialization.SerializationExtension
import scala.concurrent.ExecutionContext
import scala.concurrent.duration._
import scala.util.{Try, Failure, Success}
import scala.language.existentials
import java.util.UUID
ericacm / Topic.scala
Last active Jun 25, 2017
Example Hibernate entity in Scala
View Topic.scala
* Topic Entity
@Table(uniqueConstraints = Array(new UniqueConstraint(columnNames=Array("application_id", "name"))))
new NamedQuery(name="Topic.findAllByApplication", query="from Topic where application=:application"),
new NamedQuery(name="Topic.findByApplicationAndName", query="from Topic where application=:application and name=:name")
class Topic {
ericacm / CslConfig.scala
Last active Aug 31, 2016
Example of a Scala wrapper for Typesafe Config
View CslConfig.scala
import io.Source
import{FileInputStream, InputStream}
import com.typesafe.config.{ConfigException, Config, ConfigFactory}
import{FileSystem, Factory}
* CslConfig manages CSL Configuration.
ericacm / FutureTimeoutSupport.scala
Last active Jul 11, 2016
Future timeout support
View FutureTimeoutSupport.scala
import akka.util.{Duration, NonFatal}
import akka.dispatch.{Promise, ExecutionContext, Future}
// Copied from Akka 2.1-M1
trait FutureTimeoutSupport {
* Returns a [[akka.dispatch.Future]] that will be completed with the success or failure of the provided value
* after the specified duration.
View gist:7234947
trait ActorStack extends Actor {
/** Actor classes should implement this partialFunction for standard
* actor message handling
def wrappedReceive: Receive
/** Stackable traits should override and call super.receive(x) for
* stacking functionality
def receive: Receive = {
ericacm / MessageSequenceTest.scala
Last active Dec 31, 2015
Test for Chunking trait
View MessageSequenceTest.scala
package akka.contrib.pattern
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{FunSuite, BeforeAndAfterAll}
import akka.testkit.TestKit
import java.util
import concurrent.duration._
import akka.serialization.SerializationExtension
ericacm / ScalingThreadPoolExecutor.scala
Last active Dec 29, 2015
ThreadPoolExecutor using an unbounded queue where minThreads can be less than maxThreads
View ScalingThreadPoolExecutor.scala
import scala.concurrent.ExecutionContext
import java.lang.Thread.UncaughtExceptionHandler
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.{ThreadPoolExecutor, LinkedBlockingQueue, ThreadFactory, TimeUnit}
import java.util.concurrent.{Executors, RejectedExecutionHandler, RejectedExecutionException}
object ScalingThreadPoolExecutor {
val defaultSecondsBeforeEviction = 60
def apply(minThreads: Int, maxThreads: Int, threadFactory: ThreadFactory): ScalingThreadPoolExecutor = {
ericacm / ReliableProxy.scala
Last active Dec 16, 2015
Enhanced ReliableProxy that obtains a new connection to the target actor if the tunnel terminates via Remote Deathwatch.
View ReliableProxy.scala
* Copyright (C) 2009-2013 Typesafe Inc. <>
package akka.contrib.pattern
import akka.remote.RemoteScope
import scala.concurrent.duration._
import scala.util.Try
View CancellableFuture.scala
trait FutureCancelSupport {
def cancellableFuture[T](fun: Future[T] => T)(implicit ex: ExecutionContext): (Future[T], () => Boolean) = {
val p = Promise[T]()
val f = p.future
val funFuture = Future(fun(f))
funFuture.onComplete(p tryComplete(_)) // Akka 2.0
// p tryCompleteWith funFuture // Scala 2.10
(f, () => p.tryComplete(Left(new CancellationException))) // Akka 2.0
You can’t perform that action at this time.