val getQueryParameter[T] =
(request:Request) =>
(name:String) =>
request.query.parameters.get(name).as[T]
abstract class Request[T](val body:Body[T])
extends Query with Header {
def parser:BodyParser[T]
val content:Option[T] = parser(body)
def send(to:Service) = ???
}
case class HttpRequest[T](
method:Method,
body:Body)(implicit parser:BodyParser[T])
extends Request(body) {
// ...
}
Async HTTP
Event driven/Concurrency using Actor
Non-blocking IO (reactive: Iteratee/ CPS)
Stateless
object Dummy extends Controller {
// return async'ly the # of users w/ name start'g w/ q"char"
def countAs = Action.async { request =>
val char = request.queryString("char")
val all:Future[Seq[User]] = users.all // or WS.url
Ok(all.map(_.count(_.name startsWith "a")))
}
}
class UserRepo extends Actor {
var users = Set.empty
def receive = {
case Add(user:User) =>
users = users + user
case All =>
sender ! users
case Get(id:String) =>
user = users.find(_.id == id)
sender ! user
}
}
object AkkaApp extends App {
//...
val repo = system.actorOf(Props[UserRepo])
// add
repo ! Add(User(1L, "")
//get
val user = repo ? Get(1L)
}
val sc = new SparkContext(/*...*/)
lines = sc.textFile("hdfs://...")
errors = lines.filter(_.startsWith("ERROR"))
errors.filter(_.contains("HDFS"))
.map(_.split('\t')(3))
.collect()