Skip to content

Instantly share code, notes, and snippets.

Manuel Bernhardt manuelbernhardt

Block or report user

Report or block manuelbernhardt

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
View SimpleDocumentUploadSpec.scala
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}
/**
@manuelbernhardt
manuelbernhardt / gist:2722048
Created May 17, 2012
Akka / Play 2 & Groovy Deadlock
View gist:2722048
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)
View gist:2717311
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),
View gist:2708629
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)
View gist:2694058
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)
@manuelbernhardt
manuelbernhardt / gist:1868295
Created Feb 20, 2012
Session composition for action composition
View gist:1868295
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 {
View constraints.scala
val fieldConstraints = form.mapping.mappings.map(m => m.key -> m.constraints)
View MongoCacheImpl.scala
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
@manuelbernhardt
manuelbernhardt / gist:1249014
Created Sep 28, 2011
ObjectId de/serializer for Jerkson
View gist:1249014
@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)
View CHJson.scala
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)
}
You can’t perform that action at this time.