/
AppRouter.scala
75 lines (66 loc) · 2.61 KB
/
AppRouter.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Copyright © 2021 - 2022 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors.
* SPDX-License-Identifier: Apache-2.0
*/
package org.knora.webapi.core
import akka.actor.ActorRef
import akka.actor.Props
import akka.pattern._
import akka.util.Timeout
import zio._
import zio.macros.accessible
import org.knora.webapi.config.AppConfig
import org.knora.webapi.core
import org.knora.webapi.messages.util.KnoraSystemInstances
import org.knora.webapi.messages.v2.responder.SuccessResponseV2
import org.knora.webapi.messages.v2.responder.ontologymessages.LoadOntologiesRequestV2
import org.knora.webapi.settings._
import org.knora.webapi.store.cache.CacheServiceManager
import org.knora.webapi.store.iiif.IIIFServiceManager
import org.knora.webapi.store.triplestore.TriplestoreServiceManager
@accessible
trait AppRouter {
val system: akka.actor.ActorSystem
val ref: ActorRef
val populateOntologyCaches: UIO[Unit]
}
object AppRouter {
val layer: ZLayer[
core.ActorSystem with CacheServiceManager with IIIFServiceManager with TriplestoreServiceManager with AppConfig,
Nothing,
AppRouter
] =
ZLayer {
for {
as <- ZIO.service[core.ActorSystem]
cacheServiceManager <- ZIO.service[CacheServiceManager]
iiifServiceManager <- ZIO.service[IIIFServiceManager]
triplestoreServiceManager <- ZIO.service[TriplestoreServiceManager]
appConfig <- ZIO.service[AppConfig]
runtime <- ZIO.runtime[Any]
} yield new AppRouter {
implicit val system: akka.actor.ActorSystem = as.system
val ref: ActorRef = system.actorOf(
Props(
new core.actors.RoutingActor(
cacheServiceManager,
iiifServiceManager,
triplestoreServiceManager,
appConfig,
runtime
)
),
name = APPLICATION_MANAGER_ACTOR_NAME
)
/* Calls into the OntologyResponderV2 to initiate loading of the ontologies into the cache. */
val populateOntologyCaches: UIO[Unit] = {
val request = LoadOntologiesRequestV2(requestingUser = KnoraSystemInstances.Users.SystemUser)
val timeout = Timeout(new scala.concurrent.duration.FiniteDuration(60, scala.concurrent.duration.SECONDS))
for {
response <- ZIO.fromFuture(_ => (ref.ask(request)(timeout)).mapTo[SuccessResponseV2]).orDie
_ <- ZIO.logInfo(response.message)
} yield ()
}
}
}.tap(_ => ZIO.logInfo(">>> AppRouter Initialized <<<"))
}