/
StoreManager.scala
103 lines (91 loc) · 3.99 KB
/
StoreManager.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Copyright © 2015-2021 the contributors (see Contributors.md).
*
* This file is part of Knora.
*
* Knora is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Knora is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with Knora. If not, see <http://www.gnu.org/licenses/>.
*/
package org.knora.webapi.store
import akka.actor._
import akka.event.LoggingReceive
import org.knora.webapi.core.{LiveActorMaker, _}
import org.knora.webapi.exceptions.UnexpectedMessageException
import org.knora.webapi.feature.{FeatureFactoryConfig, KnoraSettingsFeatureFactoryConfig}
import org.knora.webapi.messages.store.cacheservicemessages.CacheServiceRequest
import org.knora.webapi.messages.store.sipimessages.IIIFRequest
import org.knora.webapi.messages.store.triplestoremessages.TriplestoreRequest
import org.knora.webapi.settings.{KnoraDispatchers, KnoraSettings, KnoraSettingsImpl, _}
import org.knora.webapi.store.cacheservice.{CacheService, CacheServiceManager}
import org.knora.webapi.store.iiif.IIIFManager
import org.knora.webapi.store.triplestore.TriplestoreManager
import scala.concurrent.ExecutionContext
/**
* This actor receives messages for different stores, and forwards them to the corresponding store manager.
* At the moment only triple stores and Sipi are implemented, but in the future, support for different
* remote repositories will probably be needed. This place would then be the crossroad for these different kinds
* of 'stores' and their requests.
*
* @param appActor a reference to the main application actor.
*/
class StoreManager(appActor: ActorRef, cs: CacheService) extends Actor with ActorLogging {
this: ActorMaker =>
/**
* The Knora Akka actor system.
*/
protected implicit val system: ActorSystem = context.system
/**
* The Akka actor system's execution context for futures.
*/
protected implicit val executionContext: ExecutionContext =
system.dispatchers.lookup(KnoraDispatchers.KnoraActorDispatcher)
/**
* The Knora settings.
*/
protected val settings: KnoraSettingsImpl = KnoraSettings(system)
/**
* The default feature factory configuration.
*/
protected val defaultFeatureFactoryConfig: FeatureFactoryConfig = new KnoraSettingsFeatureFactoryConfig(settings)
/**
* Starts the Triplestore Manager Actor
*/
protected lazy val triplestoreManager: ActorRef = makeActor(
Props(
new TriplestoreManager(
appActor = appActor,
settings = settings,
defaultFeatureFactoryConfig = defaultFeatureFactoryConfig
) with LiveActorMaker).withDispatcher(KnoraDispatchers.KnoraActorDispatcher),
TriplestoreManagerActorName
)
/**
* Starts the IIIF Manager Actor
*/
protected lazy val iiifManager: ActorRef = makeActor(
Props(new IIIFManager with LiveActorMaker).withDispatcher(KnoraDispatchers.KnoraActorDispatcher),
IIIFManagerActorName)
/**
* Instantiates the Redis Manager
*/
protected lazy val cacheServiceManager: ActorRef = makeActor(
Props(new CacheServiceManager(cs)).withDispatcher(KnoraDispatchers.KnoraActorDispatcher),
RedisManagerActorName)
def receive: Receive = LoggingReceive {
case tripleStoreMessage: TriplestoreRequest => triplestoreManager forward tripleStoreMessage
case iiifMessages: IIIFRequest => iiifManager forward iiifMessages
case cacheServiceMessages: CacheServiceRequest => cacheServiceManager forward cacheServiceMessages
case other =>
sender ! Status.Failure(UnexpectedMessageException(s"StoreManager received an unexpected message: $other"))
}
}