@@ -4,12 +4,12 @@ import akka.actor.{Actor, ActorLogging, Props}
44import com .sksamuel .elastic4s .IndexAndType
55import com .sksamuel .elastic4s .http .ElasticDsl ._
66import com .sksamuel .elastic4s .http .HttpClient
7- import de .upb .cs .swt .delphi .webapi .ElasticActor . GetSource
7+ import de .upb .cs .swt .delphi .webapi .ElasticActorManager .{ Enqueue , Retrieve }
88
99import scala .concurrent .ExecutionContext
1010import scala .concurrent .duration ._
1111
12- class ElasticActor (configuration : Configuration ) extends Actor with ActorLogging {
12+ class ElasticActor (configuration : Configuration , index : IndexAndType ) extends Actor with ActorLogging {
1313
1414 implicit val executionContext : ExecutionContext = context.system.dispatchers.lookup(" elasticsearch-handling-dispatcher" )
1515 val client = HttpClient (configuration.elasticsearchClientUri)
@@ -19,21 +19,23 @@ class ElasticActor(configuration: Configuration) extends Actor with ActorLogging
1919 context.setReceiveTimeout(2 seconds)
2020
2121 override def receive = {
22- case GetSource (id, index) => {
23- log.info(" Executing get on entry {}" , id)
24- def source = client.execute{
25- get(id).from(index)
26- }.await match {
27- case Right (res) => res.body.get
28- case Left (_) => Option .empty
29- }
30- sender().tell(source, context.self)
22+ case Enqueue (id) => getSource(id)
23+ case Retrieve (id) => getSource(id)
24+ }
25+
26+ private def getSource (id : String ) = {
27+ log.info(" Executing get on entry {}" , id)
28+ def source = client.execute{
29+ get(id).from(index)
30+ }.await match {
31+ case Right (res) => res.body.get
32+ case Left (_) => Option .empty
3133 }
34+ sender().tell(source, context.self)
3235 }
3336}
3437
3538object ElasticActor {
36- def props (configuration : Configuration ) : Props = Props (new ElasticActor (configuration))
37-
38- final case class GetSource (id : String , index : IndexAndType )
39+ def props (configuration : Configuration , index : IndexAndType ) : Props = Props (new ElasticActor (configuration, index))
40+ .withMailbox(" es-priority-mailbox" )
3941}
0 commit comments