aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/com/drivergrp/core/DriverApp.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/com/drivergrp/core/DriverApp.scala')
-rw-r--r--src/main/scala/com/drivergrp/core/DriverApp.scala19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/main/scala/com/drivergrp/core/DriverApp.scala b/src/main/scala/com/drivergrp/core/DriverApp.scala
index 7b991d1..b361c15 100644
--- a/src/main/scala/com/drivergrp/core/DriverApp.scala
+++ b/src/main/scala/com/drivergrp/core/DriverApp.scala
@@ -6,40 +6,41 @@ import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.RouteResult._
import akka.stream.ActorMaterializer
import com.drivergrp.core.logging.{Logger, TypesafeScalaLogger}
+import com.drivergrp.core.module.Module
import com.typesafe.config.Config
import org.slf4j.LoggerFactory
-class DriverApp(services: Seq[Service],
+class DriverApp(modules: Seq[Module],
log: Logger = new TypesafeScalaLogger(
com.typesafe.scalalogging.Logger(LoggerFactory.getLogger(classOf[DriverApp]))),
config: Config = com.drivergrp.core.config.loadDefaultConfig,
interface: String = "localhost", port: Int = 8080) {
def run() = {
- activateServices(services)
- scheduleServicesDeactivation(services)
- bindHttp(services)
+ activateServices(modules)
+ scheduleServicesDeactivation(modules)
+ bindHttp(modules)
}
- protected def bindHttp(services: Seq[Service]) {
+ protected def bindHttp(modules: Seq[Module]) {
implicit val actorSystem = ActorSystem("spray-routing", config)
implicit val executionContext = actorSystem.dispatcher
implicit val materializer = ActorMaterializer()(actorSystem)
- val serviceTypes = services.flatMap(_.serviceTypes)
+ val serviceTypes = modules.flatMap(_.routeTypes)
val swaggerService = new Swagger(actorSystem, serviceTypes, config)
val swaggerRoutes = swaggerService.routes ~ swaggerService.swaggerUI
Http()(actorSystem).bindAndHandle(
- route2HandlerFlow(logRequestResult("log")(services.map(_.route).foldLeft(swaggerRoutes) { _ ~ _ })),
+ route2HandlerFlow(logRequestResult("log")(modules.map(_.route).foldLeft(swaggerRoutes) { _ ~ _ })),
interface, port)(materializer)
}
/**
* Initializes services
*/
- protected def activateServices(services: Seq[Service]) = {
+ protected def activateServices(services: Seq[Module]) = {
services.foreach { service =>
Console.print(s"Service ${service.name} starts ...")
try {
@@ -56,7 +57,7 @@ class DriverApp(services: Seq[Service],
/**
* Schedules services to be deactivated on the app shutdown
*/
- protected def scheduleServicesDeactivation(services: Seq[Service]) = {
+ protected def scheduleServicesDeactivation(services: Seq[Module]) = {
Runtime.getRuntime.addShutdownHook(new Thread() {
override def run(): Unit = {
services.foreach { service =>