Skip to content

Instantly share code, notes, and snippets.

View manuelbernhardt's full-sized avatar

Manuel Bernhardt manuelbernhardt

View GitHub Profile
object CHJson extends com.codahale.jerkson.Json {
// this is where we setup out Jackson module for custom de/serialization
val module: SimpleModule = new SimpleModule("delving", Version.unknownVersion())
module.addSerializer(classOf[ObjectId], new ObjectIdSerializer)
module.addDeserializer(classOf[ObjectId], new ObjectIdDeserializer)
mapper.registerModule(module)
}
@manuelbernhardt
manuelbernhardt / gist:1249014
Created September 28, 2011 19:40
ObjectId de/serializer for Jerkson
@JsonCachable
class ObjectIdSerializer extends JsonSerializer[ObjectId] {
def serialize(id: ObjectId, json: JsonGenerator, provider: SerializerProvider) {
json.writeString(id.toString)
}
}
class ObjectIdDeserializer extends JsonDeserializer[ObjectId] {
def deserialize(jp: JsonParser, context: DeserializationContext) = {
if (!ObjectId.isValid(jp.getText)) throw context.mappingException("invalid ObjectId " + jp.getText)
package util
import play.cache.CacheImpl
import models.salatContext._
import scala.collection.JavaConversions.asJavaMap
import com.mongodb.casbah.Imports._
import com.mongodb.WriteResult
import java.io._
import play.jobs.{Every, Job}
import controllers.ErrorReporter
val fieldConstraints = form.mapping.mappings.map(m => m.key -> m.constraints)
@manuelbernhardt
manuelbernhardt / gist:1868295
Created February 20, 2012 07:42
Session composition for action composition
val newSession = additionalSessionParams.foldLeft[Session](request.session) { _ + _ }
val r: PlainResult = action(request).asInstanceOf[PlainResult]
// workaround since withSession calls aren't composable it seems
val innerSession = r.header.headers.get(SET_COOKIE).map(cookies => Session.decodeFromCookie(Cookies.decode(cookies).find(_.name == Session.COOKIE_NAME)))
if(innerSession.isDefined) {
// there really should be an API method for adding sessions
val combined = innerSession.get.data.foldLeft(newSession) { _ + _ }
r.withSession(combined)
} else {
@manuelbernhardt
manuelbernhardt / gist:2694058
Created May 14, 2012 13:43
Play Akka deadlock
2012-05-14 15:41:08
Full thread dump Java HotSpot(TM) 64-Bit Server VM (20.6-b01-415 mixed mode):
"New I/O server worker #1-9" prio=5 tid=7fdc4308c000 nid=0x116fb9000 runnable [116fb8000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.KQueueArrayWrapper.kevent0(Native Method)
at sun.nio.ch.KQueueArrayWrapper.poll(KQueueArrayWrapper.java:136)
at sun.nio.ch.KQueueSelectorImpl.doSelect(KQueueSelectorImpl.java:69)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:69)
- locked <79507ad18> (a sun.nio.ch.Util$2)
2012-05-16 10:14:59
Full thread dump Java HotSpot(TM) 64-Bit Server VM (20.6-b01-415 mixed mode):
"New I/O server worker #1-4" prio=5 tid=7f9d79d30000 nid=0x119a92000 runnable [119a91000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.KQueueArrayWrapper.kevent0(Native Method)
at sun.nio.ch.KQueueArrayWrapper.poll(KQueueArrayWrapper.java:136)
at sun.nio.ch.KQueueSelectorImpl.doSelect(KQueueSelectorImpl.java:69)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:69)
- locked <79bf3a138> (a sun.nio.ch.Util$2)
Found one Java-level deadlock:
=============================
"application-akka.actor.default-dispatcher-13":
waiting to lock monitor 7ffabd802ff0 (object 79537ad48, a sbt.PlayReloader$$anon$2$$anon$1),
which is held by "application-akka.actor.default-dispatcher-9"
"application-akka.actor.default-dispatcher-9":
waiting to lock monitor 7ffabd803098 (object 79453edb8, a sbt.PlayCommands$$anonfun$49$$anonfun$51$$anon$2),
which is held by "play-akka.actor.actions-dispatcher-3"
"play-akka.actor.actions-dispatcher-3":
waiting to lock monitor 7ffabd802ff0 (object 79537ad48, a sbt.PlayReloader$$anon$2$$anon$1),
@manuelbernhardt
manuelbernhardt / gist:2722048
Created May 17, 2012 22:35
Akka / Play 2 & Groovy Deadlock
Full thread dump Java HotSpot(TM) 64-Bit Server VM (20.6-b01-415 mixed mode):
"play-akka.actor.actions-dispatcher-11" prio=5 tid=7ff06b361000 nid=0x118434000 waiting on condition [118433000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <792efbd00> (a akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinPool)
at akka.jsr166y.ForkJoinPool.scan(ForkJoinPool.java:1593)
at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1478)
at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
import core.SystemField
import models.MetadataCache
import play.api.libs.json.Json._
import play.api.libs.json.Format._
import play.api.libs.json._
import play.api.mvc.AnyContentAsJson
import play.api.test.Helpers._
import play.api.test.{FakeHeaders, FakeRequest}
/**