Browse files

Some refinements, added structure.dot

  • Loading branch information...
1 parent 07fc91d commit 20eb138a0615c6a71d50baccc3511f79156391df @joa committed May 7, 2012
View
48 hector-web/src/main/scala/hector/actor/IOActor.scala
@@ -1,7 +1,53 @@
package hector.actor
+import java.nio.charset.{Charset JCharset}
+import hector.http.io.{HttpRequestInputActor, HttpResponseOutputActor}
+import akka.actor.{OneForOneStrategy, Props, ActorRef, Actor}
+import java.io.{IOException, OutputStream JOutputStream, InputStream JInputStream}
+import hector.Hector
+import stats.ExceptionOccurred
+import akka.actor.SupervisorStrategy.{Escalate, Stop}
+
+
/**
*/
-final class IOActor {
+private[actor] object IOActor {
+ case class NewOutput(receiver: ActorRef, encoding: JCharset, output: JOutputStream)
+ case class NewInput(receiver: ActorRef, encoding: JCharset, input: JInputStream)
+}
+
+private[actor] final class IOActor extends Actor {
+ import IOActor._
+
+ override val supervisorStrategy = OneForOneStrategy() {
+ case exception: IOException
+
+ //
+ // When an IOException occurs we usually expect a closed connection and
+ // it makes no sense to restart the actor.
+ //
+
+ Hector.statistics ! ExceptionOccurred(exception)
+ Stop
+
+ case _
+
+ //
+ // Something other than an IOException happened. Therefore we are
+ // no longer able to identify what we should do and escalate the
+ // problem to the parent.
+ //
+
+ Escalate
+ }
+
+ override protected def receive = {
+ case NewOutput(receiver, encoding, output)
+ val outputActor = context.actorOf(Props(new HttpResponseOutputActor(encoding, output)))
+ receiver ! outputActor
+ case NewInput(receiver, encoding, input)
+ val inputActor = context.actorOf(Props(new HttpRequestInputActor(encoding, input)))
+ receiver ! inputActor
+ }
}
View
3 hector-web/src/main/scala/hector/actor/RequestActor.scala
@@ -34,6 +34,9 @@ final class RequestActor extends Actor with ActorLogging {
withRouter(
RoundRobinRouter(resizer = Some(DefaultResizer(lowerBound = 1, upperBound = 10)))))
+ private[this] val io =
+ context.actorOf(Props[IOActor])
+
override protected def receive = {
case HandleAsync(asyncContext)
import akka.pattern.pipe
View
1 hector-web/src/main/scala/hector/http/HttpResponse.scala
@@ -50,7 +50,6 @@ trait HttpResponse extends Serializable {
*/
def contentType: String
-
/**
* The encoding used for the response.
*
View
13 hector-web/src/main/scala/hector/http/io/HttpRequestInputActor.scala
@@ -1,7 +1,16 @@
package hector.http.io
+import akka.actor.Actor
+
+import java.nio.charset.{Charset JCharset}
+import java.io.{InputStream JInputStream}
+
/**
*/
-final class HttpRequestInputActor {
-
+final class HttpRequestInputActor(
+ private[this] val encoding: JCharset,
+ private[this] val input: JInputStream) extends Actor {
+ override protected def receive = {
+ case _
+ }
}
View
0 setup.dot
No changes.

0 comments on commit 20eb138

Please sign in to comment.