Skip to content

Commit

Permalink
reformat source
Browse files Browse the repository at this point in the history
  • Loading branch information
ph2734 committed Apr 27, 2012
1 parent a68ca60 commit f9dc390
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 107 deletions.
Expand Up @@ -40,7 +40,7 @@ object Assets extends Controller {
* @param file the file part extracted from the URL
*/
def at(path: String, file: String): Action[AnyContent] = Action { request =>
// -- LastModified handling
// -- LastModified handling

implicit val dateFormatter = {
val formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz")
Expand Down Expand Up @@ -122,8 +122,6 @@ object Assets extends Controller {

}



private val lastModifieds = (new java.util.concurrent.ConcurrentHashMap[String, String]()).asScala

private def lastModifiedFor(resource: java.net.URL)(implicit dateFormatter: SimpleDateFormat): Option[String] = {
Expand Down
Expand Up @@ -269,11 +269,11 @@ object Promise {
toTraversableLike(in).foldLeft(Promise.pure(cbf(in)))((fr, fa: Promise[B]) => for (r <- fr; a <- fa) yield (r += a)).map(_.result)
}

def sequenceEither[A,B](e:Either[A,Promise[B]]):Promise[Either[A,B]] = e.fold(r => Promise.pure(Left(r)), _.map(Right(_)))

def sequenceEither1[A,B](e:Either[Promise[A],Promise[B]]):Promise[Either[A,B]] = e.fold(_.map(Left(_)), _.map(Right(_)))
def sequenceEither[A, B](e: Either[A, Promise[B]]): Promise[Either[A, B]] = e.fold(r => Promise.pure(Left(r)), _.map(Right(_)))

def sequenceOption[A](o:Option[Promise[A]]):Promise[Option[A]] = o.map(_.map(Some(_))).getOrElse(Promise.pure(None))
def sequenceEither1[A, B](e: Either[Promise[A], Promise[B]]): Promise[Either[A, B]] = e.fold(_.map(Left(_)), _.map(Right(_)))

def sequenceOption[A](o: Option[Promise[A]]): Promise[Option[A]] = o.map(_.map(Some(_))).getOrElse(Promise.pure(None))

}

Expand Up @@ -16,7 +16,7 @@ object Iteratee {
error: (String, Input[E]) => Promise[B]): Promise[B] = i.flatMap(_.fold(done, cont, error))
}

def isDoneOrError[E,A](it:Iteratee[E,A]):Promise[Boolean] = it.pureFold((_,_) => true, _ => false, (_,_) => true)
def isDoneOrError[E, A](it: Iteratee[E, A]): Promise[Boolean] = it.pureFold((_, _) => true, _ => false, (_, _) => true)

/**
* Create an [[play.api.libs.iteratee.Iteratee]] which folds the content of the Input using a given function and an initial state
Expand Down Expand Up @@ -59,12 +59,12 @@ object Iteratee {
(Cont[E, A](i => step(state)(i)))
}

def fold2[E, A](state: A)(f: (A, E) => Promise[(A,Boolean)]): Iteratee[E, A] = {
def fold2[E, A](state: A)(f: (A, E) => Promise[(A, Boolean)]): Iteratee[E, A] = {
def step(s: A)(i: Input[E]): Iteratee[E, A] = i match {

case Input.EOF => Done(s, Input.EOF)
case Input.Empty => Cont[E, A](i => step(s)(i))
case Input.El(e) => { val newS = f(s, e); flatten(newS.map{ case (s1,done) => if(!done) Cont[E, A](i => step(s1)(i)) else Done(s1,Input.Empty) }) }
case Input.El(e) => { val newS = f(s, e); flatten(newS.map { case (s1, done) => if (!done) Cont[E, A](i => step(s1)(i)) else Done(s1, Input.Empty) }) }
}
(Cont[E, A](i => step(state)(i)))
}
Expand Down Expand Up @@ -425,7 +425,7 @@ trait Enumerator[E] {
new Enumerator[U] {
def apply[A](iteratee: Iteratee[U, A]): Promise[Iteratee[U, A]] = {

val folder = Iteratee.fold2[E, Iteratee[U, A]](iteratee)((it, e) => f(e)(it).flatMap(newIt => Iteratee.isDoneOrError(newIt).map((newIt,_))))
val folder = Iteratee.fold2[E, Iteratee[U, A]](iteratee)((it, e) => f(e)(it).flatMap(newIt => Iteratee.isDoneOrError(newIt).map((newIt, _))))
parent(folder).flatMap(_.run)
}
}
Expand Down Expand Up @@ -577,7 +577,7 @@ object Enumeratee {
}

def mapM[E] = new {
def apply[NE](f: E => Promise[NE]): Enumeratee[E, NE] = mapInputM[E]{
def apply[NE](f: E => Promise[NE]): Enumeratee[E, NE] = mapInputM[E] {
case Input.Empty => Promise.pure(Input.Empty)
case Input.EOF => Promise.pure(Input.EOF)
case Input.El(e) => f(e).map(Input.El(_))
Expand Down Expand Up @@ -789,25 +789,25 @@ object Enumeratee {
def continue[A](k: K[M, A]) = Cont(step(k))
}

def onIterateeDone[E](action: () => Unit):Enumeratee[E,E] = new Enumeratee[E,E]{
def onIterateeDone[E](action: () => Unit): Enumeratee[E, E] = new Enumeratee[E, E] {

def applyOn[A](iteratee:Iteratee[E,A]):Iteratee[E,Iteratee[E,A]] = passAlong[E](iteratee).map{ a => action();a}
def applyOn[A](iteratee: Iteratee[E, A]): Iteratee[E, Iteratee[E, A]] = passAlong[E](iteratee).map { a => action(); a }

}

def onEOF[E](action: () => Unit):Enumeratee[E,E] = new CheckDone[E, E] {
def onEOF[E](action: () => Unit): Enumeratee[E, E] = new CheckDone[E, E] {

def step[A](k: K[E, A]): K[E, Iteratee[E, A]] = {
def step[A](k: K[E, A]): K[E, Iteratee[E, A]] = {

case Input.EOF =>
action()
Done(Cont(k), Input.EOF)
case Input.EOF =>
action()
Done(Cont(k), Input.EOF)

case in =>
new CheckDone[E, E] { def continue[A](k: K[E, A]) = Cont(step(k)) } &> k(in)
}
case in =>
new CheckDone[E, E] { def continue[A](k: K[E, A]) = Cont(step(k)) } &> k(in)
}

def continue[A](k: K[E, A]) = Cont(step(k))
def continue[A](k: K[E, A]) = Cont(step(k))

}

Expand Down Expand Up @@ -959,12 +959,12 @@ object Enumerator {

import scalax.io.JavaConverters._

def unfoldM[S,E](s:S)(f: S => Promise[Option[(S,E)]] ): Enumerator[E] = new Enumerator[E] {
def unfoldM[S, E](s: S)(f: S => Promise[Option[(S, E)]]): Enumerator[E] = new Enumerator[E] {
def apply[A](it: Iteratee[E, A]): Promise[Iteratee[E, A]] = {

var iterateeP = Promise[Iteratee[E, A]]()

def step(it: Iteratee[E, A], state:S) {
def step(it: Iteratee[E, A], state: S) {

val next = it.fold(
(a, e) => { iterateeP.redeem(it); Promise.pure(None) },
Expand All @@ -975,17 +975,17 @@ object Enumerator {
iterateeP.redeem(remainingIteratee)
None
}
case Some((s,read)) => {
case Some((s, read)) => {
val nextIteratee = k(Input.El(read))
Some((nextIteratee,s))
Some((nextIteratee, s))
}
}
},
(_, _) => { iterateeP.redeem(it); Promise.pure(None) }
)

next.extend1 {
case Redeemed(Some((i,s))) => step(i,s)
case Redeemed(Some((i, s))) => step(i, s)
case Redeemed(None) => // do nothing, already redeemed
case Thrown(e) => iterateeP.throwing(e)
}
Expand Down Expand Up @@ -1028,7 +1028,7 @@ object Enumerator {
case Redeemed(Some(i)) => step(i)

case Redeemed(None) => onComplete()
case Thrown(e) =>
case Thrown(e) =>
iterateeP.throwing(e)
}
}
Expand Down Expand Up @@ -1066,7 +1066,7 @@ object Enumerator {

next.extend1 {
case Redeemed(Some(i)) => step(i)
case Thrown(e) =>
case Thrown(e) =>
iterateeP.throwing(e)
case _ => onComplete()
}
Expand Down
Expand Up @@ -2,8 +2,7 @@ package play.api.libs.iteratee

object Traversable {


@scala.deprecated("use Enumeratee.passAlong instead","2.1.x")
@scala.deprecated("use Enumeratee.passAlong instead", "2.1.x")
def passAlong[M] = Enumeratee.passAlong[M]

def takeUpTo[M](count: Int)(implicit p: M => scala.collection.TraversableLike[_, M]): Enumeratee[M, M] = new Enumeratee[M, M] {
Expand Down
27 changes: 13 additions & 14 deletions framework/src/play/src/main/scala/play/api/libs/json/Json.scala
Expand Up @@ -35,34 +35,33 @@ object Json {
*/
def fromJson[T](json: JsValue)(implicit fjs: Reads[T]): T = fjs.reads(json)


/**
/**
* Next is the trait that allows Simplified Json syntax :
*
* Example :
* Example :
* JsObject(Seq(
* "key1", JsString("value"),
* "key2" -> JsNumber(123),
* "key1", JsString("value"),
* "key2" -> JsNumber(123),
* "key3" -> JsObject(Seq("key31" -> JsString("value31")))
* ))
* ))
* ====> Json.obj( "key1" -> "value", "key2" -> 123, "key3" -> obj("key31" -> "value31"))
*
* JsArray(JsString("value"), JsNumber(123), JsBoolean(true))
* JsArray(JsString("value"), JsNumber(123), JsBoolean(true))
* ====> Json.arr( "value", 123, true )
*
* There is an implicit conversion from any Type with a Json Writes to JsValueWrapper which is an empty trait that
*
* There is an implicit conversion from any Type with a Json Writes to JsValueWrapper which is an empty trait that
* shouldn't end into unexpected implicit conversions
*
* Something to note due to JsValueWrapper extending NotNull :
* Something to note due to JsValueWrapper extending NotNull :
* - null or None will end into compiling error : use JsNull instead
*/
sealed trait JsValueWrapper extends NotNull

private case class JsValueWrapperImpl(field: JsValue) extends JsValueWrapper
private case class JsValueWrapperImpl(field: JsValue) extends JsValueWrapper

implicit def toJsFieldJsValueWrapper[T](field: T)(implicit w:Writes[T]): JsValueWrapper = JsValueWrapperImpl(w.writes(field))
implicit def toJsFieldJsValueWrapper[T](field: T)(implicit w: Writes[T]): JsValueWrapper = JsValueWrapperImpl(w.writes(field))

def obj(fields: (String, JsValueWrapper) *): JsObject = JsObject( fields.map( f => (f._1, f._2.asInstanceOf[JsValueWrapperImpl].field)))
def arr(fields: JsValueWrapper *): JsArray = JsArray(fields.map(_.asInstanceOf[JsValueWrapperImpl].field))
def obj(fields: (String, JsValueWrapper)*): JsObject = JsObject(fields.map(f => (f._1, f._2.asInstanceOf[JsValueWrapperImpl].field)))
def arr(fields: JsValueWrapper*): JsArray = JsArray(fields.map(_.asInstanceOf[JsValueWrapperImpl].field))

}
Expand Up @@ -138,7 +138,7 @@ trait DefaultReads {
/**
* Deserializer for Array[T] types.
*/
implicit def arrayReads[T : Reads : Manifest]: Reads[Array[T]] = new Reads[Array[T]] {
implicit def arrayReads[T: Reads: Manifest]: Reads[Array[T]] = new Reads[Array[T]] {
def reads(json: JsValue) = json.as[List[T]].toArray
}

Expand Down
Expand Up @@ -102,7 +102,7 @@ trait DefaultWrites {
/**
* Serializer for Traversables types.
*/
implicit def traversableWrites[A : Writes] = new Writes[Traversable[A]] {
implicit def traversableWrites[A: Writes] = new Writes[Traversable[A]] {
def writes(as: Traversable[A]) = JsArray(as.map(toJson(_)).toSeq)
}

Expand Down
Expand Up @@ -30,7 +30,7 @@ object JavaResults extends Results with DefaultWriteables with DefaultContentTyp
val rsp = play.mvc.Http.Context.current().response()
AsyncResult(p.map {
case r: PlainResult =>
r.withHeaders((rsp.getHeaders().asScala -- r.header.headers.keys).toList:_*)
r.withHeaders((rsp.getHeaders().asScala -- r.header.headers.keys).toList: _*)
case r =>
r
})
Expand Down
Expand Up @@ -46,12 +46,12 @@ class NettyServer(appProvider: ApplicationProvider, port: Int, sslPort: Option[I
new org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()))

class PlayPipelineFactory(secure: Boolean = false) extends ChannelPipelineFactory {
def getPipeline = {
val newPipeline = pipeline()
if(secure) {

if (secure) {
val keyStore = KeyStore.getInstance("JKS")
keyStore.load(FakeKeyStore.asInputStream, FakeKeyStore.getKeyStorePassword)
val kmf = KeyManagerFactory.getInstance("SunX509")
Expand All @@ -62,28 +62,28 @@ class NettyServer(appProvider: ApplicationProvider, port: Int, sslPort: Option[I
sslEngine.setUseClientMode(false)
newPipeline.addLast("ssl", new SslHandler(sslEngine))
}

newPipeline.addLast("decoder", new HttpRequestDecoder(4096, 8192, 8192))
newPipeline.addLast("encoder", new HttpResponseEncoder())
newPipeline.addLast("handler", defaultUpStreamHandler)
newPipeline
}
}

// Keep a reference on all opened channels (useful to close everything properly, especially in DEV mode)
val allChannels = new DefaultChannelGroup

// Our upStream handler is stateless. Let's use this instance for every new connection
val defaultUpStreamHandler = new PlayDefaultUpstreamHandler(this, allChannels)

// The HTTP server channel
val HTTP: Bootstrap = {
val bootstrap = newBootstrap
bootstrap.setPipelineFactory(new PlayPipelineFactory)
allChannels.add(bootstrap.bind(new java.net.InetSocketAddress(address, port)))
bootstrap
}

// Maybe the HTTPS server channel
val HTTPS: Option[Bootstrap] = sslPort.map { port =>
val bootstrap = newBootstrap
Expand Down Expand Up @@ -123,10 +123,10 @@ class NettyServer(appProvider: ApplicationProvider, port: Int, sslPort: Option[I

// First, close all opened sockets
allChannels.close().awaitUninterruptibly()

// Release the HTTP server
HTTP.releaseExternalResources()

// Release the HTTPS server if needed
HTTPS.foreach(_.releaseExternalResources())

Expand All @@ -141,7 +141,7 @@ object NettyServer {

import java.io._
import java.net._

/**
* creates a NettyServer based on the application represented by applicationPath
* @param applicationPath path to application
Expand Down
Expand Up @@ -30,7 +30,7 @@ private[server] class PlayDefaultUpstreamHandler(server: Server, allChannels: De
Logger.trace("Exception caught in Netty", e.getCause)
e.getChannel.close()
}

override def channelConnected(ctx: ChannelHandlerContext, e: ChannelStateEvent) {
Option(ctx.getPipeline.get(classOf[SslHandler])).map { sslHandler =>
sslHandler.handshake()
Expand Down Expand Up @@ -252,25 +252,24 @@ private[server] class PlayDefaultUpstreamHandler(server: Server, allChannels: De
k => {
val continue = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE)
e.getChannel.write(continue)

},
(_, _) => ()
)

}
case _ => Promise.pure()
}
}

}

val eventuallyResultOrBody = if (nettyHttpRequest.isChunked) {

val ( result, handler) = newRequestBodyHandler(eventuallyBodyParser,allChannels, server)
val (result, handler) = newRequestBodyHandler(eventuallyBodyParser, allChannels, server)

val p: ChannelPipeline = ctx.getChannel().getPipeline()
p.replace("handler", "handler", handler)
val p: ChannelPipeline = ctx.getChannel().getPipeline()
p.replace("handler", "handler", handler)

result
result

} else {

Expand Down

0 comments on commit f9dc390

Please sign in to comment.