diff --git a/integration/src/test/scala/org/knora/webapi/core/ActorSystemTest.scala b/integration/src/test/scala/org/knora/webapi/core/ActorSystemTest.scala index 54be8be062..e95614994d 100644 --- a/integration/src/test/scala/org/knora/webapi/core/ActorSystemTest.scala +++ b/integration/src/test/scala/org/knora/webapi/core/ActorSystemTest.scala @@ -5,11 +5,9 @@ package org.knora.webapi.core -import org.apache.pekko +import org.apache.pekko.actor.ActorSystem import zio.* object ActorSystemTest { - - def layer(sys: pekko.actor.ActorSystem): ZLayer[Any, Nothing, ActorSystem] = - ZLayer.scoped(ZIO.succeed(new ActorSystem { override val system: pekko.actor.ActorSystem = sys })) + def layer(sys: ActorSystem): ZLayer[Any, Nothing, ActorSystem] = ZLayer.succeed(sys) } diff --git a/integration/src/test/scala/org/knora/webapi/core/LayersTest.scala b/integration/src/test/scala/org/knora/webapi/core/LayersTest.scala index b0e7d72b74..b78b76832d 100644 --- a/integration/src/test/scala/org/knora/webapi/core/LayersTest.scala +++ b/integration/src/test/scala/org/knora/webapi/core/LayersTest.scala @@ -85,7 +85,11 @@ object LayersTest { with DspIngestTestContainer with SharedVolumes.Images - type CommonR0 = ActorSystem with AppConfigurationsTest with JwtService with SipiService with StringFormatter + type CommonR0 = pekko.actor.ActorSystem + with AppConfigurationsTest + with JwtService + with SipiService + with StringFormatter type CommonR = ApiRoutes with AdminApiEndpoints diff --git a/integration/src/test/scala/org/knora/webapi/testservices/TestClientService.scala b/integration/src/test/scala/org/knora/webapi/testservices/TestClientService.scala index e1e8f01c5c..e899a27c4a 100644 --- a/integration/src/test/scala/org/knora/webapi/testservices/TestClientService.scala +++ b/integration/src/test/scala/org/knora/webapi/testservices/TestClientService.scala @@ -19,6 +19,7 @@ import org.apache.http.impl.client.HttpClients import org.apache.http.impl.conn.PoolingHttpClientConnectionManager import org.apache.http.util.EntityUtils import org.apache.pekko +import org.apache.pekko.actor.ActorSystem import spray.json.JsObject import spray.json.* import zio.* @@ -33,7 +34,6 @@ import dsp.errors.AssertionException import dsp.errors.BadRequestException import dsp.errors.NotFoundException import org.knora.webapi.config.AppConfig -import org.knora.webapi.core.ActorSystem import org.knora.webapi.messages.store.sipimessages.SipiUploadResponse import org.knora.webapi.messages.store.sipimessages.SipiUploadResponseJsonProtocol.* import org.knora.webapi.messages.store.sipimessages.SipiUploadWithoutProcessingResponse @@ -65,11 +65,10 @@ final case class FileToUpload(path: Path, mimeType: ContentType) */ final case class InputFile(fileToUpload: FileToUpload, width: Int, height: Int) -final case class TestClientService(config: AppConfig, httpClient: CloseableHttpClient, sys: pekko.actor.ActorSystem) +final case class TestClientService(config: AppConfig, httpClient: CloseableHttpClient)(implicit system: ActorSystem) extends TriplestoreJsonProtocol with RequestBuilding { - implicit val system: pekko.actor.ActorSystem = sys implicit val executionContext: ExecutionContext = system.dispatchers.lookup(KnoraDispatchers.KnoraBlockingDispatcher) case class TestClientTimeoutException(msg: String) extends Exception @@ -356,7 +355,7 @@ object TestClientService { /** * Releases the httpClient, freeing all resources. */ - private def release(httpClient: CloseableHttpClient)(implicit system: pekko.actor.ActorSystem) = ZIO.attemptBlocking { + private def release(httpClient: CloseableHttpClient)(implicit system: ActorSystem) = ZIO.attemptBlocking { pekko.http.scaladsl.Http().shutdownAllConnectionPools() httpClient.close() }.tap(_ => ZIO.logDebug(">>> Release Test Client Service <<<")).orDie @@ -366,8 +365,8 @@ object TestClientService { for { sys <- ZIO.service[ActorSystem] config <- ZIO.service[AppConfig] - httpClient <- ZIO.acquireRelease(acquire)(release(_)(sys.system)) - } yield TestClientService(config, httpClient, sys.system) + httpClient <- ZIO.acquireRelease(acquire)(release(_)(sys)) + } yield TestClientService(config, httpClient)(sys) } } diff --git a/webapi/src/main/scala/org/knora/webapi/core/ActorSystem.scala b/webapi/src/main/scala/org/knora/webapi/core/ActorSystem.scala index fbe2595808..24b3c2dac9 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/ActorSystem.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/ActorSystem.scala @@ -5,47 +5,27 @@ package org.knora.webapi.core -import org.apache.pekko +import org.apache.pekko.actor import zio.* -import zio.macros.accessible import scala.concurrent.ExecutionContext -import pekko.actor - -@accessible -trait ActorSystem { - val system: pekko.actor.ActorSystem -} - object ActorSystem { private def acquire(executionContext: ExecutionContext): URIO[Any, actor.ActorSystem] = ZIO - .attempt( - pekko.actor.ActorSystem( - name = "webapi", - config = None, - classLoader = None, - defaultExecutionContext = Some(executionContext), - ), - ) + .attempt(actor.ActorSystem("webapi", None, None, Some(executionContext))) .zipLeft(ZIO.logInfo(">>> Acquire Actor System <<<")) .orDie - private def release(system: pekko.actor.ActorSystem): URIO[Any, actor.Terminated] = - ZIO - .fromFuture(_ => system.terminate()) - .zipLeft(ZIO.logInfo(">>> Release Actor System <<<")) - .orDie + private def release(system: actor.ActorSystem): URIO[Any, actor.Terminated] = + ZIO.fromFuture(_ => system.terminate()).zipLeft(ZIO.logInfo(">>> Release Actor System <<<")).orDie - val layer: ZLayer[Any, Nothing, ActorSystem] = - ZLayer.scoped { + val layer: ZLayer[Any, Nothing, actor.ActorSystem] = + ZLayer.scoped( for { - context <- ZIO.executor.map(_.asExecutionContext) - actorSystem <- ZIO.acquireRelease(acquire(context))(release) - } yield new ActorSystem { - override val system: pekko.actor.ActorSystem = actorSystem - } - } + context <- ZIO.executor.map(_.asExecutionContext) + system <- ZIO.acquireRelease(acquire(context))(release) + } yield system, + ) } diff --git a/webapi/src/main/scala/org/knora/webapi/core/AppRouter.scala b/webapi/src/main/scala/org/knora/webapi/core/AppRouter.scala index d3452f7ea3..0a498b965a 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/AppRouter.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/AppRouter.scala @@ -32,14 +32,14 @@ trait AppRouter { object AppRouter { val layer: ZLayer[ - core.ActorSystem & CardinalityHandler & CardinalityService & ConstructResponseUtilV2 & MessageRelay & + pekko.actor.ActorSystem & CardinalityHandler & CardinalityService & ConstructResponseUtilV2 & MessageRelay & OntologyCache & OntologyHelpers & OntologyRepo & PermissionUtilADM & ResourceUtilV2 & StandoffTagUtilV2, Nothing, AppRouter, ] = ZLayer { for { - as <- ZIO.service[core.ActorSystem] + as <- ZIO.service[pekko.actor.ActorSystem] messageRelay <- ZIO.service[MessageRelay] runtime <- ZIO.runtime[ @@ -47,7 +47,7 @@ object AppRouter { OntologyRepo & PermissionUtilADM & ResourceUtilV2 & StandoffTagUtilV2, ] } yield new AppRouter { - implicit val system: org.apache.pekko.actor.ActorSystem = as.system + implicit val system: org.apache.pekko.actor.ActorSystem = as val ref: ActorRef = system.actorOf( Props( diff --git a/webapi/src/main/scala/org/knora/webapi/core/AppServer.scala b/webapi/src/main/scala/org/knora/webapi/core/AppServer.scala index 27f1232c43..e0f06bf004 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/AppServer.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/AppServer.scala @@ -5,6 +5,7 @@ package org.knora.webapi.core +import org.apache.pekko.actor import zio.* import org.knora.webapi.config.AppConfig @@ -26,7 +27,7 @@ final case class AppServer( state: State, ts: TriplestoreService, ru: RepositoryUpdater, - as: ActorSystem, + as: actor.ActorSystem, ontologyCache: OntologyCache, sipiService: SipiService, hs: HttpServer, @@ -136,7 +137,7 @@ final case class AppServer( object AppServer { private type AppServerEnvironment = - State & TriplestoreService & RepositoryUpdater & ActorSystem & OntologyCache & SipiService & HttpServer & AppConfig + State & TriplestoreService & RepositoryUpdater & actor.ActorSystem & OntologyCache & SipiService & HttpServer & AppConfig /** * Initializes the AppServer instance with the required services @@ -146,7 +147,7 @@ object AppServer { state <- ZIO.service[State] ts <- ZIO.service[TriplestoreService] ru <- ZIO.service[RepositoryUpdater] - as <- ZIO.service[ActorSystem] + as <- ZIO.service[actor.ActorSystem] oc <- ZIO.service[OntologyCache] iiifs <- ZIO.service[SipiService] hs <- ZIO.service[HttpServer] diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServer.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServer.scala index 6a5c4832c6..9bbc27d04c 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServer.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServer.scala @@ -5,15 +5,13 @@ package org.knora.webapi.core -import org.apache.pekko +import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.http.scaladsl.Http import zio.* import org.knora.webapi.config.AppConfig -import org.knora.webapi.core import org.knora.webapi.routing.ApiRoutes -import pekko.http.scaladsl.Http - /** * The Akka based HTTP server */ @@ -25,11 +23,11 @@ object HttpServer { val layer: ZLayer[ActorSystem & AppConfig & ApiRoutes, Nothing, HttpServer] = ZLayer.scoped { for { - as <- ZIO.service[core.ActorSystem] + as <- ZIO.service[ActorSystem] config <- ZIO.service[AppConfig] apiRoutes <- ZIO.service[ApiRoutes] binding <- { - implicit val system: pekko.actor.ActorSystem = as.system + implicit val system: ActorSystem = as ZIO.acquireRelease { ZIO diff --git a/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala b/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala index 9fe8bb17c1..1bbfe44227 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala @@ -5,6 +5,7 @@ package org.knora.webapi.core +import org.apache.pekko.actor.ActorSystem import zio.ULayer import zio.ZLayer @@ -93,7 +94,7 @@ object LayersLive { */ val dspLayersLive: ULayer[DspEnvironmentLive] = ZLayer.make[DspEnvironmentLive]( - ActorSystem.layer, + org.knora.webapi.core.ActorSystem.layer, AdminApiEndpoints.layer, AdminApiRoutes.layer, ApiRoutes.layer, diff --git a/webapi/src/main/scala/org/knora/webapi/routing/ApiRoutes.scala b/webapi/src/main/scala/org/knora/webapi/routing/ApiRoutes.scala index 5c404d1c5f..edc5e047bb 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/ApiRoutes.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/ApiRoutes.scala @@ -5,7 +5,7 @@ package org.knora.webapi.routing -import org.apache.pekko.actor +import org.apache.pekko.actor.ActorSystem import org.apache.pekko.http.cors.scaladsl.CorsDirectives import org.apache.pekko.http.cors.scaladsl.settings.CorsSettings import org.apache.pekko.http.scaladsl.model.HttpMethods.* @@ -15,7 +15,6 @@ import zio.* import org.knora.webapi.config.AppConfig import org.knora.webapi.core -import org.knora.webapi.core.ActorSystem import org.knora.webapi.core.AppRouter import org.knora.webapi.core.MessageRelay import org.knora.webapi.http.directives.DSPApiDirectives @@ -61,7 +60,7 @@ object ApiRoutes { resourceInfoRoutes <- ZIO.service[ResourceInfoRoutes] searchApiRoutes <- ZIO.service[SearchApiRoutes] managementRoutes <- ZIO.service[ManagementRoutes] - routeData <- ZIO.succeed(KnoraRouteData(sys.system, router.ref, appConfig)) + routeData <- ZIO.succeed(KnoraRouteData(sys, router.ref, appConfig)) runtime <- ZIO.runtime[ AppConfig & AuthorizationRestService & core.State & IriConverter & KnoraProjectRepo & MessageRelay & ProjectADMRestService & RestCardinalityService & RestResourceInfoService & routing.Authenticator & SearchApiRoutes & SearchResponderV2 & SipiService & StringFormatter & UserService & ValuesResponderV2, @@ -98,7 +97,7 @@ private final case class ApiRoutesImpl( ) extends ApiRoutes with AroundDirectives { - private implicit val system: actor.ActorSystem = routeData.system + private implicit val system: ActorSystem = routeData.system val routes: Route = logDuration { diff --git a/webapi/src/main/scala/org/knora/webapi/slice/common/api/TapirToPekkoInterpreter.scala b/webapi/src/main/scala/org/knora/webapi/slice/common/api/TapirToPekkoInterpreter.scala index 47174a2e31..f46a8077bb 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/common/api/TapirToPekkoInterpreter.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/common/api/TapirToPekkoInterpreter.scala @@ -5,6 +5,7 @@ package org.knora.webapi.slice.common.api +import org.apache.pekko.actor.ActorSystem import org.apache.pekko.http.scaladsl.server.Route import sttp.capabilities.WebSockets import sttp.capabilities.pekko.PekkoStreams @@ -22,10 +23,8 @@ import zio.json.JsonCodec import scala.concurrent.ExecutionContext import scala.concurrent.Future -import org.knora.webapi.core.ActorSystem - -final case class TapirToPekkoInterpreter()(actorSystem: ActorSystem) { - implicit val executionContext: ExecutionContext = actorSystem.system.dispatcher +final case class TapirToPekkoInterpreter()(system: ActorSystem) { + implicit val executionContext: ExecutionContext = system.dispatcher private case class GenericErrorResponse(error: String) private object GenericErrorResponse { implicit val codec: JsonCodec[GenericErrorResponse] = DeriveJsonCodec.gen[GenericErrorResponse]