Skip to content

Instantly share code, notes, and snippets.

View jboner's full-sized avatar

Jonas Bonér jboner

View GitHub Profile
import scala.collection.mutable.ListBuffer
import akka.actor.{Actor,ActorRef}
import akka.actor.Actor._
import akka.routing.{ Listeners, Listen }
//Represents a domain event
trait Event
//A builder to create domain entities
trait EntityBuilder[Entity] {
// Shutdown HawtDispatch GlobalQueue
org.fusesource.hawtdispatch.ScalaDispatch.globalQueue.asInstanceOf[org.fusesource.hawtdispatch.internal.GlobalDispatchQueue].shutdown
// Clear Thread.subclassAudits
val tf = classOf[java.lang.Thread].getDeclaredField("subclassAudits")
tf.setAccessible(true)
val subclassAudits = tf.get(null).asInstanceOf[java.util.Map[_,_]]
subclassAudits.synchronized {subclassAudits.clear}
// Clear and reset j.u.l.Level.known (due to Configgy)
import java.util.zip._
import java.io._
class InMemZip(compressionLevel: Int) {
private val _outBytes = new ByteArrayOutputStream
private val _zipOutStream = {
val s = new ZipOutputStream(_outBytes)
s.setLevel(compressionLevel)
s
}
<!-- Example of Akka/Spring integration -->
<beans>
<!-- Create an active object -->
<akka:active-object id="myActiveObject"
target="com.biz.MyPOJO"
transactional="true"
timeout="1000" />
import java.io.{BufferedReader, File, InputStream, InputStreamReader, IOException, PrintWriter, Writer}
import java.net.{InetAddress, ServerSocket, Socket, SocketException}
import java.util.concurrent.Executors
import net.lag.logging.Logger
import scala.actors.Actor
import scala.actors.Actor._
import scala.tools.nsc._
class RemoteDebugServer(port: Int) {
import com.facebook.thrift.{TBase, TDeserializer}
import java.io.{BufferedInputStream, DataInputStream, File, FileInputStream, InputStream}
import java.util.zip.GZIPInputStream
import net.lag.logging.Logger
import scala.reflect.Manifest
// you'll want to import your generated Thrift package too!
class ThriftFileScanner[T <: TBase](implicit man: Manifest[T]) {
val log = Logger.get
var bufferedIn: BufferedInputStream = null
@jboner
jboner / LoggableException.scala
Created September 23, 2009 07:56
Loggable exception class, with trackable unique id
/**
* Base trait for all classes that wants to be able use the logging infrastructure.
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
trait Logging {
@transient var log = Logger.get(this.getClass.getName)
}
/**
@jboner
jboner / gist:182740
Created September 8, 2009 05:44
DI using var's and partial functions
object HttpBuilder {
var buildHttp: () => HttpThingIntf = new NormalHttpThing
}
// I want to change what is built by the HttpBuilder:
HttpBuilder.buildHttp = () => new MockHttpThing
// And to build a new HttpThing:
import se.scalablesolutions.akka.serialization.Serializer
import se.scalablesolutions.akka.actor.Actor
import com.rabbitmq.client.ConnectionParameters
object ExampleSession {
import AMQP._
val SERIALIZER = Serializer.Java
val CONFIG = new ConnectionParameters
val HOSTNAME = "localhost"
val PORT = 5672
@jboner
jboner / Immutable domain model in Scala
Created August 24, 2009 15:06
Immutable Domain Model with JPA
// Sketch of an immutable domain model in Scala
// We used this scheme together with this JPA module:
// http://github.com/jboner/skalman/blob/d1e03a85be3964b9012f9e79dd726b0546342b2b/core/src/main/scala/JPA.scala
// ...and this GenericRepository:
// http://github.com/jboner/skalman/blob/d1e03a85be3964b9012f9e79dd726b0546342b2b/core/src/main/scala/GenericRepository.scala
abstract class Entity[T](val id: Int)
object User {