本文整理汇总了Scala中com.softwaremill.macwire.wire类的典型用法代码示例。如果您正苦于以下问题:Scala wire类的具体用法?Scala wire怎么用?Scala wire使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了wire类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: OrderApplication
//设置package包名称以及导入依赖的类
package demo.impl.order
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.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire.wire
import demo.api.basket.BasketService
import demo.api.order.OrderService
import play.api.libs.ws.ahc.AhcWSComponents
import scala.collection.immutable.Seq
abstract class OrderApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
with AhcWSComponents
with CassandraPersistenceComponents
with LagomKafkaComponents {
override def lagomServer: LagomServer = LagomServer.forServices {
bindService[OrderService].to(wire[OrderServiceImpl])
}
lazy val basketService: BasketService = serviceClient.implement[BasketService]
persistentEntityRegistry.register(wire[Order])
wire[BasketServiceSubscriber]
}
class OrderApplicationLoader extends LagomApplicationLoader {
override def loadDevMode(context: LagomApplicationContext): LagomApplication = {
new OrderApplication(context) with LagomDevModeComponents {
override def jsonSerializerRegistry: JsonSerializerRegistry = OrderSerializerRegistry
}
}
override def load(context: LagomApplicationContext): LagomApplication = {
new OrderApplication(context) {
override def serviceLocator: ServiceLocator = NoServiceLocator
override def jsonSerializerRegistry: JsonSerializerRegistry = OrderSerializerRegistry
}
}
}
object OrderSerializerRegistry extends JsonSerializerRegistry {
import OrderEntityFormats._
override def serializers: Seq[JsonSerializer[_]] = {
Seq(JsonSerializer[OrderInitialized],
JsonSerializer[OrderState],
JsonSerializer[CreateOrder],
JsonSerializer[GetOrder.type],
JsonSerializer[OrderItems])
}
}
示例2: HelloWorldServiceLoader
//设置package包名称以及导入依赖的类
package me.alexray.helloWorldService.impl
import com.lightbend.lagom.scaladsl.server.{LagomApplication, LagomApplicationContext, LagomApplicationLoader, LagomServer}
import com.softwaremill.macwire.wire
import me.alexray.lagom.kube.client.LagomKubeModeComponents
import me.alexray.helloWorldService.api.HelloWorldService
import play.api.libs.ws.ahc.AhcWSComponents
class HelloWorldServiceLoader extends LagomApplicationLoader {
override def load(context: LagomApplicationContext): LagomApplication =
new HelloWorldServiceApplication(context) with LagomKubeModeComponents
override def loadDevMode(context: LagomApplicationContext): LagomApplication =
new HelloWorldServiceApplication(context) with LagomKubeModeComponents
override def describeServices = List(
readDescriptor[HelloWorldService]
)
}
abstract class HelloWorldServiceApplication(context: LagomApplicationContext)
extends LagomApplication(context) with AhcWSComponents
{
// Bind the service that this server provides
override lazy val lagomServer: LagomServer = serverFor[HelloWorldService](wire[HelloWorldServiceImpl])
}
示例3: createActionBuilders
//设置package包名称以及导入依赖的类
package authentication
import authentication.deadbolt.config.{DeadboltHandlerCache, OAuthDeadboltHandler}
import authentication.oauth2.{AccessTokenRepo, AuthenticationConfig, OAuth2Controller, PlayWithFoodAuthorizationHandler}
import authentication.repositories.SecurityUserRepo
import authentication.services.api.{PasswordValidator, SecurityUserCreator, SecurityUserProvider}
import authentication.services.{PasswordValidatorImpl, SecurityUserService}
import be.objectify.deadbolt.scala.cache._
import be.objectify.deadbolt.scala.{ActionBuilders, DeadboltComponents}
import com.softwaremill.macwire.wire
import commons.CommonsComponents
import commons.config.WithControllerComponents
import play.api.mvc.PlayBodyParsers
import play.api.routing.Router
import play.api.routing.sird._
trait AuthenticationsComponents extends CommonsComponents with DeadboltComponents with WithControllerComponents{
lazy val passwordValidator: PasswordValidator = wire[PasswordValidatorImpl]
lazy val securityUserCreator: SecurityUserCreator = wire[SecurityUserService]
lazy val securityUserProvider: SecurityUserProvider = wire[SecurityUserService]
lazy val securityUserRepo: SecurityUserRepo = wire[SecurityUserRepo]
lazy val oAuth2Controller: OAuth2Controller = wire[OAuth2Controller]
lazy val playWithFoodAuthorizationHandler: PlayWithFoodAuthorizationHandler = wire[PlayWithFoodAuthorizationHandler]
lazy val authenticationConfig: AuthenticationConfig = wire[AuthenticationConfig]
lazy val accessTokenRepo: AccessTokenRepo = wire[AccessTokenRepo]
override lazy val patternCache: PatternCache = wire[DefaultPatternCache]
override lazy val compositeCache: CompositeCache = wire[DefaultCompositeCache]
override lazy val handlers: HandlerCache = wire[DeadboltHandlerCache]
lazy val oAuthDeadboltHandler: OAuthDeadboltHandler = wire[OAuthDeadboltHandler]
protected def createActionBuilders: PlayBodyParsers => ActionBuilders = parsers => actionBuilders(deadboltActions(parsers))
val authenticationRoutes: Router.Routes = {
case POST(p"/oauth/accessToken") => oAuth2Controller.accessToken
}
}
示例4:
//设置package包名称以及导入依赖的类
package users
import authentication.AuthenticationsComponents
import com.softwaremill.macwire.wire
import commons.config.WithControllerComponents
import play.api.routing.Router
import play.api.routing.sird._
import users.controllers.UserController
import users.repositories.UserRepo
import users.services.api.{UserCreator, UserProvider}
import users.services.{UserCreatorImpl, UserProviderImpl, UserRegistrationService, UserRegistrationValidator}
trait UsersComponents extends AuthenticationsComponents with WithControllerComponents {
lazy val userController: UserController = wire[UserController]
lazy val userRepo: UserRepo = wire[UserRepo]
lazy val userCreator: UserCreator = wire[UserCreatorImpl]
lazy val userProvider: UserProvider = wire[UserProviderImpl]
lazy val userRegistrationService: UserRegistrationService = wire[UserRegistrationService]
lazy val userRegistrationValidator: UserRegistrationValidator = wire[UserRegistrationValidator]
val userRoutes: Router.Routes = {
case GET(p"/users") => userController.all
case GET(p"/users/login/$login") => userController.byLogin(login)
case POST(p"/users/register") => userController.register
}
}
示例5: ComputationFollowedByAsyncPublishing
//设置package包名称以及导入依赖的类
package org.zalando.benchmarks
import java.util.concurrent.TimeUnit
import akka.actor._
import com.softwaremill.macwire.wire
import org.openjdk.jmh.annotations._
import scala.concurrent.duration._
import scala.util.Random
object ComputationFollowedByAsyncPublishing {
implicit val system = ActorSystem()
val publishDuration = 15 millis
val numTasks = 20000
val numTokensToConsume = 5000000L // eats about 9-10 ms on my box
val actors = wire[Actors]
val futures = wire[Futures]
val blocking = wire[Blocking]
val streams = wire[Streams]
val rx = wire[RxScala]
def printResult(rs: Seq[PublishResult]): Unit = println(rs map computeResult sum)
def computeResult(r: PublishResult): Int =
r.result.result + r.result.job.payload(Random.nextInt(r.result.job.payload length))
def numWorkers(coreFactor: Int): Int = Runtime.getRuntime.availableProcessors * coreFactor
}
@BenchmarkMode(Array(Mode.AverageTime))
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Benchmark)
class ComputationFollowedByAsyncPublishing {
import ComputationFollowedByAsyncPublishing._
@Benchmark def bmActors(): Unit = actors benchmark 1 // <= 109 threads ("Live peak" in JVisualVM)
@Benchmark def bmParallelFutures(): Unit = futures benchmark 1 // <= 44 threads ("Live peak" in JVisualVM)
@Benchmark def bmBlocking(): Unit = blocking benchmark 64 // <= 549 threads ("Live peak" in JVisualVM)
@Benchmark def bmStreams(): Unit = streams benchmark 1 // <= 52 threads ("Live peak" in JVisualVM)
//@Benchmark def bmRxScala(): Unit = rx benchmark // blows up with OutOfMemoryError :(
@TearDown def tearDown(): Unit = system.terminate()
}
开发者ID:narayana-glassbeam,项目名称:scala-concurrency-playground,代码行数:48,代码来源:ComputationFollowedByAsyncPublishing.scala
示例6: executionContext
//设置package包名称以及导入依赖的类
package modules
import com.softwaremill.macwire.wire
import io.getquill.{PostgresAsyncContext, SnakeCase}
import services._
import scala.concurrent.ExecutionContext
trait DatabaseModule {
// quill
implicit def executionContext: ExecutionContext
// database
lazy val dbCtx = new PostgresAsyncContext[SnakeCase]("ctx")
lazy val universityService = wire[UniversityService]
lazy val facultyService = wire[FacultyService]
lazy val departmentService = wire[DepartmentService]
lazy val userService = wire[UserService]
lazy val passwordInfoService = wire[PasswordInfoService]
lazy val employeeService = wire[EmployeeService]
lazy val studentService = wire[StudentService]
}
示例7: NotificationsApp
//设置package包名称以及导入依赖的类
package it.wknd.reactive.backend
import akka.actor.{ActorSystem, Props}
import akka.http.scaladsl.Http
import akka.http.scaladsl.Http.ServerBinding
import akka.stream.ActorMaterializer
import akka.stream.actor.ActorPublisher
import akka.stream.scaladsl.{RunnableGraph, Sink, Source}
import com.softwaremill.macwire.wire
import com.typesafe.config.ConfigFactory
import it.wknd.reactive.backend.flow.EventGraph
import it.wknd.reactive.backend.model.{HealthNotification, HeartRate, Step}
import it.wknd.reactive.backend.source.{HrActorSource, SourceProvider, StepActorSource}
import scala.concurrent.Future
object NotificationsApp extends App {
implicit val config = ConfigFactory.load()
implicit val actorSystem = ActorSystem("hr-backend")
implicit val ec = actorSystem.dispatcher
implicit val materializer = ActorMaterializer()
lazy val sourceProvider = wire[SourceProvider]
val hrActor = actorSystem.actorOf(Props[HrActorSource])
val hrPub = ActorPublisher[HeartRate](hrActor)
val stepActor = actorSystem.actorOf(Props[StepActorSource])
val stepPub = ActorPublisher[Step](stepActor)
RunnableGraph fromGraph {
EventGraph(
stepSource = Source.fromPublisher(stepPub),
hrSource = Source.fromPublisher(hrPub),
sink = Sink.actorSubscriber[HealthNotification](Props[NotifierActor]))
} run()
val bindingFuture: Future[ServerBinding] =
Http().bindAndHandle(sourceProvider.routes(hrActor = hrActor, stepActor = stepActor), "localhost", 2525)
}
示例8: TripLoader
//设置package包名称以及导入依赖的类
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])
}
示例9: CalculatorLoader
//设置package包名称以及导入依赖的类
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])
)
}
示例10: ConsumerLoader
//设置package包名称以及导入依赖的类
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]
}
示例11: ec
//设置package包名称以及导入依赖的类
package dao
import akka.actor.ActorSystem
import models.{OrderPlaced, UserRecognized}
import play.api.BuiltInComponents
import scala.concurrent.ExecutionContext
trait DaoModule extends BuiltInComponents {
import com.softwaremill.macwire.wire
import com.softwaremill.tagging._
implicit def ec: ExecutionContext =
ExecutionContext.global
implicit def sys: ActorSystem =
actorSystem
private def userTopic =
"users".taggedWith[UserRecognized]
private def orderTopic = "orders".taggedWith[OrderPlaced]
lazy val orderDao: EventDao[OrderPlaced] =
wire[KafkaDao[OrderPlaced]]
lazy val userDao: EventDao[UserRecognized] =
wire[KafkaDao[UserRecognized]]
}
示例12: initDbAggregation
//设置package包名称以及导入依赖的类
package loader
import com.softwaremill.macwire.wire
import model.sensor.impl.{LocationRepositorySql, SensorRepositorySql}
import play.api.BuiltInComponents
import play.api.libs.concurrent.Execution.Implicits._
import scala.concurrent.duration._
import scala.language.postfixOps
trait DaoConfig extends BuiltInComponents with ClockConfig with SqlH2Config {
lazy val locationRepository: LocationRepositorySql = wire[LocationRepositorySql]
lazy val sensorRepository: SensorRepositorySql = new SensorRepositorySql(locationRepository, clock)
def initDbAggregation(): Unit = {
actorSystem.scheduler.schedule(
10 second,
1 hour,
new Runnable {
override def run() = {
sensorRepository.findAll().foreach(sensor => sensor.aggregateOldMeasurements())
}
}
)
}
}
示例13: initializeListeners
//设置package包名称以及导入依赖的类
package loader
import akka.actor.{ActorRef, Props}
import com.softwaremill.macwire.wire
import config.HomeControllerConfiguration
import model.actuator.impl.ActuatorRepositoryNaive
import mqtt.clown.BridgeListener
import mqtt.watering.{WateringCommander, WateringHelloListener, WateringListener}
import mqtt.{MqttConnector, MqttDispatchingListener, MqttListenerMessage, MqttRepeater}
import play.api.BuiltInComponents
trait MqttConfig extends BuiltInComponents with DaoConfig with ClockConfig {
lazy val mqttDispatchingListener: MqttDispatchingListener = wire[MqttDispatchingListener]
lazy val mqttConnector = new MqttConnector(
HomeControllerConfiguration(
mqttBrokerUrl = configuration.getString("home_center.mqtt.url").get,
mqttClientId = configuration.getString("home_center.mqtt.clientId").get
),
mqttDispatchingListener,
actorSystem
)
lazy val wateringCommander = wire[WateringCommander]
lazy val actuatorRepository: ActuatorRepositoryNaive = wire[ActuatorRepositoryNaive]
lazy val wateringListener: ActorRef = actorSystem.actorOf(Props(wire[WateringListener]))
lazy val wateringHelloListener: ActorRef = actorSystem.actorOf(Props(wire[WateringHelloListener]))
lazy val bcBridgeListenerActor: ActorRef = actorSystem.actorOf(Props(wire[BridgeListener]))
lazy val mqttRepeaterActor: ActorRef = actorSystem.actorOf(Props(
new MqttRepeater(
HomeControllerConfiguration(
configuration.getString("home_center.mqtt_repeater.url").orNull,
configuration.getString("home_center.mqtt_repeater.clientId").orNull
),
actorSystem,
mqttConnector
)
))
def initializeListeners(): Unit = {
mqttConnector.reconnect.run()
bcBridgeListenerActor ! MqttListenerMessage.Ping
wateringListener ! MqttListenerMessage.Ping
wateringHelloListener ! MqttListenerMessage.Ping
mqttRepeaterActor ! MqttListenerMessage.Ping
mqttDispatchingListener.addListener(bcBridgeListenerActor.path)
mqttDispatchingListener.addListener(wateringListener.path)
mqttDispatchingListener.addListener(wateringHelloListener.path)
mqttDispatchingListener.addListener(mqttRepeaterActor.path)
}
}
示例14: initWsQuerying
//设置package包名称以及导入依赖的类
package loader
import com.softwaremill.macwire.wire
import play.api.BuiltInComponents
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.ws.ahc.AhcWSClient
import ws.WattmeterClient
import scala.concurrent.duration._
import scala.language.postfixOps
trait WsClientConfig extends BuiltInComponents with DaoConfig with ClockConfig {
lazy val wsClient = AhcWSClient()
lazy val wattmeterClient = wire[WattmeterClient]
def initWsQuerying(): Unit = {
actorSystem.scheduler.schedule(
1 second,
1 second,
new Runnable {
override def run() = {
wattmeterClient.queryWattmeter()
}
}
)
}
}
示例15: WateringListenerTest
//设置package包名称以及导入依赖的类
package mqtt.watering
import java.time.{Clock, Instant}
import akka.actor.{ActorSystem, Props}
import akka.testkit.TestActorRef
import com.softwaremill.macwire.wire
import model.sensor._
import model.sensor.impl.{LocationRepositorySql, LocationSql, SensorRepositorySql}
import mqtt.MqttListenerMessage.ConsumeMessage
import org.scalamock.scalatest.MockFactory
import org.scalatest.{Matchers, WordSpec}
class WateringListenerTest extends WordSpec with Matchers with MockFactory {
"WateringListener" when {
implicit val system = ActorSystem()
val clock = mock[Clock]
val instant = Instant.ofEpochSecond(22)
(clock.instant _).expects().returning(instant).atLeastOnce()
"receives the message" should {
"store it in dao if the message is correct" in {
val locationRepository = mock[LocationRepositorySql]
val sensorRepository = mock[SensorRepositorySqlWithCtor]
val listener = TestActorRef[WateringListener](Props(wire[WateringListener]))
val sensor = mock[Sensor]
val humidityPhenomenon = mock[MeasuredPhenomenon]
val wateringPhenomenon = mock[MeasuredPhenomenon]
val location = LocationSql("watering-ibiscus", "label")
(locationRepository.findOrCreateLocation _).expects("watering-ibiscus").returning(location)
(sensorRepository.findOrCreateSensor _).expects(location, "watering").returning(sensor)
(sensor.findOrCreatePhenomenon _).expects( "humidity", "", IdentityMeasurementAggregationStrategy).returning(humidityPhenomenon)
(sensor.addMeasurement _).expects(Measurement(86, Instant.ofEpochSecond(22)), humidityPhenomenon)
(sensor.findOrCreatePhenomenon _).expects( "watering", "", BooleanMeasurementAggregationStrategy).returning(wateringPhenomenon)
(sensor.addMeasurement _).expects(Measurement(10, Instant.ofEpochSecond(22)), wateringPhenomenon)
val correctJson = """ {"ts":8119,"tm":{"hu":{"a":86,"bl":512,"md":1000,"bs":10,"pd":30},"wa":{"ip":true,"wp":20000,"wt":5000},"wlh":true}}"""
listener ! ConsumeMessage("home/watering/ibisek/telemetry", correctJson)
}
}
}
class SensorRepositorySqlWithCtor extends SensorRepositorySql(null, null)
}