This file contains 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 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] { |
This file contains 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
// 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) |
This file contains 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.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 | |
} |
This file contains 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
<!-- Example of Akka/Spring integration --> | |
<beans> | |
<!-- Create an active object --> | |
<akka:active-object id="myActiveObject" | |
target="com.biz.MyPOJO" | |
transactional="true" | |
timeout="1000" /> | |
This file contains 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.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) { |
This file contains 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 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 |
This file contains 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
/** | |
* Base trait for all classes that wants to be able use the logging infrastructure. | |
* | |
* @author <a href="http://jonasboner.com">Jonas Bonér</a> | |
*/ | |
trait Logging { | |
@transient var log = Logger.get(this.getClass.getName) | |
} | |
/** |
This file contains 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
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: |
This file contains 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 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 |
This file contains 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
// 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 { |