本文整理汇总了Scala中com.google.inject.Provider类的典型用法代码示例。如果您正苦于以下问题:Scala Provider类的具体用法?Scala Provider怎么用?Scala Provider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Provider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: TaskStatusEmitterPublishStepImpl
//设置package包名称以及导入依赖的类
package mesosphere.marathon.core.task.update.impl.steps
import javax.inject.Inject
import akka.Done
import com.google.inject.Provider
import mesosphere.marathon.core.instance.update.{ InstanceChange, InstanceChangeHandler }
import mesosphere.marathon.core.task.bus.TaskStatusEmitter
import scala.concurrent.Future
// TODO(PODS): remove the emitter stuff and taskStatusObservables
// the taskStatusObservables are only used in OfferMatcherLaunchTokensActor, which could subscribe
// to the eventStream, instead
// then this whole step and related code could be removed.
class TaskStatusEmitterPublishStepImpl @Inject() (
taskStatusEmitterProvider: Provider[TaskStatusEmitter]) extends InstanceChangeHandler {
private[this] lazy val taskStatusEmitter = taskStatusEmitterProvider.get()
override def name: String = "emitUpdate"
override def process(update: InstanceChange): Future[Done] = {
taskStatusEmitter.publish(update)
Future.successful(Done)
}
}
示例2: NotifyHealthCheckManagerStepImpl
//设置package包名称以及导入依赖的类
package mesosphere.marathon
package core.task.update.impl.steps
import akka.Done
import com.google.inject.{ Inject, Provider }
import mesosphere.marathon.core.health.HealthCheckManager
import mesosphere.marathon.core.instance.update.{ InstanceChange, InstanceChangeHandler }
import scala.concurrent.Future
class NotifyHealthCheckManagerStepImpl @Inject() (healthCheckManagerProvider: Provider[HealthCheckManager])
extends InstanceChangeHandler {
override def name: String = "notifyHealthCheckManager"
lazy val healthCheckManager = healthCheckManagerProvider.get
override def process(update: InstanceChange): Future[Done] = {
update.instance.tasksMap.valuesIterator.flatMap(_.status.mesosStatus).foreach { mesosStatus =>
// TODO(PODS): the healthCheckManager should collect health status based on instances, not tasks
healthCheckManager.update(mesosStatus, update.runSpecVersion)
}
Future.successful(Done)
}
}
示例3: ScaleAppUpdateStepImpl
//设置package包名称以及导入依赖的类
package mesosphere.marathon.core.task.update.impl.steps
//scalastyle:off
import javax.inject.Named
import akka.Done
import akka.actor.ActorRef
import com.google.inject.{ Inject, Provider }
import mesosphere.marathon.MarathonSchedulerActor.ScaleRunSpec
import mesosphere.marathon.core.condition.Condition
import mesosphere.marathon.core.instance.update.{ InstanceChange, InstanceChangeHandler }
import org.slf4j.LoggerFactory
import scala.concurrent.Future
//scalastyle:on
class ScaleAppUpdateStepImpl @Inject() (
@Named("schedulerActor") schedulerActorProvider: Provider[ActorRef]) extends InstanceChangeHandler {
private[this] val log = LoggerFactory.getLogger(getClass)
private[this] lazy val schedulerActor = schedulerActorProvider.get()
private[this] def scalingWorthy: Condition => Boolean = {
case Condition.Reserved | Condition.UnreachableInactive | _: Condition.Terminal => true
case _ => false
}
override def name: String = "scaleApp"
override def process(update: InstanceChange): Future[Done] = {
// TODO(PODS): it should be up to a tbd TaskUnreachableBehavior how to handle Unreachable
calcScaleEvent(update).foreach(event => schedulerActor ! event)
Future.successful(Done)
}
def calcScaleEvent(update: InstanceChange): Option[ScaleRunSpec] = {
if (scalingWorthy(update.condition) && update.lastState.forall(lastState => !scalingWorthy(lastState.condition))) {
val runSpecId = update.runSpecId
val instanceId = update.id
val state = update.condition
log.info(s"initiating a scale check for runSpec [$runSpecId] due to [$instanceId] $state")
// TODO(PODS): we should rename the Message and make the SchedulerActor generic
Some(ScaleRunSpec(runSpecId))
} else {
None
}
}
}
示例4: NotifyLaunchQueueStepImplTest
//设置package包名称以及导入依赖的类
package mesosphere.marathon.core.task.update.impl.steps
import akka.Done
import com.google.inject.Provider
import mesosphere.marathon.core.launchqueue.LaunchQueue
import mesosphere.marathon.core.task.bus.TaskStatusUpdateTestHelper
import mesosphere.marathon.test.Mockito
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{ FunSuite, GivenWhenThen, Matchers }
import scala.concurrent.Future
class NotifyLaunchQueueStepImplTest extends FunSuite with Matchers with GivenWhenThen with Mockito with ScalaFutures {
test("name") {
new Fixture().step.name should equal("notifyLaunchQueue")
}
test("notifying launch queue") {
Given("a status update")
val f = new Fixture
val expectedUpdate = TaskStatusUpdateTestHelper.running().wrapped
When("calling processUpdate")
f.launchQueue.notifyOfInstanceUpdate(expectedUpdate) returns Future.successful(Done)
f.step.process(expectedUpdate).futureValue
Then("the update is passed to the LaunchQueue")
verify(f.launchQueue).notifyOfInstanceUpdate(expectedUpdate)
}
class Fixture {
val launchQueue = mock[LaunchQueue]
val launchQueueProvider = new Provider[LaunchQueue] {
override def get(): LaunchQueue = launchQueue
}
val step = new NotifyLaunchQueueStepImpl(launchQueueProvider = launchQueueProvider)
}
}
示例5: ActorSystemProvider
//设置package包名称以及导入依赖的类
package com.franklevering.banking.infrastructure.dependencyinjection.modules
import akka.actor.ActorSystem
import com.franklevering.banking.infrastructure.dependencyinjection.extension.GuiceAkkaExtension
import com.google.inject.{AbstractModule, Inject, Injector, Provider}
import net.codingwell.scalaguice.ScalaModule
class ActorSystemProvider @Inject() (val injector:Injector) extends Provider[ActorSystem] {
override def get(): ActorSystem = {
val system = ActorSystem("banking-context")
GuiceAkkaExtension(system).initialize(injector)
system
}
}
class AkkaModule extends AbstractModule with ScalaModule {
override def configure(): Unit = {
bind[ActorSystem].toProvider[ActorSystemProvider].asEagerSingleton()
}
}
示例6: AkkaModule
//设置package包名称以及导入依赖的类
package com.nulabinc.backlog.migration.common.modules
import javax.inject.Inject
import akka.actor.ActorSystem
import com.google.inject.{AbstractModule, Injector, Provider}
import com.nulabinc.backlog.migration.common.modules.akkaguice.GuiceAkkaExtension
import com.nulabinc.backlog.migration.common.modules.AkkaModule.ActorSystemProvider
import com.typesafe.config.Config
import net.codingwell.scalaguice.ScalaModule
object AkkaModule {
class ActorSystemProvider @Inject()(val config: Config, val injector: Injector) extends Provider[ActorSystem] {
override def get() = {
val system = ActorSystem.apply("main-actor-system", config)
// add the GuiceAkkaExtension to the system, and initialize it with the Guice injector
GuiceAkkaExtension(system).initialize(injector)
system
}
}
}
class AkkaModule extends AbstractModule with ScalaModule {
override def configure() {
bind[ActorSystem].toProvider[ActorSystemProvider].asEagerSingleton()
}
}
示例7: ConfigModule
//设置package包名称以及导入依赖的类
package backend.core.module
import com.google.inject.{AbstractModule, Inject, Provider}
import backend.core.model.AppConfig
import play.api.Configuration
class ConfigModule extends AbstractModule {
override def configure(): Unit = {
bind(classOf[AppConfig])
.toProvider(classOf[ConfigProvider])
.asEagerSingleton()
}
}
class ConfigProvider @Inject()(config: Configuration) extends Provider[AppConfig] {
override def get(): AppConfig = {
AppConfig()
}
}
示例8: LogSinkModule
//设置package包名称以及导入依赖的类
package io.neons.collector.application.guice.infrastructure.log.sink
import java.util.{Properties, UUID}
import com.google.inject.{AbstractModule, Inject, Provider}
import io.neons.collector.application.config.CollectorConfig
import io.neons.collector.application.guice.infrastructure.log.sink.LogSinkModule.KafkaLogSinkModuleProvider
import io.neons.collector.infrastructure.log.sink.KafkaLogSink
import io.neons.collector.model.log.{Log, LogSink}
import net.codingwell.scalaguice.ScalaModule
import org.apache.kafka.clients.producer.KafkaProducer
object LogSinkModule {
class KafkaLogSinkModuleProvider @Inject()(collectorConfig: CollectorConfig) extends Provider[KafkaProducer[UUID, Log]] {
override def get(): KafkaProducer[UUID, Log] = {
val kafkaConfig = collectorConfig.sink.kafkaSinkConfig
val properties = new Properties()
properties.put("bootstrap.servers", kafkaConfig.host.concat(":").concat(kafkaConfig.port.toString))
properties.put("client.id", kafkaConfig.clientId)
properties.put("max.block.ms", "5000")
properties.put("request.timeout.ms", "10000")
properties.put("acks", "all")
properties.put("key.serializer", "io.neons.collector.application.guice.infrastructure.log.sink.serialization.UuidSerializer")
properties.put("value.serializer", "io.neons.collector.application.guice.infrastructure.log.sink.serialization.RawEventSerializer")
new KafkaProducer[UUID, Log](properties)
}
}
}
class LogSinkModule extends AbstractModule with ScalaModule {
override def configure(): Unit = {
bind[LogSink].to[KafkaLogSink].asEagerSingleton()
bind[KafkaProducer[UUID, Log]].toProvider[KafkaLogSinkModuleProvider].asEagerSingleton()
}
}
示例9: ActorMaterializerModule
//设置package包名称以及导入依赖的类
package io.neons.collector.application.guice.application.akka.actor
import javax.inject.Inject
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import com.google.inject.{AbstractModule, Provider}
import io.neons.collector.application.guice.application.akka.actor.ActorMaterializerModule.ActorMaterializerProvider
import net.codingwell.scalaguice.ScalaModule
object ActorMaterializerModule {
class ActorMaterializerProvider @Inject()(actorSystem: ActorSystem) extends Provider[ActorMaterializer] {
override def get(): ActorMaterializer = ActorMaterializer.apply()(context = actorSystem)
}
}
class ActorMaterializerModule extends AbstractModule with ScalaModule {
override def configure(): Unit = {
bind[ActorMaterializer].toProvider[ActorMaterializerProvider].asEagerSingleton()
}
}
示例10: AkkaModule
//设置package包名称以及导入依赖的类
package io.neons.collector.application.guice.application.akka.actor
import javax.inject.Inject
import akka.actor.ActorSystem
import com.google.inject.{AbstractModule, Injector, Provider}
import io.neons.collector.application.guice.application.akka.actor.AkkaModule.ActorSystemProvider
import net.codingwell.scalaguice.ScalaModule
object AkkaModule {
class ActorSystemProvider @Inject()(injector: Injector) extends Provider[ActorSystem] {
override def get = {
val actorSystem = ActorSystem("collector")
GuiceAkkaExtension(actorSystem).initialize(injector)
actorSystem
}
}
}
class AkkaModule extends AbstractModule with ScalaModule {
override def configure(): Unit = {
bind[ActorSystem].toProvider[ActorSystemProvider].asEagerSingleton()
}
}
示例11: CollectorConfigModule
//设置package包名称以及导入依赖的类
package io.neons.collector.application.guice.application.config
import com.google.inject.{AbstractModule, Provider}
import com.typesafe.config.ConfigFactory
import io.neons.collector.application.config.CollectorConfig
import io.neons.collector.application.guice.application.config.CollectorConfigModule.CollectorConfigProvider
import net.codingwell.scalaguice.ScalaModule
object CollectorConfigModule {
class CollectorConfigProvider extends Provider[CollectorConfig] {
override def get(): CollectorConfig = {
CollectorConfig.load(ConfigFactory.load())
}
}
}
class CollectorConfigModule extends AbstractModule with ScalaModule {
override def configure(): Unit = {
bind[CollectorConfig].toProvider[CollectorConfigProvider].asEagerSingleton()
}
}
示例12: BeamAgentModule
//设置package包名称以及导入依赖的类
package beam.sim.modules
import akka.actor.ActorSystem
import beam.playground.akkaguice.{AkkaGuiceSupport, GuiceAkkaExtension}
import beam.sim.BeamServices
import beam.sim.modules.BeamAgentModule.ActorSystemProvider
import com.google.inject.{AbstractModule, Inject, Injector, Provider}
import com.typesafe.config.Config
import net.codingwell.scalaguice.ScalaModule
import org.slf4j.{Logger, LoggerFactory}
object BeamAgentModule {
private val logger: Logger = LoggerFactory.getLogger(classOf[BeamAgentModule])
class ActorSystemProvider @Inject()(val injector: Injector, config: Config) extends Provider[ActorSystem] {
override def get(): ActorSystem = {
val system = ActorSystem("beam-actor-system", config)
// add the GuiceAkkaExtension to the system, and initialize it with the Guice injector
GuiceAkkaExtension(system).initialize(injector)
system
}
}
}
class BeamAgentModule extends AbstractModule with AkkaGuiceSupport with ScalaModule {
override def configure(): Unit = {
bind[ActorSystem].toProvider[ActorSystemProvider].asEagerSingleton()
bind[BeamServices].asEagerSingleton()
// bind[BeamAgentScheduler].asEagerSingleton()
}
}
示例13: ErrorHandler
//设置package包名称以及导入依赖的类
package sc.ript.cgmlms.fw.handlers
import javax.inject.{Inject, Singleton}
import com.google.inject.Provider
import com.typesafe.scalalogging.LazyLogging
import play.api.http.DefaultHttpErrorHandler
import play.api.mvc.Results.{InternalServerError, Status}
import play.api.mvc.{RequestHeader, Result}
import play.api.routing.Router
import play.api.{Configuration, Environment, OptionalSourceMapper}
import scala.concurrent.Future
@Singleton
private class ErrorHandler @Inject()(env: Environment, config: Configuration, sourceMapper: OptionalSourceMapper, router: Provider[Router]) extends DefaultHttpErrorHandler(env, config, sourceMapper, router) with LazyLogging {
override def onClientError(request: RequestHeader, statusCode: Int, message: String): Future[Result] = {
logger.info("statusCode = {}, message = {}", statusCode.toString, message)
Future.successful(Status(statusCode)("A client error occurred: " + message))
}
override def onServerError(request: RequestHeader, exception: Throwable): Future[Result] = {
logger.error(s"message = ${exception.getMessage}", exception)
Future.successful(InternalServerError("A server error occurred: " + exception.getMessage))
}
}
示例14: AkkaModule
//设置package包名称以及导入依赖的类
package play.modules.io.joaovasques.playspark.akkaguice
import akka.actor.ActorSystem
import play.modules.io.joaovasques.playspark.akkaguice.AkkaModule.ActorSystemProvider
import com.google.inject.{AbstractModule, Injector, Provider}
import com.typesafe.config.Config
import net.codingwell.scalaguice.ScalaModule
import javax.inject.Inject
object AkkaModule {
class ActorSystemProvider @Inject() (val config: Config, val injector: Injector) extends Provider[ActorSystem] {
override def get() = {
val system = ActorSystem("play-spark-main-actor-system", config)
// add the GuiceAkkaExtension to the system, and initialize it with the Guice injector
GuiceAkkaExtension(system).initialize(injector)
system
}
}
}
class AkkaModule extends AbstractModule with ScalaModule {
override def configure() {
bind[ActorSystem].toProvider[ActorSystemProvider].asEagerSingleton()
}
}
示例15: ConfigModule
//设置package包名称以及导入依赖的类
package play.modules.io.joaovasques.playspark.config
import play.modules.io.joaovasques.playspark.config.ConfigModule.ConfigProvider
import com.google.inject.{AbstractModule, Provider}
import com.typesafe.config.{ConfigFactory, Config}
import net.codingwell.scalaguice.ScalaModule
object ConfigModule {
class ConfigProvider extends Provider[Config] {
override def get() = ConfigFactory.load()
}
}
class ConfigModule extends AbstractModule with ScalaModule {
override def configure() {
bind[Config].toProvider[ConfigProvider].asEagerSingleton()
}
}