本文整理汇总了Scala中com.google.inject.Provider类的典型用法代码示例。如果您正苦于以下问题:Scala Provider类的具体用法?Scala Provider怎么用?Scala Provider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Provider类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
}
开发者ID:xiaozai512,项目名称:marathon,代码行数:29,代码来源:TaskStatusEmitterPublishStepImpl.scala
示例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)
}
}
开发者ID:xiaozai512,项目名称:marathon,代码行数:27,代码来源:NotifyHealthCheckManagerStepImpl.scala
示例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
}
}
}
开发者ID:xiaozai512,项目名称:marathon,代码行数:48,代码来源:ScaleAppUpdateStepImpl.scala
示例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)
}
}
开发者ID:xiaozai512,项目名称:marathon,代码行数:39,代码来源:NotifyLaunchQueueStepImplTest.scala
示例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()
}
}
开发者ID:frankieleef,项目名称:banking,代码行数:20,代码来源:AkkaModule.scala
示例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()
}
}
开发者ID:nulab,项目名称:backlog-migration-common,代码行数:33,代码来源:AkkaModule.scala
示例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()
}
}
开发者ID:igeolise,项目名称:single-page-app-skeleton,代码行数:20,代码来源:Config.scala
示例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()
}
}
开发者ID:NeonsIo,项目名称:collector,代码行数:37,代码来源:LogSinkModule.scala
示例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()
}
}
开发者ID:NeonsIo,项目名称:collector,代码行数:22,代码来源:ActorMaterializerModule.scala
示例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()
}
}
开发者ID:NeonsIo,项目名称:collector,代码行数:25,代码来源:AkkaModule.scala
示例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()
}
}
开发者ID:NeonsIo,项目名称:collector,代码行数:22,代码来源:CollectorConfigModule.scala
示例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()
}
}
开发者ID:LBNL-UCB-STI,项目名称:beam,代码行数:34,代码来源:BeamAgentModule.scala
示例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))
}
}
开发者ID:brightgenerous,项目名称:cgm-lms,代码行数:29,代码来源:ErrorHandler.scala
示例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()
}
}
开发者ID:zqhxuyuan,项目名称:first-player,代码行数:28,代码来源:AkkaModule.scala
示例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()
}
}
开发者ID:zqhxuyuan,项目名称:first-player,代码行数:22,代码来源:ConfigModule.scala
示例16: ServiceClientLoader
//设置package包名称以及导入依赖的类
package com.lightbend.lagom.internal.javadsl.client
import javax.inject.{ Inject, Singleton }
import com.google.inject.Provider
import com.lightbend.lagom.internal.javadsl.api.{ JacksonPlaceholderExceptionSerializer, JacksonPlaceholderSerializerFactory, ServiceReader }
import com.lightbend.lagom.javadsl.api.Service
import com.lightbend.lagom.javadsl.jackson.{ JacksonExceptionSerializer, JacksonSerializerFactory }
import play.api.Environment
@Singleton
class ServiceClientLoader @Inject() (
jacksonSerializerFactory: JacksonSerializerFactory,
jacksonExceptionSerializer: JacksonExceptionSerializer, environment: Environment,
implementor: JavadslServiceClientImplementor
) {
def loadServiceClient[T](interface: Class[T]): T = {
if (classOf[Service].isAssignableFrom(interface)) {
val descriptor = ServiceReader.readServiceDescriptor(
environment.classLoader,
interface.asSubclass(classOf[Service])
)
val resolved = ServiceReader.resolveServiceDescriptor(descriptor, environment.classLoader,
Map(JacksonPlaceholderSerializerFactory -> jacksonSerializerFactory),
Map(JacksonPlaceholderExceptionSerializer -> jacksonExceptionSerializer))
implementor.implement(interface, resolved)
} else {
throw new IllegalArgumentException("Don't know how to load services that don't implement Service")
}
}
}
@Singleton
class ServiceClientProvider[T](interface: Class[T]) extends Provider[T] {
@Inject private var loader: ServiceClientLoader = _
lazy val get = loader.loadServiceClient(interface)
}
开发者ID:lagom,项目名称:lagom,代码行数:38,代码来源:ServiceClientLoader.scala
示例17: TVDBTVShowInfoProvider
//设置package包名称以及导入依赖的类
package providers
import com.google.inject.{Provider, Inject}
import mediainfo.tv.{TVShowDAO, TVShowInfo}
import mediainfo.tv.tvdb.TVDBTVShowInfo
import play.api.Configuration
import play.api.libs.ws.WSClient
import scala.concurrent.ExecutionContext
class TVDBTVShowInfoProvider @Inject()(
configuration: Configuration,
ws: WSClient,
tvShowDAO: TVShowDAO
)(implicit exec: ExecutionContext) extends Provider[TVShowInfo] {
override def get(): TVShowInfo = {
val tvdbApiKey = configuration.getString("tvdb.apiKey")
.getOrElse(throw new RuntimeException("TVDB API Key required with config key tvdb.apiKey"))
new TVDBTVShowInfo(apiKey = tvdbApiKey, ws = ws, tvShowDAO = tvShowDAO)
}
}
开发者ID:pequalsnp,项目名称:portroyal,代码行数:22,代码来源:TVDBTVShowInfoProvider.scala
示例18: Module
//设置package包名称以及导入依赖的类
package com.github.dnvriend
import akka.actor.ActorSystem
import akka.persistence.cassandra.query.scaladsl.CassandraReadJournal
import akka.persistence.query.PersistenceQuery
import akka.persistence.query.scaladsl.ReadJournal
import com.google.inject.{ AbstractModule, Inject, Provider }
class Module extends AbstractModule {
protected def configure(): Unit = {
bind(classOf[ReadJournal])
.toProvider(classOf[CassandraReadJournalProvider])
}
}
class CassandraReadJournalProvider @Inject() (system: ActorSystem) extends Provider[ReadJournal] {
override def get(): ReadJournal =
PersistenceQuery.apply(system).readJournalFor(CassandraReadJournal.Identifier)
}
开发者ID:dnvriend,项目名称:akka-persistence-cassandra-test,代码行数:20,代码来源:Module.scala
示例19: FBAdsStandaloneModule
//设置package包名称以及导入依赖的类
package com.fourseasapp.facebookads
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import com.fourseasapp.facebookads.network.{APIRequest, APIRequestFactory, BatchAPIRequest}
import com.google.inject.assistedinject.FactoryModuleBuilder
import com.google.inject.{AbstractModule, Inject, Provider}
import com.typesafe.config.ConfigFactory
import net.codingwell.scalaguice.ScalaModule
import org.asynchttpclient.AsyncHttpClientConfig
import play.api.libs.ws.ahc.{AhcConfigBuilder, AhcWSClient, AhcWSClientConfig}
import play.api.libs.ws.{WSClient, WSConfigParser}
import play.api.{Configuration, Environment, Mode}
class FBAdsStandaloneModule extends AbstractModule with ScalaModule {
override def configure(): Unit = {
install(new FactoryModuleBuilder()
.implement(classOf[APIRequest], classOf[APIRequest])
.implement(classOf[BatchAPIRequest], classOf[BatchAPIRequest])
.build(classOf[APIRequestFactory]))
bind[ActorSystem].toInstance(ActorSystem(classOf[FBAdsStandaloneModule].getSimpleName))
bind[WSClient].toProvider[WSClientProvider].in[javax.inject.Singleton]
}
}
class WSClientProvider @Inject() (system: ActorSystem) extends Provider[WSClient] {
override def get(): WSClient = {
val materializer = ActorMaterializer(namePrefix = Some(classOf[FBAdsStandaloneModule].getSimpleName))(system)
val configuration = Configuration.reference ++ Configuration(ConfigFactory.parseString(
"""
|ws.followRedirects = true
""".stripMargin))
val parser = new WSConfigParser(configuration, Environment.simple(mode = Mode.Prod))
val config = new AhcWSClientConfig(wsClientConfig = parser.parse())
val builder = new AhcConfigBuilder(config)
val logging = new AsyncHttpClientConfig.AdditionalChannelInitializer() {
override def initChannel(channel: io.netty.channel.Channel): Unit = {
channel.pipeline.addFirst("log", new io.netty.handler.logging.LoggingHandler("debug"))
}
}
val ahcBuilder = builder.configure()
ahcBuilder.setHttpAdditionalChannelInitializer(logging)
val ahcConfig = ahcBuilder.build()
return new AhcWSClient(ahcConfig)(materializer)
}
}
开发者ID:hailg,项目名称:facebook-scala-ads-sdk,代码行数:51,代码来源:FBAdsStandaloneModule.scala
示例20: ConnectionErrorHandler
//设置package包名称以及导入依赖的类
package auth.http.util
import java.net.ConnectException
import com.google.inject.{Inject, Provider}
import play.api._
import play.api.http.{DefaultHttpErrorHandler, HttpErrorHandler}
import play.api.mvc.RequestHeader
import play.api.mvc._
import play.api.mvc.Results._
import play.api.routing.Router
import scala.concurrent.Future
class ConnectionErrorHandler @Inject()(env: Environment,
config: Configuration,
sourceMapper: OptionalSourceMapper,
router: Provider[Router])
extends DefaultHttpErrorHandler(env, config, sourceMapper, router) {
private val logger = Logger(this.getClass)
override def onServerError(request: RequestHeader, exception: Throwable): Future[Result] =
exception match {
case e: ConnectException ?
logger.error(
s"Connection failed for $request, transferring to ServiceUnavailable result", e)
Future.successful(ServiceUnavailable(exception.getMessage))
case e: Throwable ? super.onServerError(request, exception)
}
}
开发者ID:KadekM,项目名称:play-slick-silhouette-auth-api,代码行数:33,代码来源:ConnectionErrorHandler.scala
注:本文中的com.google.inject.Provider类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论