@@ -4,12 +4,12 @@ import akka.actor.{Actor, ActorLogging, Props}
4
4
import com .sksamuel .elastic4s .IndexAndType
5
5
import com .sksamuel .elastic4s .http .ElasticDsl ._
6
6
import 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 }
8
8
9
9
import scala .concurrent .ExecutionContext
10
10
import scala .concurrent .duration ._
11
11
12
- class ElasticActor (configuration : Configuration ) extends Actor with ActorLogging {
12
+ class ElasticActor (configuration : Configuration , index : IndexAndType ) extends Actor with ActorLogging {
13
13
14
14
implicit val executionContext : ExecutionContext = context.system.dispatchers.lookup(" elasticsearch-handling-dispatcher" )
15
15
val client = HttpClient (configuration.elasticsearchClientUri)
@@ -19,21 +19,23 @@ class ElasticActor(configuration: Configuration) extends Actor with ActorLogging
19
19
context.setReceiveTimeout(2 seconds)
20
20
21
21
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
31
33
}
34
+ sender().tell(source, context.self)
32
35
}
33
36
}
34
37
35
38
object 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" )
39
41
}
0 commit comments