com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents Scala Examples

The following examples show how to use com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: WebGatewayLoader.scala    From Scala-Reactive-Programming   with MIT License 5 votes vote down vote up
import javax.inject.Inject
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.api.{ServiceAcl, ServiceInfo}
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.packt.publishing.wf.api.WFService
import com.packt.publishing.wf.consumer.api.WFConsumerService
import com.softwaremill.macwire._
import controllers.{Assets, WFConsumerController, WFController}
import play.api.ApplicationLoader.Context
import play.api.i18n.I18nComponents
import play.api.libs.ws.ahc.AhcWSComponents
import play.api._
import play.api.Play.current
import play.api.i18n.Messages.Implicits._
import router.Routes

import scala.collection.immutable
import scala.concurrent.ExecutionContext

abstract class WebGateway @Inject()(context: Context) extends BuiltInComponentsFromContext(context)
  with I18nComponents
  with AhcWSComponents
  with LagomServiceClientComponents{

  override lazy val serviceInfo: ServiceInfo = ServiceInfo(
    "wf-frontend",
    Map(
      "wf-frontend" -> immutable.Seq(ServiceAcl.forPathRegex("(?!/api/).*"))
    )
  )
  override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher
  override lazy val router = {
    val prefix = "/"
    wire[Routes]
  }

  lazy val wfService = serviceClient.implement[WFService]
  lazy val wfConsumerService = serviceClient.implement[WFConsumerService]
  lazy val wfController = wire[WFController]
  lazy val wfConsumerController = wire[WFConsumerController]
  lazy val assets = wire[Assets]
}

class WebGatewayLoader extends ApplicationLoader {
  override def load(context: Context): Application = context.environment.mode match {
    case Mode.Dev =>
      new WebGateway(context) with LagomDevModeComponents {}.application
    case _ =>
      new WebGateway(context) {
        override def serviceLocator = NoServiceLocator
      }.application
  }
} 
Example 2
Source File: Loader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
import play.api.Application
import play.api.ApplicationLoader
import play.api.BuiltInComponentsFromContext
import play.api.libs.ws.ahc.AhcWSComponents
import com.softwaremill.macwire._
import router.Routes
import com.lightbend.lagom.scaladsl.api._
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import scala.collection.immutable

class Loader extends ApplicationLoader {
  def load(context: ApplicationLoader.Context): Application = {
    new BuiltInComponentsFromContext(context) with LagomServiceClientComponents with AhcWSComponents
    with LagomDevModeComponents with controllers.AssetsComponents {
      override lazy val serviceInfo = ServiceInfo(
        "p",
        Map(
          "p" -> immutable.Seq(
            ServiceAcl.forPathRegex("/p"),
            ServiceAcl.forPathRegex("/assets/.*")
          )
        )
      )
      override lazy val router = {
        val prefix = "/"
        wire[Routes]
      }
      override lazy val httpFilters  = Nil
      lazy val applicationController = wire[controllers.Application]
    }.application
  }
} 
Example 3
Source File: FooLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package impl

import java.nio.file.Files
import java.nio.file.StandardOpenOption
import java.util.Date

import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import api.FooService
import com.softwaremill.macwire._

class FooLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new FooApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new FooApplication(context) with LagomDevModeComponents
}

abstract class FooApplication(context: LagomApplicationContext) extends LagomApplication(context) with AhcWSComponents {

  override lazy val lagomServer = serverFor[FooService](wire[FooServiceImpl])

  Files.write(
    environment.getFile("target/reload.log").toPath,
    s"${new Date()} - reloaded\n".getBytes("utf-8"),
    StandardOpenOption.CREATE,
    StandardOpenOption.APPEND
  )
} 
Example 4
Source File: BarLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package impl

import api.BarService
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.cluster.ClusterComponents
import com.lightbend.lagom.scaladsl.playjson.EmptyJsonSerializerRegistry
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents

class BarLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new BarApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BarApplication(context) with LagomDevModeComponents
}

abstract class BarApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents
    with ClusterComponents {

  override lazy val lagomServer = serverFor[BarService](wire[BarServiceImpl])

  lazy val jsonSerializerRegistry = EmptyJsonSerializerRegistry
} 
Example 5
Source File: FooLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package impl

import api.FooService
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.cluster.ClusterComponents
import com.lightbend.lagom.scaladsl.playjson.EmptyJsonSerializerRegistry
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents

class FooLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new FooApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new FooApplication(context) with LagomDevModeComponents
}

abstract class FooApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents
    with ClusterComponents {

  override lazy val lagomServer = serverFor[FooService](wire[FooServiceImpl])

  lazy val jsonSerializerRegistry = EmptyJsonSerializerRegistry
} 
Example 6
Source File: AkkaDiscoveryIntegration.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package docs.scaladsl.production.overview

package akkadiscoveryservicelocator {
  import docs.scaladsl.services.lagomapplication.HelloApplication

  //#akka-discovery-service-locator
  import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
  import com.lightbend.lagom.scaladsl.server._
  import com.lightbend.lagom.scaladsl.akka.discovery.AkkaDiscoveryComponents

  class HelloApplicationLoader extends LagomApplicationLoader {
    override def load(context: LagomApplicationContext) =
      new HelloApplication(context) with AkkaDiscoveryComponents

    override def loadDevMode(context: LagomApplicationContext) =
      new HelloApplication(context) with LagomDevModeComponents
  }
  //#akka-discovery-service-locator
} 
Example 7
Source File: ProductionOverview.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package docs.scaladsl.production.overview

package configurationservicelocator {
  import docs.scaladsl.services.lagomapplication.HelloApplication

  //#configuration-service-locator
  import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
  import com.lightbend.lagom.scaladsl.server._
  import com.lightbend.lagom.scaladsl.client.ConfigurationServiceLocatorComponents

  class HelloApplicationLoader extends LagomApplicationLoader {
    override def load(context: LagomApplicationContext) =
      new HelloApplication(context) with ConfigurationServiceLocatorComponents

    override def loadDevMode(context: LagomApplicationContext) =
      new HelloApplication(context) with LagomDevModeComponents
  }
  //#configuration-service-locator
} 
Example 8
Source File: JdbcBlogApplicationLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package docs.home.scaladsl.persistence

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.jdbc.JdbcPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.db.HikariCPComponents
import play.api.libs.ws.ahc.AhcWSComponents

class JdbcBlogApplicationLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new BlogApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BlogApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[BlogService])
}

//#load-components
abstract class BlogApplication(context: LagomApplicationContext)
    extends LagomApplication(context)
    with JdbcPersistenceComponents
    with HikariCPComponents
    with AhcWSComponents {
//#load-components

  // Bind the services that this server provides
  override lazy val lagomServer = ???

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = BlogPostSerializerRegistry

  // Register the Blog application persistent entity
  persistentEntityRegistry.register(wire[Post])
} 
Example 9
Source File: LeagueLoader.scala    From eventsourcing-intro   with Apache License 2.0 5 votes vote down vote up
package eu.reactivesystems.league.impl

import akka.actor.PoisonPill
import akka.cluster.singleton.{
  ClusterSingletonManager,
  ClusterSingletonManagerSettings
}
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.WriteSideCassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.persistence.jdbc.ReadSideJdbcPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{
  JsonSerializer,
  JsonSerializerRegistry
}
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import com.softwaremill.macwire.akkasupport._
import eu.reactivesystems.league.api.LeagueService
import play.api.db.HikariCPComponents
import play.api.libs.ws.ahc.AhcWSComponents

import scala.collection.immutable.Seq

class LeagueLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new LeagueApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(
      context: LagomApplicationContext): LagomApplication =
    new LeagueApplication(context) with LagomDevModeComponents

  override def describeServices = List(
    readDescriptor[LeagueService]
  )
}

abstract class LeagueApplication(context: LagomApplicationContext)
    extends LagomApplication(context)
    with WriteSideCassandraPersistenceComponents
    with ReadSideJdbcPersistenceComponents
    with HikariCPComponents
    with AhcWSComponents {

  // Bind the service that this server provides
  override lazy val lagomServer =
    serverFor[LeagueService](wire[LeagueServiceImpl])

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = LeagueSerializerRegistry

  // Register the league persistent entity
  persistentEntityRegistry.register(wire[LeagueEntity])

  // Register read side processor

  val leagueProjectionProps = wireProps[LeagueProjection]

  actorSystem.actorOf(
    ClusterSingletonManager.props(
      singletonProps = leagueProjectionProps,
      terminationMessage = PoisonPill,
      settings = ClusterSingletonManagerSettings(actorSystem)),
    name = "leagueProjection"
  )

}


object LeagueSerializerRegistry extends JsonSerializerRegistry {
  override def serializers: Seq[JsonSerializer[_]] = Seq(
    JsonSerializer[AddClub],
    JsonSerializer[AddGame],
    JsonSerializer[ChangeGame],
    JsonSerializer[ClubRegistered],
    JsonSerializer[GamePlayed],
    JsonSerializer[ResultRevoked],
    JsonSerializer[LeagueState]
  )
} 
Example 10
Source File: TelegramBotServiceLoader.scala    From lagom-on-kube   with Apache License 2.0 5 votes vote down vote up
package me.alexray.telegramBot.impl

import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import me.alexray.telegramBot.api.TelegramBotService
import com.softwaremill.macwire._
import me.alexray.lagom.kube.client.LagomKubeModeComponents
import me.alexray.wolfram.api.WolframService

class TelegramBotServiceLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new TelegramBotServiceApplication(context) with LagomKubeModeComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new TelegramBotServiceApplication(context) with LagomKubeModeComponents

  override def describeServices = List(
    readDescriptor[TelegramBotService]
  )
}

abstract class TelegramBotServiceApplication(context: LagomApplicationContext)
  extends LagomApplication(context) with AhcWSComponents
{
  // Bind the service that this server provides
  override lazy val lagomServer: LagomServer = serverFor[TelegramBotService](wire[TelegramBotServiceImpl])

  // Bind the TwbService client
  lazy val wolframService: WolframService = serviceClient.implement[WolframService]
} 
Example 11
Source File: WFLoader.scala    From Scala-Reactive-Programming   with MIT License 5 votes vote down vote up
package com.packt.publishing.wf.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.publishing.wf.api.WFService

class WFLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new WFApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new WFApplication(context) with LagomDevModeComponents
}

abstract class WFApplication(context: LagomApplicationContext) extends WFComponents(context)
  with LagomKafkaComponents {

}

abstract class WFComponents(context: LagomApplicationContext) extends LagomApplication(context)
  with CassandraPersistenceComponents
  with AhcWSComponents {

  override lazy val lagomServer = LagomServer.forServices(
    bindService[WFService].to(wire[WFServiceImpl])
  )

  override lazy val jsonSerializerRegistry = WFSerializerRegistry

  persistentEntityRegistry.register(wire[WFEntity])
} 
Example 12
Source File: BazLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package impl

import java.nio.file.Files
import java.nio.file.StandardOpenOption
import java.util.Date

import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import api.BazService
import com.softwaremill.macwire._

class BazLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new BazApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BazApplication(context) with LagomDevModeComponents
}

abstract class BazApplication(context: LagomApplicationContext) extends LagomApplication(context) with AhcWSComponents {

  override lazy val lagomServer = serverFor[BazService](wire[BazServiceImpl])

  Files.write(
    environment.getFile("target/reload.log").toPath,
    s"${new Date()} - reloaded\n".getBytes("utf-8"),
    StandardOpenOption.CREATE,
    StandardOpenOption.APPEND
  )
} 
Example 13
Source File: WFConsumerLoader.scala    From Scala-Reactive-Programming   with MIT License 5 votes vote down vote up
package com.packt.publishing.wf.consumer.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server.{LagomApplication, LagomApplicationContext, LagomApplicationLoader, LagomServer}
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.publishing.wf.api.WFService
import com.packt.publishing.wf.consumer.api.WFConsumerService
import com.packt.publishing.wf.consumer.impl.repositories.WFRepository

class WFConsumerLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new WFConsumerApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new WFConsumerApplication(context) with LagomDevModeComponents
}

abstract class WFConsumerApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with CassandraPersistenceComponents
    with LagomKafkaComponents
    with AhcWSComponents {

  // Bind the services that this server provides
  override lazy val lagomServer = LagomServer.forServices(
    bindService[WFConsumerService].to(wire[WFConsumerServiceImpl])
  )

  //Bind the WFService client
  lazy val wfService = serviceClient.implement[WFService]

  lazy val messageRepository = wire[WFRepository]

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = WFConsumerSerializerRegistry

  // Register the Message persistent entity
   persistentEntityRegistry.register(wire[WFEntity])

  readSide.register(wire[WFEventProcessor])
} 
Example 14
Source File: LagomscalahelloserviceLoader.scala    From Scala-Reactive-Programming   with MIT License 5 votes vote down vote up
package com.packt.publishing.lagomscalahelloservice.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.publishing.lagomscalahelloservice.api.LagomscalahelloserviceService
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.softwaremill.macwire._
import com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents

class LagomscalahelloserviceLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new LagomscalahelloserviceApplication(context) with ConductRApplicationComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new LagomscalahelloserviceApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[LagomscalahelloserviceService])
}

abstract class LagomscalahelloserviceApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with CassandraPersistenceComponents
    with LagomKafkaComponents
    with AhcWSComponents {

  // Bind the service that this server provides
  override lazy val lagomServer = serverFor[LagomscalahelloserviceService](wire[LagomscalahelloserviceServiceImpl])

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = LagomscalahelloserviceSerializerRegistry

  // Register the lagom-scala-hello-service persistent entity
  persistentEntityRegistry.register(wire[LagomscalahelloserviceEntity])
} 
Example 15
package com.packt.publishing.lagomscalahelloservicestream.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.publishing.lagomscalahelloservicestream.api.LagomscalahelloserviceStreamService
import com.packt.publishing.lagomscalahelloservice.api.LagomscalahelloserviceService
import com.softwaremill.macwire._
import com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents

class LagomscalahelloserviceStreamLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new LagomscalahelloserviceStreamApplication(context) with ConductRApplicationComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new LagomscalahelloserviceStreamApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[LagomscalahelloserviceStreamService])
}

abstract class LagomscalahelloserviceStreamApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents {

  // Bind the service that this server provides
  override lazy val lagomServer = serverFor[LagomscalahelloserviceStreamService](wire[LagomscalahelloserviceStreamServiceImpl])

  // Bind the LagomscalahelloserviceService client
  lazy val lagomscalahelloserviceService = serviceClient.implement[LagomscalahelloserviceService]
} 
Example 16
Source File: WFProducerLoader.scala    From Scala-Reactive-Programming   with MIT License 5 votes vote down vote up
package com.packt.publishing.wf.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.publishing.wf.api.WFService
import com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents

class WFProducerLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new WFProducerApplication(context) with ConductRApplicationComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new WFProducerApplication(context) with LagomDevModeComponents

  override def describeServices = List(readDescriptor[WFService])
}

abstract class WFProducerApplication(context: LagomApplicationContext) extends WFComponents(context)
  with LagomKafkaComponents {

}

abstract class WFComponents(context: LagomApplicationContext) extends LagomApplication(context)
  with CassandraPersistenceComponents
  with AhcWSComponents {

  override lazy val lagomServer = LagomServer.forServices(
    bindService[WFService].to(wire[WFServiceImpl])
  )

  override lazy val jsonSerializerRegistry = WFSerializerRegistry

  persistentEntityRegistry.register(wire[WFEntity])
} 
Example 17
Source File: WebGatewayLoader.scala    From Scala-Reactive-Programming   with MIT License 5 votes vote down vote up
import javax.inject.Inject
import com.lightbend.lagom.internal.client.CircuitBreakerMetricsProviderImpl
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.api.{ServiceAcl, ServiceInfo}
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.packt.publishing.wf.api.WFService
import com.packt.publishing.wf.consumer.api.WFConsumerService
import com.softwaremill.macwire._
import controllers.{Assets, WFConsumerController, WFController}
import play.api.ApplicationLoader.Context
import play.api.i18n.I18nComponents
import play.api.libs.ws.ahc.AhcWSComponents
import play.api._
import play.api.Play.current
import play.api.i18n.Messages.Implicits._
import router.Routes
import scala.collection.immutable
import scala.concurrent.ExecutionContext
import com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents

abstract class WebGateway @Inject()(context: Context) extends BuiltInComponentsFromContext(context)
  with I18nComponents
  with AhcWSComponents
  with LagomServiceClientComponents {

  override lazy val serviceInfo: ServiceInfo = ServiceInfo(
    "wf-frontend",
    Map(
      "wf-frontend" -> immutable.Seq(ServiceAcl.forPathRegex("(?!/api/).*"))
    )
  )
  override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher
  override lazy val router = {
    val prefix = "/"
    wire[Routes]
  }

  lazy val wfService = serviceClient.implement[WFService]
  lazy val wfConsumerService = serviceClient.implement[WFConsumerService]
  lazy val wfController = wire[WFController]
  lazy val wfConsumerController = wire[WFConsumerController]
  lazy val assets = wire[Assets]
}

class WebGatewayLoader extends ApplicationLoader {
  override def load(context: Context): Application = context.environment.mode match {
    case Mode.Dev =>
      new WebGateway(context) with LagomDevModeComponents {}.application
    case _ =>
      (new WebGateway(context) with ConductRApplicationComponents {
        override lazy val circuitBreakerMetricsProvider = new CircuitBreakerMetricsProviderImpl(actorSystem)
      }).application
  }
} 
Example 18
Source File: WFConsumerLoader.scala    From Scala-Reactive-Programming   with MIT License 5 votes vote down vote up
package com.packt.publishing.wf.consumer.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server.{LagomApplication, LagomApplicationContext, LagomApplicationLoader, LagomServer}
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.publishing.wf.api.WFService
import com.packt.publishing.wf.consumer.api.WFConsumerService
import com.packt.publishing.wf.consumer.impl.repositories.WFRepository
import com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents

class WFConsumerLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new WFConsumerApplication(context) with ConductRApplicationComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new WFConsumerApplication(context) with LagomDevModeComponents

  override def describeServices = List(readDescriptor[WFConsumerService])
}

abstract class WFConsumerApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with CassandraPersistenceComponents
    with LagomKafkaComponents
    with AhcWSComponents {

  override lazy val lagomServer = LagomServer.forServices(
    bindService[WFConsumerService].to(wire[WFConsumerServiceImpl])
  )

  lazy val wfService = serviceClient.implement[WFService]

  lazy val messageRepository = wire[WFRepository]

  override lazy val jsonSerializerRegistry = WFConsumerSerializerRegistry

  persistentEntityRegistry.register(wire[WFEntity])
  readSide.register(wire[WFEventProcessor])
} 
Example 19
Source File: LagomscalahelloserviceLoader.scala    From Scala-Reactive-Programming   with MIT License 5 votes vote down vote up
package com.packt.publishing.lagomscalahelloservice.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.publishing.lagomscalahelloservice.api.LagomscalahelloserviceService
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.softwaremill.macwire._
import com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents

class LagomscalahelloserviceLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new LagomscalahelloserviceApplication(context) with ConductRApplicationComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new LagomscalahelloserviceApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[LagomscalahelloserviceService])
}

abstract class LagomscalahelloserviceApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with CassandraPersistenceComponents
    with LagomKafkaComponents
    with AhcWSComponents {

  // Bind the service that this server provides
  override lazy val lagomServer = serverFor[LagomscalahelloserviceService](wire[LagomscalahelloserviceServiceImpl])

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = LagomscalahelloserviceSerializerRegistry

  // Register the lagom-scala-hello-service persistent entity
  persistentEntityRegistry.register(wire[LagomscalahelloserviceEntity])
} 
Example 20
package com.packt.publishing.lagomscalahelloservicestream.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.publishing.lagomscalahelloservicestream.api.LagomscalahelloserviceStreamService
import com.packt.publishing.lagomscalahelloservice.api.LagomscalahelloserviceService
import com.softwaremill.macwire._
import com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents

class LagomscalahelloserviceStreamLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new LagomscalahelloserviceStreamApplication(context) with ConductRApplicationComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new LagomscalahelloserviceStreamApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[LagomscalahelloserviceStreamService])
}

abstract class LagomscalahelloserviceStreamApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents {

  // Bind the service that this server provides
  override lazy val lagomServer = serverFor[LagomscalahelloserviceStreamService](wire[LagomscalahelloserviceStreamServiceImpl])

  // Bind the LagomscalahelloserviceService client
  lazy val lagomscalahelloserviceService = serviceClient.implement[LagomscalahelloserviceService]
} 
Example 21
Source File: FrontEndLoader.scala    From lagom-scala-chirper   with Apache License 2.0 5 votes vote down vote up
import com.lightbend.lagom.scaladsl.api.{ServiceAcl, ServiceInfo}
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.dns.DnsServiceLocatorComponents
import com.softwaremill.macwire._
import play.api.ApplicationLoader._
import play.api.i18n.I18nComponents
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.{Application, ApplicationLoader, BuiltInComponentsFromContext, Mode}
import router.Routes

import scala.concurrent.ExecutionContext

class FrontEndLoader extends ApplicationLoader {
  override def load(context: Context): Application = context.environment.mode match {
    case Mode.Dev => (new FrontEndModule(context) with LagomDevModeComponents).application
    case _ => (new FrontEndModule(context) with DnsServiceLocatorComponents).application
  }
}

abstract class FrontEndModule(context: Context)
  extends BuiltInComponentsFromContext(context)
    with I18nComponents
    with AhcWSComponents
    with LagomServiceClientComponents {

  override lazy val serviceInfo = ServiceInfo(
    "front-end",
    Map("front-end" -> List(ServiceAcl.forPathRegex("(?!/api/).*")))
  )

  override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher

  override lazy val router = {
    wire[Routes]
  }

} 
Example 22
Source File: HelloLoader.scala    From scala-tutorials   with MIT License 5 votes vote down vote up
package com.baeldung.hello.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.baeldung.hello.api.HelloService
import com.baeldung.hello.play.SimplePlayRouter
import com.lightbend.lagom.scaladsl.pubsub.PubSubComponents
import com.softwaremill.macwire._

class HelloLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new HelloApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new HelloApplication(context) with LagomDevModeComponents {
    }

  override def describeService = Some(readDescriptor[HelloService])
}

abstract class HelloApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with PubSubComponents
    with AhcWSComponents {

  override lazy val lagomServer: LagomServer = serverFor[HelloService](wire[HelloServiceImpl])
    .additionalRouter(wire[SimplePlayRouter].router)

} 
Example 23
Source File: AkkacookbookLoader.scala    From Akka-Cookbook   with MIT License 5 votes vote down vote up
package com.packt.chapter11.akkacookbook.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.chapter11.akkacookbook.api.AkkacookbookService
import com.softwaremill.macwire._

class AkkacookbookLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new AkkacookbookApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new AkkacookbookApplication(context) with LagomDevModeComponents

  override def describeServices = List(
    readDescriptor[AkkacookbookService]
  )
}

abstract class AkkacookbookApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with CassandraPersistenceComponents
    with AhcWSComponents {

  // Bind the services that this server provides
  override lazy val lagomServer = LagomServer.forServices(
    bindService[AkkacookbookService].to(wire[AkkacookbookServiceImpl])
  )

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = AkkacookbookSerializerRegistry

  // Register the AkkaCookbook persistent entity
  persistentEntityRegistry.register(wire[AkkacookbookEntity])
} 
Example 24
Source File: HelloLoader.scala    From sbt-reactive-app   with Apache License 2.0 5 votes vote down vote up
package lagomendpoints.impl

import lagomendpoints.api.HelloService
import com.lightbend.lagom.scaladsl.client.ConfigurationServiceLocatorComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server.{ LagomApplication, LagomApplicationContext, LagomApplicationLoader }
import play.api.libs.ws.ahc.AhcWSComponents

class HelloLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new HelloApplication(context) with ConfigurationServiceLocatorComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new HelloApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[HelloService])
}

abstract class HelloApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
  with AhcWSComponents {
  override lazy val lagomServer = serverFor[HelloService](new HelloServiceImpl)
} 
Example 25
Source File: SimpleLoader.scala    From sbt-reactive-app   with Apache License 2.0 5 votes vote down vote up
package left

import com.lightbend.lagom.scaladsl.api.Descriptor
import com.lightbend.lagom.scaladsl.client.ConfigurationServiceLocatorComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server.{ LagomApplication, LagomApplicationContext, LagomApplicationLoader, LagomServer }
import play.api.libs.ws.ahc.AhcWSComponents

class SimpleLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new SimpleApplication(context) with ConfigurationServiceLocatorComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new SimpleApplication(context) with LagomDevModeComponents

  override def describeService: Option[Descriptor] = Some(readDescriptor[SimpleService])
}

abstract class SimpleApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
  with AhcWSComponents {
  override lazy val lagomServer: LagomServer = serverFor[SimpleService](new SimpleServiceImpl)
} 
Example 26
Source File: EchoLoader.scala    From sbt-reactive-app   with Apache License 2.0 5 votes vote down vote up
package lagomendpoints.impl

import lagomendpoints.api.EchoService
import com.lightbend.lagom.scaladsl.client.ConfigurationServiceLocatorComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server.{ LagomApplication, LagomApplicationContext, LagomApplicationLoader }
import play.api.libs.ws.ahc.AhcWSComponents

class EchoLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new EchoApplication(context) with ConfigurationServiceLocatorComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new EchoApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[EchoService])
}

abstract class EchoApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
  with AhcWSComponents {
  override lazy val lagomServer = serverFor[EchoService](new EchoServiceImpl)
} 
Example 27
Source File: HelloLoader.scala    From sbt-reactive-app   with Apache License 2.0 5 votes vote down vote up
package lagomendpoints.impl

import lagomendpoints.api.HelloService
import com.lightbend.lagom.scaladsl.client.ConfigurationServiceLocatorComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server.{ LagomApplication, LagomApplicationContext, LagomApplicationLoader }
import play.api.libs.ws.ahc.AhcWSComponents

class HelloLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new HelloApplication(context) with ConfigurationServiceLocatorComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new HelloApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[HelloService])
}

abstract class HelloApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
  with AhcWSComponents {
  override lazy val lagomServer = serverFor[HelloService](new HelloServiceImpl)
} 
Example 28
Source File: bakerLoader.scala    From Learn-Scala-Programming   with MIT License 5 votes vote down vote up
package ch15

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents


abstract class BakerApplication(context: LagomApplicationContext)
  extends LagomApplication(context) with AhcWSComponents {
  override lazy val lagomServer: LagomServer = serverFor[BakerService](wire[BakerServiceImpl])
}

class BakerLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new BakerApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BakerApplication(context) with LagomDevModeComponents

} 
Example 29
Source File: cookLoader.scala    From Learn-Scala-Programming   with MIT License 5 votes vote down vote up
package ch15

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents


abstract class CookApplication(context: LagomApplicationContext)
  extends LagomApplication(context) {
  override lazy val lagomServer: LagomServer = serverFor[CookService](wire[CookServiceImpl])
}

class CookLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new CookApplication(context) with AhcWSComponents {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new CookApplication(context) with AhcWSComponents with LagomDevModeComponents

} 
Example 30
Source File: managerLoader.scala    From Learn-Scala-Programming   with MIT License 5 votes vote down vote up
package ch15

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents


abstract class ManagerApplication(context: LagomApplicationContext)
    extends LagomApplication(context) with LagomKafkaClientComponents {
  lazy val boyService: BoyService = serviceClient.implement[BoyService]
  lazy val chefService: ChefService = serviceClient.implement[ChefService]
  lazy val cookService: CookService = serviceClient.implement[CookService]
  lazy val bakerService: BakerService = serviceClient.implement[BakerService]
  override lazy val lagomServer: LagomServer =
    serverFor[ManagerService](wire[ManagerServiceImpl])
}

class ManagerLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new ManagerApplication(context) with AhcWSComponents {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new ManagerApplication(context) with AhcWSComponents
    with LagomDevModeComponents

} 
Example 31
Source File: chefLoader.scala    From Learn-Scala-Programming   with MIT License 5 votes vote down vote up
package ch15

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents


abstract class ChefApplication(context: LagomApplicationContext)
  extends LagomApplication(context) with CassandraPersistenceComponents with LagomKafkaComponents {
  override lazy val lagomServer: LagomServer = serverFor[ChefService](wire[ChefServiceImpl])
  override lazy val jsonSerializerRegistry = new JsonSerializerRegistry {
    override def serializers = ChefModel.serializers
  }
}

class ChefLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new ChefApplication(context) with AhcWSComponents {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new ChefApplication(context) with AhcWSComponents with LagomDevModeComponents

} 
Example 32
Source File: boyLoader.scala    From Learn-Scala-Programming   with MIT License 5 votes vote down vote up
package ch15

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents

abstract class BoyApplication(context: LagomApplicationContext)
  extends LagomApplication(context) with AhcWSComponents {
  lazy val shopService: ShopService = serviceClient.implement[ShopService]
  override lazy val lagomServer: LagomServer = serverFor[BoyService](wire[BoyServiceImpl])
}

class BoyLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext) =
    new BoyApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext) =
    new BoyApplication(context) with LagomDevModeComponents

} 
Example 33
Source File: CalculatorLoader.scala    From Akka-Cookbook   with MIT License 5 votes vote down vote up
package com.packt.chapter11.akka.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server.{LagomApplication, LagomApplicationContext, LagomApplicationLoader, LagomServer}
import com.packt.chapter11.akka.api.CalculatorService
import com.softwaremill.macwire.wire
import play.api.libs.ws.ahc.AhcWSComponents

class CalculatorLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new CalculatorApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication = {
    new CalculatorApplication(context) with LagomDevModeComponents
  }

  override def describeServices = List(
    readDescriptor[CalculatorService]
  )
}

abstract class CalculatorApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents {

  // Bind the services that this server provides
  override lazy val lagomServer = LagomServer.forServices(
    bindService[CalculatorService].to(wire[CalculatorServiceImpl])
  )
} 
Example 34
Source File: EchoLoader.scala    From sbt-reactive-app   with Apache License 2.0 5 votes vote down vote up
package lagomendpoints.impl

import lagomendpoints.api.EchoService
import com.lightbend.lagom.scaladsl.client.ConfigurationServiceLocatorComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server.{ LagomApplication, LagomApplicationContext, LagomApplicationLoader }
import play.api.libs.ws.ahc.AhcWSComponents

class EchoLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new EchoApplication(context) with ConfigurationServiceLocatorComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new EchoApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[EchoService])
}

abstract class EchoApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
  with AhcWSComponents {
  override lazy val lagomServer = serverFor[EchoService](new EchoServiceImpl)
} 
Example 35
Source File: AkkacookbookStreamLoader.scala    From Akka-Cookbook   with MIT License 5 votes vote down vote up
package com.packt.chapter11.akkacookbookstream.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.chapter11.akkacookbookstream.api.AkkacookbookStreamService
import com.packt.chapter11.akkacookbook.api.AkkacookbookService
import com.softwaremill.macwire._

class AkkacookbookStreamLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new AkkacookbookStreamApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new AkkacookbookStreamApplication(context) with LagomDevModeComponents

  override def describeServices = List(
    readDescriptor[AkkacookbookStreamService]
  )
}

abstract class AkkacookbookStreamApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents {

  // Bind the services that this server provides
  override lazy val lagomServer = LagomServer.forServices(
    bindService[AkkacookbookStreamService].to(wire[AkkacookbookStreamServiceImpl])
  )

  // Bind the AkkacookbookService client
  lazy val akkacookbookService = serviceClient.implement[AkkacookbookService]
} 
Example 36
Source File: TokenLoader.scala    From Akka-Cookbook   with MIT License 5 votes vote down vote up
package com.packt.chapter11.token.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server._
import com.packt.chapter11.token.api.TokenService
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents

class TokenLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new TokenApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new TokenApplication(context) with LagomDevModeComponents

  override def describeServices = List(readDescriptor[TokenService])
}

abstract class TokenApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents {

  // Bind the services that this server provides
  override lazy val lagomServer = LagomServer.forServices(
    bindService[TokenService].to(wire[TokenServiceImpl])
  )
} 
Example 37
Source File: ConsumerLoader.scala    From Akka-Cookbook   with MIT License 5 votes vote down vote up
package com.packt.chapter11.consumer.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server.{LagomApplication, LagomApplicationContext, LagomApplicationLoader, LagomServer}
import com.packt.chapter11.consumer.api.ConsumerService
import com.packt.chapter11.token.api.TokenService
import com.softwaremill.macwire.wire
import play.api.libs.ws.ahc.AhcWSComponents

class ConsumerLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new ConsumerApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new ConsumerApplication(context) with LagomDevModeComponents

  override def describeServices = List(readDescriptor[ConsumerService])
}

abstract class ConsumerApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents {

  // Bind the services that this server provides
  override lazy val lagomServer = LagomServer.forServices(
    bindService[ConsumerService].to(wire[ConsumerServiceImpl])
  )

  lazy val tokenService = serviceClient.implement[TokenService]
} 
Example 38
Source File: TripLoader.scala    From Akka-Cookbook   with MIT License 5 votes vote down vote up
package com.packt.chapter11.trip.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server.{LagomApplication, LagomApplicationContext, LagomApplicationLoader, LagomServer}
import com.packt.chapter11.trip.api.TripService
import com.softwaremill.macwire.wire
import play.api.libs.ws.ahc.AhcWSComponents

class TripLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new TripApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication = {
    new TripApplication(context) with LagomDevModeComponents
  }

  override def describeServices = List(
    readDescriptor[TripService]
  )
}

abstract class TripApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with CassandraPersistenceComponents
    with AhcWSComponents {

  // Bind the services that this server provides
  override lazy val lagomServer = LagomServer.forServices(
    bindService[TripService].to(wire[TripServiceImpl])
  )

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = ClientSerializerRegistry

  // Register the AkkaCookbook persistent entity
  persistentEntityRegistry.register(wire[ClientEntity])
} 
Example 39
Source File: HelloWorldLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package com.example.helloworld.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.example.helloworld.api.HelloWorldService
import com.example.helloworld.impl.readsides.StartedReadSideProcessor
import com.example.helloworld.impl.readsides.StoppedReadSideProcessor
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.softwaremill.macwire._

class HelloWorldLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new HelloWorldApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new HelloWorldApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[HelloWorldService])
}

abstract class HelloWorldApplication(context: LagomApplicationContext)
    extends LagomApplication(context)
    with CassandraPersistenceComponents
    with AhcWSComponents {

  override lazy val lagomServer: LagomServer =
    serverFor[HelloWorldService](wire[HelloWorldServiceImpl])
  override lazy val jsonSerializerRegistry: JsonSerializerRegistry =
    HelloWorldSerializerRegistry
  persistentEntityRegistry.register(wire[HelloWorldEntity])

  private lazy val startedProcessor = wire[StartedReadSideProcessor]
  private lazy val stoppedProcessor = wire[StoppedReadSideProcessor]

  // The following three lines are the key step on this scripted test:
  //  - request the workers of a projection to be started before registering the processor.
  // This service is setup to not start the projections eagerly (see application.conf) but we do
  // start one of the projections programmatically.
  projections.startAllWorkers(StartedReadSideProcessor.Name)

  readSide.register(startedProcessor)
  readSide.register(stoppedProcessor)

} 
Example 40
Source File: FooLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package impl


import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import api.FooService
import com.softwaremill.macwire._

class FooLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new FooApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new FooApplication(context) with LagomDevModeComponents
}

abstract class FooApplication(context: LagomApplicationContext) extends LagomApplication(context) with AhcWSComponents {
  override lazy val lagomServer = serverFor[FooService](wire[FooServiceImpl])
} 
Example 41
Source File: ShoppingCartLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package com.example.shoppingcart.impl

import com.example.shoppingcart.api.ShoppingCartService
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.slick.SlickPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.db.HikariCPComponents
import play.api.libs.ws.ahc.AhcWSComponents

class ShoppingCartLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new ShoppingCartApplication(context) with LagomDevModeComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new ShoppingCartApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[ShoppingCartService])
}

abstract class ShoppingCartApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with SlickPersistenceComponents
    with HikariCPComponents
    with AhcWSComponents {

  // Bind the service that this server provides
  override lazy val lagomServer = serverFor[ShoppingCartService](wire[ShoppingCartServiceImpl])

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = ShoppingCartSerializerRegistry

  lazy val reportRepository = wire[ShoppingCartReportRepository]
  readSide.register(wire[ShoppingCartReportProcessor])

  //#akka-persistence-register-classic
  // Register the ShoppingCart persistent entity
  persistentEntityRegistry.register(wire[ShoppingCartEntity])
  //#akka-persistence-register-classic

} 
Example 42
Source File: ShoppingCartLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package com.example.shoppingcart.impl

import com.example.shoppingcart.api.ShoppingCartService
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.slick.SlickPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.db.HikariCPComponents
import play.api.libs.ws.ahc.AhcWSComponents
import akka.cluster.sharding.typed.scaladsl.Entity
import com.lightbend.lagom.scaladsl.playjson.EmptyJsonSerializerRegistry

class ShoppingCartLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new ShoppingCartApplication(context) with LagomDevModeComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new ShoppingCartApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[ShoppingCartService])
}

abstract class ShoppingCartApplication(context: LagomApplicationContext)
    extends LagomApplication(context)
    with SlickPersistenceComponents
    with HikariCPComponents
    with AhcWSComponents {

  // Bind the service that this server provides
  override lazy val lagomServer = serverFor[ShoppingCartService](wire[ShoppingCartServiceImpl])

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = ShoppingCartSerializerRegistry

  lazy val reportRepository = wire[ShoppingCartReportRepository]
  readSide.register(wire[ShoppingCartReportProcessor])

  //#akka-persistence-init-sharded-behavior
  // in Akka Typed, this is the equivalent of Lagom's PersistentEntityRegistry.register
  clusterSharding.init(
    Entity(ShoppingCart.typeKey) {
      ctx => ShoppingCart.behavior(ctx)
    }
  )
  //#akka-persistence-init-sharded-behavior

} 
Example 43
Source File: A.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package com.example

import akka.NotUsed
import com.lightbend.lagom.scaladsl.api._
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import scala.concurrent.Future

trait A extends Service {
  def hello(name: String): ServiceCall[NotUsed, String]

  override def descriptor = {
    import Service._
    named("a")
      .withCalls(
        pathCall("/hello/:name", hello _)
      )
      .withAutoAcl(true)
  }
}

class AImpl extends A {
  override def hello(name: String) = ServiceCall { _ =>
    Future.successful(s"Hello $name")
  }
}

abstract class AApplication(context: LagomApplicationContext) extends LagomApplication(context) with AhcWSComponents {

  override def lagomServer = serverFor[A](new AImpl)
}

class ALoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new AApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new AApplication(context) with LagomDevModeComponents
} 
Example 44
Source File: BarLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package impl

import java.nio.file.Files
import java.nio.file.StandardOpenOption
import java.util.Date

import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import api.BarService
import api.FooService
import com.softwaremill.macwire._

class BarLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new BarApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BarApplication(context) with LagomDevModeComponents
}

abstract class BarApplication(context: LagomApplicationContext) extends LagomApplication(context) with AhcWSComponents {

  override lazy val lagomServer = serverFor[BarService](wire[BarServiceImpl])

  lazy val fooService = serviceClient.implement[FooService]

  Files.write(
    environment.getFile("target/reload.log").toPath,
    s"${new Date()} - reloaded\n".getBytes("utf-8"),
    StandardOpenOption.CREATE,
    StandardOpenOption.APPEND
  )
}