Skip to content

Instantly share code, notes, and snippets.

@derekwyatt
derekwyatt / Alternate restart factory diff
Created April 11, 2011 17:33
I threw this together to illustrate the idea of sliding in an alternate factory to use during Actor restarts, as opposed to the initial one that was used on construction
diff --git a/akka-actor/src/main/scala/akka/actor/ActorRef.scala b/akka-actor/src/main/scala/akka/actor/ActorRef.scala
index ce62987..fbe6eef 100644
--- a/akka-actor/src/main/scala/akka/actor/ActorRef.scala
+++ b/akka-actor/src/main/scala/akka/actor/ActorRef.scala
@@ -949,7 +949,8 @@ class LocalActorRef private[akka] (
failedActor.postRestart(reason)
case _ =>
failedActor.preRestart(reason)
- val freshActor = newActor
+ val restartFactory = newActor(failedActor.getRestartFactory(reason).getOrElse(actorFactory))
@derekwyatt
derekwyatt / NewRouter.scala
Created April 21, 2011 13:33
Pattern for async exception handling?
class NewRouter extends Actor {
self.faultHandler = OneForOneStrategy(List(classOf[Throwable]), 5, 5000)
var sendCount = 0
def receive = {
case Send(tag) =>
val routeBackTo = self.sender
val riskyWorker = actorOf(new Actor {
self.lifeCycle = Permanent
def receive = {
case "go" =>
@derekwyatt
derekwyatt / ReqRspActor.scala
Created May 3, 2011 16:00
A simple Request/Response one-shot Akka Actor example
object ReqRspActor {
object ReqRspProtocol {
case class UnknownMessage(msg: String) extends Exception(msg)
case class FutureException(exception: Throwable)
}
object ResendOrNot extends Enumeration {
type ResendOrNot = Value
val Resend, DoNotResend = Value
}
@derekwyatt
derekwyatt / ActorInversion.scala
Created May 9, 2011 19:21
Inversion of actor messaging control example. !, !! and !!! are not defined on the Actor, they are defined on the message
import akka.actor._
import akka.actor.Actor._
import akka.dispatch.{Future, CompletableFuture, DefaultCompletableFuture, FutureTimeoutException}
/************************************************
* Toolkit stuff
************************************************/
// Something to derive from
@derekwyatt
derekwyatt / microkernel-server.xml
Created May 11, 2011 12:07
My microkernel / jetty config
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<!-- =============================================================== -->
<!-- Configure the Jetty Server -->
<!-- -->
<!-- Documentation of this file format can be found at: -->
<!-- http://wiki.eclipse.org/Jetty/Reference/jetty.xml_syntax -->
<!-- -->
<!-- Additional configuration files are available in $JETTY_HOME/etc -->
@derekwyatt
derekwyatt / reqrsp.scala
Created June 23, 2011 17:27
Shows a simple request/response wrapper for Akka Actors
object ReqRspActor {
object ReqRspProtocol {
case class UnknownMessage(msg: String) extends Exception(msg)
case class FutureException(exception: Throwable)
}
object HandledOrNot extends Enumeration {
type HandledOrNot = Value
val MessageHandled, MessageNotHandled = Value
}
@derekwyatt
derekwyatt / dir.sh
Created August 18, 2011 14:04
A BASH script to handle directory management
export DIRSTACK_MAX=15
DS=()
function eecho
{
echo $@ 1>&2
}
function shiftStackUp
{
@derekwyatt
derekwyatt / broker.py
Created August 30, 2011 23:35
This is an ENSIME broker to be used for Vim integration to ENSIME... just a prototype at this point
#!/usr/bin/python
import socket
import re
from time import sleep
from os import system
from threading import Thread
from optparse import OptionParser
parser = OptionParser()
@derekwyatt
derekwyatt / scalatestobject.scala
Created September 6, 2011 13:01
Illustrating flexible test object creation using named parameters, option monads, and list flattening
// This just illustrates some nice aspects of the Option type with List and 'flatten' as well as named parameters
// Some "complex" object here
val defaultSubField1: SubField = ...
val defaultSubField2: SubField = ...
val defaultSubField3: SubField = ...
def createTestComposite(identifier: String = "default", something: Boolean = true,
subField1: Option[SubField] = Some(defaultSubField1),
subField2: Option[SubField] = Some(defaultSubField2),
@derekwyatt
derekwyatt / updateboundingbox.vim
Created September 27, 2011 19:13
An example of integrating a simple shell script into Vim
" When I'm editing some LaTeX, I use PDF files to handle any inserted images and
" LaTeX has some difficulty lining them up right, so I explicitly state the
" viewport. To get the bounding box from the PDF file, I have a script called
" 'getbb'. This function is /very/ specific to my needs. It pulls the filename
" from the current line, which always looks something like this:
"
" \includegraphics[scale=0.5, viewport = 40 39 703 153]{target/filename.pdf}
"
" Pulls out the filename (i.e. target/filename.pdf), runs 'getbb' on that and
" inserts the output back overtop of the "viewport = 40 39 703 153".