ScalaDays 2014-06-17@Berlin
Mathias Doenitz
/
/
This presentation: http://spray.io/scaladays2014/
Isn't this "feature creep"?
Too high-level?
Where is the connection to its "actor heart"?
"A toolkit and runtime for building
highly concurrent, distributed, and fault-tolerant
event-driven applications on the JVM"
"Build powerful
concurrent
concurrent
&
distributed
distributed
applications more easily"
case class ServerBinding(
localAddress: InetSocketAddress,
connectionStream: Producer[IncomingConnection])
case class IncomingConnection(
remoteAddress: InetSocketAddress,
requestProducer: Producer[HttpRequest],
responseConsumer: Consumer[HttpResponse])
val bindingFuture = IO(Http) ? Http.Bind("localhost", 8080)
bindingFuture foreach { binding ⇒
Flow(binding.connectionStream) foreach { connection ⇒
Flow(connection.requestProducer).map {
case HttpRequest(GET, Uri.Path("/ping"), _, _, _) ⇒
HttpResponse(entity = "PONG!")
case _ ⇒ HttpResponse(404, entity = "Unknown resource!")
}.produceTo(connection.responseOut)
}
}
case class OutgoingConnection(
remoteAddress: InetSocketAddress,
localAddress: InetSocketAddress,
processor: HttpClientProcessor[Any])
trait HttpClientProcessor[T]
extends Consumer[(HttpRequest, T)]
with Producer[(HttpResponse, T)]
case class HttpRequest(
method: HttpMethod = HttpMethods.GET,
uri: Uri = Uri./,
headers: immutable.Seq[HttpHeader] = Nil,
entity: HttpEntity.Regular = HttpEntity.Empty,
protocol: HttpProtocol = HttpProtocols.`HTTP/1.1`
) extends HttpMessage
case class HttpResponse(
status: StatusCode = StatusCodes.OK,
headers: immutable.Seq[HttpHeader] = Nil,
entity: HttpEntity = HttpEntity.Empty,
protocol: HttpProtocol = HttpProtocols.`HTTP/1.1`
) extends HttpMessage
sealed trait HttpEntity
object HttpEntity {
sealed trait Regular extends HttpEntity
case class Strict(contentType: ContentType,
data: ByteString) extends Regular
case class Default(contentType: ContentType, contentLength: Long,
data: Producer[ByteString]) extends Regular
case class Chunked(contentType: ContentType,
chunks: Producer[ChunkStreamPart]) extends Regular
case class CloseDelimited(contentType: ContentType,
data: Producer[ByteString]) extends HttpEntity
}