com.ecfront.rpc.akka.server.AkkaActor.scala Maven / Gradle / Ivy
package com.ecfront.rpc.akka.server
import java.util.concurrent.Executors
import akka.actor.{Actor, Props}
import com.ecfront.rpc.Router
import com.typesafe.scalalogging.slf4j.LazyLogging
/**
* AKKA Actor
*/
class AkkaActor(router: Router) extends Actor with LazyLogging {
private val executeThreadPool = Executors.newFixedThreadPool(Runtime.getRuntime.availableProcessors() * 4)
def receive = {
case AkkaRequest(method, path, parameter, body) =>
val urlParameter = collection.mutable.Map[String, String]()
parameter.foreach {
item =>
urlParameter += (item._1 -> item._2)
}
val (preResult, fun, postFun) = router.getFunction(method, path, urlParameter)
val sendHandler = sender()
if (preResult) {
executeThreadPool.execute(new Runnable {
override def run(): Unit = {
sendHandler ! postFun(fun.execute(urlParameter.toMap, body, preResult.body))
}
})
} else {
executeThreadPool.execute(new Runnable {
override def run(): Unit = {
sendHandler ! preResult
}
})
}
}
}
object AkkaActor {
private[rpc] def props(router: Router): Props = Props(new AkkaActor(router))
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy