• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala TwitterModule类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中com.twitter.inject.TwitterModule的典型用法代码示例。如果您正苦于以下问题:Scala TwitterModule类的具体用法?Scala TwitterModule怎么用?Scala TwitterModule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TwitterModule类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: SNSClientModule

//设置package包名称以及导入依赖的类
package uk.ac.wellcome.finatra.modules

import javax.inject.Singleton

import com.amazonaws.auth.{AWSStaticCredentialsProvider, BasicAWSCredentials}
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.amazonaws.services.sns._
import com.google.inject.Provides
import com.twitter.inject.TwitterModule
import uk.ac.wellcome.models.aws.AWSConfig

object SNSClientModule extends TwitterModule {
  val snsEndpoint = flag[String](
    "aws.sns.endpoint",
    "",
    "Endpoint of AWS SNS. The region will be used if the enpoint is not provided")
  @Singleton
  @Provides
  def providesSNSClient(awsConfig: AWSConfig): AmazonSNS = {
    val standardSnsClient = AmazonSNSClientBuilder.standard
    if (snsEndpoint().isEmpty)
      standardSnsClient
        .withRegion(awsConfig.region)
        .build()
    else
      standardSnsClient
        .withCredentials(
          new AWSStaticCredentialsProvider(
            new BasicAWSCredentials(awsConfig.accessKey.get,
                                    awsConfig.secretKey.get)))
        .withEndpointConfiguration(
          new EndpointConfiguration(snsEndpoint(), awsConfig.region))
        .build()
  }
} 
开发者ID:wellcometrust,项目名称:platform-api,代码行数:36,代码来源:SNSClientModule.scala


示例2: Modules

//设置package包名称以及导入依赖的类
package com.bob.reservefund.scala

import com.bob.reservefund.scala.Service.UserService
import com.bob.reservefund.scala.Util.EnvironmentContext
import com.google.gson.JsonParser
import com.google.inject.{Provides, Singleton}
import com.twitter.finatra.annotations.Flag
import com.twitter.inject.TwitterModule
import com.typesafe.config.ConfigFactory

import scala.collection.JavaConversions._
import scala.io.Source

object Modules extends TwitterModule {

  val config = ConfigFactory.load()
  val test = config.getString("config.testurl")
  val default = config.getString("config.defaulturl")

  val env = System.getProperty("active.environment", "default")
  val url = env match {
    case "test" => test
    case _ => default
  }

  val jsons = Source.fromURL(url).mkString
  val parser = new JsonParser()
  val jsonobj = parser.parse(jsons).getAsJsonObject.getAsJsonArray("propertySources").get(0).getAsJsonObject.getAsJsonObject("source")
  jsonobj.entrySet().foreach(x => {
    flag(x.getKey, x.getValue.getAsString, "")
    EnvironmentContext.put(x.getKey, x.getValue.getAsString)
  })

  flag("dbusername", "root", "the username of the database")
  flag("active.environment", env, "which environment now is run")

  @Singleton
  @Provides
  def providesUserService(@Flag("dbusername") dbusername: String): UserService = {
    new UserService(dbusername)
  }

} 
开发者ID:bobxwang,项目名称:ReserveFundService,代码行数:44,代码来源:Modules.scala


示例3: DataSource

//设置package包名称以及导入依赖的类
package io.github.mijicd.prezi.modules

import com.fasterxml.jackson.databind.ObjectMapper
import com.google.inject.{Provides, Singleton}
import com.twitter.inject.TwitterModule
import io.github.mijicd.prezi.domain.Presentation

import scala.collection.JavaConverters._
import scala.io.BufferedSource

object DataSource extends TwitterModule with Managed with DateConversion {
  @Singleton
  @Provides
  def provideSource: Seq[Presentation] = {
    val resource = getClass.getResource("/prezis.json")

    using(scala.io.Source.fromURL(resource)) { source =>
      val items = loadFrom(source)
      sortSeq(items)
    }
  }

  private def loadFrom(source: BufferedSource): Seq[Presentation] = {
    val json = source.getLines().mkString
    val mapper = new ObjectMapper()
    val factory = mapper.getTypeFactory

    val items: java.util.List[Presentation] =
      mapper.readValue(json,
        factory.constructCollectionType(classOf[java.util.List[Presentation]],
          classOf[Presentation]))

    items.asScala
  }

  private def sortSeq(seq: Seq[Presentation]) = seq.sortWith(compare)

  private def compare(first: Presentation, second: Presentation): Boolean = {
    val firstDate = dateOf(first.createdAt)
    val secondDate = dateOf(second.createdAt)

    firstDate.isAfter(secondDate)
  }
} 
开发者ID:mijicd,项目名称:finatra-demo,代码行数:45,代码来源:DataSource.scala


示例4: SwaggerModule

//设置package包名称以及导入依赖的类
package com.github.ikhoon.modules

import javax.inject.Singleton

import com.google.inject.Provides
import com.twitter.inject.TwitterModule
import io.swagger.models.{ Info, Swagger }

object SwaggerModule extends TwitterModule {

  flag(name = "swagger.docs.endpoint", default = "/api-docs", help = "The key to use")

  lazy val swagger = {
    val swag = new Swagger()

    val info = new Info()
      .description("The Finatra Mysql Seed API, this is a sample for swagger document generation")
      .version("1.0.1")
      .title("Finatra Mysql Seed API")

    swag
      .info(info)
    swag
  }

  @Singleton
  @Provides
  def provideSwagger: Swagger = swagger
} 
开发者ID:ikhoon,项目名称:finatra-mysql-seed,代码行数:30,代码来源:SwaggerModule.scala


示例5: HttpClientModules

//设置package包名称以及导入依赖的类
package com.github.ikhoon.modules

import javax.inject.{ Named, Singleton }

import com.google.inject.Provides
import com.twitter.finatra.httpclient.HttpClient
import com.twitter.finatra.httpclient.modules.HttpClientModule
import com.twitter.finatra.json.FinatraObjectMapper
import com.twitter.inject.TwitterModule
import com.typesafe.config.Config
import net.ceedubs.ficus.Ficus._

object HttpClientModules {
  val modules = Seq(FakeHttpClientModule())
}


abstract class BasicHttpClientModule() extends TwitterModule {

  protected def provideHttpClient(mapper: FinatraObjectMapper, host: String, port: Int = 80): HttpClient = {
    val httpClientModule = new HttpClientModule {
      override def dest: String = s"$host:$port"
      override def defaultHeaders: Map[String, String] = Map("Host" -> host)
    }
    httpClientModule.provideHttpClient(mapper, httpClientModule.provideHttpService)
  }
}

object FakeHttpClientModule {
  def apply() = new BasicHttpClientModule {
    @Named("fake") @Provides @Singleton
    def provideHttpClient(mapper: FinatraObjectMapper, config: Config) =
      super.provideHttpClient(mapper, config.as[String]("fake.host"), config.as[Int]("fake.port"))
  }
} 
开发者ID:ikhoon,项目名称:finatra-mysql-seed,代码行数:36,代码来源:HttpClientModules.scala


示例6: ExceptionMapperModule

//设置package包名称以及导入依赖的类
package me.kamkor.yaas.http.modules

import com.twitter.finatra.http.exceptions.DefaultExceptionMapper
import com.twitter.finatra.http.internal.exceptions.json.JsonParseExceptionMapper
import com.twitter.finatra.http.internal.exceptions.{ExceptionManager, FinatraDefaultExceptionMapper}
import com.twitter.inject.{Injector, InjectorModule, TwitterModule}
import me.kamkor.yaas.http.exceptions.json.CaseClassExceptionMapper
import me.kamkor.yaas.http.exceptions.{HttpExceptionMapper, ValidationExceptionMapper}

object ExceptionMapperModule extends TwitterModule {

  override def modules = Seq(InjectorModule)

  override def configure(): Unit = {
    bindSingleton[DefaultExceptionMapper].to[FinatraDefaultExceptionMapper]
  }

  override def singletonStartup(injector: Injector): Unit = {
    val manager = injector.instance[ExceptionManager]
    manager.add[JsonParseExceptionMapper]
    manager.add[CaseClassExceptionMapper]
    manager.add[ValidationExceptionMapper]
    manager.add[HttpExceptionMapper]
  }

} 
开发者ID:kamkor,项目名称:yaas-wishlist-service,代码行数:27,代码来源:ExceptionMapperModule.scala


示例7: DocumentWishListsRepositoryModule

//设置package包名称以及导入依赖的类
package me.kamkor.wishlists.repository.document

import java.net.URL

import com.google.inject.{Provides, Singleton}
import com.twitter.finatra.json.FinatraObjectMapper
import com.twitter.inject.TwitterModule
import me.kamkor.finatra.httpclient.HttpClient
import me.kamkor.wishlists.repository.WishListsRepository
import me.kamkor.yaas.oauth2.OAuthService
import me.kamkor.yaas.oauth2.model.ClientCredentials
import me.kamkor.yaas.proxy.YaasProxyClient

object DocumentWishListsRepositoryModule extends TwitterModule {

  val documentUrl = flag("document.url", "https://api.yaas.io/hybris/document/v1", "destination of the yaas document service")
  val documentClientId = flag("document.clientId", "clientId", "client id for the document service")
  val documentClientSecret = flag("document.clientSecret", "clientSecret", "client secret for the document service")

  @Singleton
  @Provides
  @DocumentClient
  def provideDocumentClient(oauthService: OAuthService): YaasProxyClient = {
    val httpClient = HttpClient(new URL(documentUrl()))
    val proxyClient = new YaasProxyClient(oauthService, httpClient)
    proxyClient
  }

  @Singleton
  @Provides
  def providesWishListsRepository(oauthService: OAuthService, mapper: FinatraObjectMapper): WishListsRepository = {
    val httpClient = HttpClient(new URL(documentUrl()))
    val proxyClient = new YaasProxyClient(oauthService, httpClient)

    val clientCredentials = ClientCredentials(
      documentClientId(), documentClientSecret(), Seq("hybris.document_view", "hybris.document_manage"))
    new DocumentWishListsRepository(proxyClient, mapper, clientCredentials)
  }

} 
开发者ID:kamkor,项目名称:yaas-wishlist-service,代码行数:41,代码来源:DocumentWishListsRepositoryModule.scala


示例8: ApiModule

//设置package包名称以及导入依赖的类
package org.globalnames
package index
package api

import com.google.inject.{Provides, Singleton}
import com.twitter.app.Flag
import com.twitter.finagle.ThriftMux
import com.twitter.inject.TwitterModule
import thrift.nameresolver.{Service => NameResolverService}

import scala.util.Properties

object ApiModule extends TwitterModule {
  val nameresolverServiceAddress: Flag[String] = flag(
    name = "nameresolverServiceAddress",
    help = "Host and port of nameresolver service",
    default = Properties.envOrElse("NAMERESOLVER_ADDRESS", "")
  )

  @Singleton
  @Provides
  def provideNameResolverClient: NameResolverService.FutureIface =
    ThriftMux.client.newIface[NameResolverService.FutureIface](nameresolverServiceAddress())

} 
开发者ID:GlobalNamesArchitecture,项目名称:gnindex,代码行数:26,代码来源:ApiModule.scala


示例9: MatcherModule

//设置package包名称以及导入依赖的类
package org.globalnames
package index
package matcher

import java.io.File
import com.google.inject.{Provides, Singleton}
import com.twitter.app.Flag
import com.twitter.inject.{Logging, TwitterModule}
import org.globalnames.{matcher => matcherlib}

import scala.io.Source

import scalaz._
import Scalaz._

object MatcherModule extends TwitterModule with Logging {

  val namesFileKey: Flag[File] = flag(
    name = "names-path",
    help = "Path to file that contains canonical names for matcher"
  )

  val namesWithDatasourcesFileKey: Flag[File] = flag(
    name = "names-datasources-path",
    help = "Path to file that contains canonical names with datasources for matcher"
  )

  @Singleton
  @Provides
  def prodiveMatcherLib: matcherlib.Matcher = {
    val names = namesFileKey().exists ?
      Source.fromFile(namesFileKey()).getLines.toVector |
      { logger.error(s"${namesFileKey()} file doesn't exist"); Vector.empty[String] }
    matcherlib.Matcher(names)
  }

  @Singleton
  @Provides
  def provideCanonicalNames: CanonicalNames = {
    def create(): CanonicalNames = {
      val nameToDatasourceIdsMap =
        Source.fromFile(namesWithDatasourcesFileKey()).getLines.zipWithIndex
          .foldLeft(Map.empty[String, Set[Int]].withDefaultValue(Set.empty)) {
            case (mp, (line, idx)) =>
              if (idx % 100000 == 0) {
                logger.info(s"Names with datasources loaded in total: $idx")
              }
              val Array(canonicalName, dataSourceId) = line.split('\t')
              mp + (canonicalName -> (mp(canonicalName) + dataSourceId.toInt))
          }
      CanonicalNames(nameToDatasourceIdsMap)
    }

    namesWithDatasourcesFileKey().exists ? create() |
      { logger.error(s"${namesWithDatasourcesFileKey()} file doesn't exist")
        CanonicalNames(Map.empty.withDefaultValue(Set.empty)) }
  }

} 
开发者ID:GlobalNamesArchitecture,项目名称:gnindex,代码行数:60,代码来源:MatcherModule.scala


示例10: NameResolverModule

//设置package包名称以及导入依赖的类
package org.globalnames
package index
package nameresolver

import com.google.inject.{Provides, Singleton}
import com.twitter.app.Flag
import com.twitter.finagle.ThriftMux
import com.twitter.inject.TwitterModule
import thrift.matcher.{Service => MatcherService}
import slick.jdbc.PostgresProfile.api._
import scala.util.Properties

object NameResolverModule extends TwitterModule {
  val matcherServiceAddress: Flag[String] = flag(
    name = "matcherServiceAddress",
    help = "Host and port of matcher service",
    default = Properties.envOrElse("MATCHER_ADDRESS", "")
  )

  @Singleton
  @Provides
  def provideDatabase: Database = {
    val host = Properties.envOrElse("DB_HOST", "localhost")
    val port = Properties.envOrElse("DB_PORT", "5432")
    val database = Properties.envOrElse("DB_DATABASE", "development")
    val url = s"jdbc:postgresql://$host:$port/$database"
    Database.forURL(
      url = url,
      user = Properties.envOrElse("DB_USER", "postgres"),
      password = Properties.envOrElse("DB_USER_PASS", ""),
      driver = "org.postgresql.Driver"
    )
  }

  @Singleton
  @Provides
  def provideMatcherClient: MatcherService.FutureIface =
    ThriftMux.client.newIface[MatcherService.FutureIface](matcherServiceAddress())

} 
开发者ID:GlobalNamesArchitecture,项目名称:gnindex,代码行数:41,代码来源:NameResolverModule.scala


示例11: IdMinterDynamoConfigModule

//设置package包名称以及导入依赖的类
package uk.ac.wellcome.platform.idminter.modules

import javax.inject.Singleton

import com.google.inject.Provides
import com.twitter.inject.TwitterModule
import uk.ac.wellcome.finatra.modules.PlatformDynamoConfigModule
import uk.ac.wellcome.models.aws.DynamoConfig

object IdMinterDynamoConfigModule extends TwitterModule {
  override val modules = Seq(PlatformDynamoConfigModule)

  @Singleton
  @Provides
  def providesDynamoConfig(
    platformDynamoConfig: Map[String, DynamoConfig]): DynamoConfig =
    platformDynamoConfig.getOrElse(
      "identifiers",
      throw new RuntimeException("Identifiers dynamo config missing"))

} 
开发者ID:wellcometrust,项目名称:platform-api,代码行数:22,代码来源:IdMinterDynamoConfigModule.scala


示例12: IdMinterWorkerModule

//设置package包名称以及导入依赖的类
package uk.ac.wellcome.platform.idminter.modules

import akka.actor.ActorSystem
import com.twitter.inject.{Injector, TwitterModule}
import uk.ac.wellcome.platform.idminter.database.TableProvisioner
import uk.ac.wellcome.platform.idminter.services.IdMinterWorkerService

object IdMinterWorkerModule extends TwitterModule {
  val database = flag[String]("aws.rds.identifiers.database",
                              "",
                              "Name of the identifiers database")
  val tableName = flag[String]("aws.rds.identifiers.table",
                               "",
                               "Name of the identifiers table")

  override def singletonStartup(injector: Injector) {
    val tableProvisioner = injector.instance[TableProvisioner]
    val workerService = injector.instance[IdMinterWorkerService]

    tableProvisioner.provision(database(), tableName())
    workerService.runSQSWorker()

    super.singletonStartup(injector)
  }

  override def singletonShutdown(injector: Injector) {
    info("Terminating SQS worker")

    val system = injector.instance[ActorSystem]
    val workerService = injector.instance[IdMinterWorkerService]

    workerService.cancelRun()
    system.terminate()
  }
} 
开发者ID:wellcometrust,项目名称:platform-api,代码行数:36,代码来源:IdMinterWorkerModule.scala


示例13: MysqlModule

//设置package包名称以及导入依赖的类
package uk.ac.wellcome.platform.idminter.modules

import com.google.inject.Provides
import com.twitter.inject.TwitterModule
import scalikejdbc.{AutoSession, ConnectionPool, DB}

object MysqlModule extends TwitterModule {

  private val host =
    flag[String]("aws.rds.host", "", "Host of the MySQL database")
  private val port =
    flag[String]("aws.rds.port", "3306", "Port of the MySQL database")
  private val userName = flag[String]("aws.rds.userName",
                                      "",
                                      "User to connect to the MySQL database")
  private val password = flag[String](
    "aws.rds.password",
    "",
    "Password to connect to the MySQL database")

  @Provides
  def providesDB(): DB = {
    Class.forName("com.mysql.jdbc.Driver")
    ConnectionPool.singleton(s"jdbc:mysql://${host()}:${port()}",
                             userName(),
                             password())
    implicit val session = AutoSession
    DB.connect()
  }
} 
开发者ID:wellcometrust,项目名称:platform-api,代码行数:31,代码来源:MysqlModule.scala


示例14: ElasticSearchServiceModule

//设置package包名称以及导入依赖的类
package uk.ac.wellcome.platform.api.finatra.modules.ElasticSearchServiceModule

import com.google.inject.Provides
import com.sksamuel.elastic4s.http.HttpClient
import com.twitter.inject.TwitterModule
import uk.ac.wellcome.finatra.modules.ElasticClientModule
import uk.ac.wellcome.platform.api.services.ElasticSearchService

object ElasticSearchServiceModule extends TwitterModule {
  override val modules = Seq(ElasticClientModule)

  private val defaultIndex = flag[String](name = "es.index",
                                          default = "records",
                                          help = "ES index name")
  private val documentType =
    flag[String](name = "es.type", default = "item", help = "ES document type")

  @Provides
  def providesElasticSearchService(
    elasticClient: HttpClient): ElasticSearchService =
    new ElasticSearchService(defaultIndex = defaultIndex(),
                             documentType = documentType(),
                             elasticClient = elasticClient)

} 
开发者ID:wellcometrust,项目名称:platform-api,代码行数:26,代码来源:ElasticSearchServiceModule.scala


示例15: IngestorWorkerModule

//设置package包名称以及导入依赖的类
package uk.ac.wellcome.platform.ingestor.modules

import akka.actor.ActorSystem
import com.twitter.inject.{Injector, TwitterModule}
import uk.ac.wellcome.platform.ingestor.services.IngestorWorkerService

object IngestorWorkerModule extends TwitterModule {
  private val esIndex = flag[String]("es.index", "records", "ES index name")
  private val esType = flag[String]("es.type", "item", "ES document type")

  override def singletonStartup(injector: Injector) {
    val workerService = injector.instance[IngestorWorkerService]

    workerService.runSQSWorker()

    super.singletonStartup(injector)
  }

  override def singletonShutdown(injector: Injector) {
    info("Terminating SQS worker")

    val system = injector.instance[ActorSystem]
    val workerService = injector.instance[IngestorWorkerService]

    workerService.cancelRun()
    system.terminate()
  }
} 
开发者ID:wellcometrust,项目名称:platform-api,代码行数:29,代码来源:IngestorWorkerModule.scala


示例16: TransformableParserModule

//设置package包名称以及导入依赖的类
package uk.ac.wellcome.transformer.modules

import com.google.inject.{Provides, Singleton}
import com.twitter.inject.TwitterModule
import uk.ac.wellcome.models.Transformable
import uk.ac.wellcome.transformer.parsers.{
  CalmParser,
  MiroParser,
  TransformableParser
}

object TransformableParserModule extends TwitterModule {
  val dataSource =
    flag[String]("transformer.source", "", "Name of the source of data")

  @Singleton
  @Provides
  def providesTransformableParser(): TransformableParser[Transformable] = {

    dataSource() match {
      case "MiroData" => new MiroParser
      case "CalmData" => new CalmParser
      case tableName =>
        throw new RuntimeException(s"$tableName is not a recognised source")
    }
  }
} 
开发者ID:wellcometrust,项目名称:platform-api,代码行数:28,代码来源:TransformableParserModule.scala


示例17: TransformerWorkerModule

//设置package包名称以及导入依赖的类
package uk.ac.wellcome.transformer.modules

import akka.actor.ActorSystem
import com.twitter.inject.{Injector, TwitterModule}
import uk.ac.wellcome.transformer.services.TransformerWorkerService

object TransformerWorkerModule extends TwitterModule {
  override def singletonStartup(injector: Injector) {
    val workerService = injector.instance[TransformerWorkerService]

    workerService.runSQSWorker()

    super.singletonStartup(injector)
  }

  override def singletonShutdown(injector: Injector) {
    info("Terminating SQS worker")

    val system = injector.instance[ActorSystem]
    val workerService = injector.instance[TransformerWorkerService]

    workerService.cancelRun()
    system.terminate()
  }
} 
开发者ID:wellcometrust,项目名称:platform-api,代码行数:26,代码来源:TransformerWorkerModule.scala


示例18: ElasticCredentials

//设置package包名称以及导入依赖的类
package uk.ac.wellcome.finatra.modules

import javax.inject.Singleton

import com.google.inject.Provides
import org.elasticsearch.client.RestClient
import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback
import com.sksamuel.elastic4s.http.HttpClient
import com.twitter.inject.TwitterModule
import org.apache.http.auth.{AuthScope, UsernamePasswordCredentials}
import org.apache.http.HttpHost
import org.apache.http.impl.client.BasicCredentialsProvider
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder

class ElasticCredentials(username: String, password: String)
    extends HttpClientConfigCallback {
  val credentials = new UsernamePasswordCredentials(username, password)
  val credentialsProvider = new BasicCredentialsProvider()
  credentialsProvider.setCredentials(AuthScope.ANY, credentials)

  override def customizeHttpClient(
    httpClientBuilder: HttpAsyncClientBuilder): HttpAsyncClientBuilder = {
    httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)
  }
}

object ElasticClientModule extends TwitterModule {
  private val host = flag[String]("es.host", "localhost", "host name of ES")
  private val port = flag[Int]("es.port", 9200, "port no of ES")
  private val protocol =
    flag[String]("es.protocol", "http", "protocol for talking to ES")
  private val clusterName =
    flag[String]("es.name", "elasticsearch", "cluster name")
  private val username = flag[String]("es.username", "elastic", "ES username")
  private val password = flag[String]("es.password", "changeme", "ES username")

  @Singleton
  @Provides
  def provideElasticClient(): HttpClient = {
    info(s"Building clientUri for ${host()}:${port()}")

    val restClient = RestClient
      .builder(new HttpHost(host(), port(), protocol()))
      .setHttpClientConfigCallback(
        new ElasticCredentials(username(), password()))
      .build()

    HttpClient.fromRestClient(restClient)
  }
} 
开发者ID:wellcometrust,项目名称:platform-api,代码行数:51,代码来源:ElasticClientModule.scala


示例19: SQSConfigModule

//设置package包名称以及导入依赖的类
package uk.ac.wellcome.finatra.modules

import javax.inject.Singleton

import com.google.inject.Provides
import com.twitter.inject.TwitterModule
import uk.ac.wellcome.models.aws.SQSConfig

import scala.concurrent.duration._

object SQSConfigModule extends TwitterModule {
  private val queueUrl =
    flag[String]("aws.sqs.queue.url", "", "URL of the SQS Queue")
  val waitTime = flag(
    "aws.sqs.waitTime",
    20,
    "Time to wait (in seconds) for a message to arrive on the queue before returning")
  val maxMessages =
    flag("aws.sqs.maxMessages", 1, "Maximum number of SQS messages to return")

  @Singleton
  @Provides
  def providesSQSConfig(): SQSConfig =
    SQSConfig(queueUrl(), waitTime() seconds, maxMessages())
} 
开发者ID:wellcometrust,项目名称:platform-api,代码行数:26,代码来源:SQSConfigModule.scala


示例20: AmazonCloudWatchModule

//设置package包名称以及导入依赖的类
package uk.ac.wellcome.finatra.modules

import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.amazonaws.services.cloudwatch.{
  AmazonCloudWatch,
  AmazonCloudWatchClientBuilder
}
import com.google.inject.{Provides, Singleton}
import com.twitter.inject.TwitterModule
import uk.ac.wellcome.metrics.MetricsSender
import uk.ac.wellcome.models.aws.AWSConfig

object AmazonCloudWatchModule extends TwitterModule {
  private val awsNamespace = flag[String]("aws.metrics.namespace",
                                          "",
                                          "Namespace for cloudwatch metrics")
  private val awsEndpoint = flag[String](
    "aws.cloudWatch.endpoint",
    "",
    "Endpoint of AWS CloudWatch. If not set, it will use the region")

  @Provides
  @Singleton
  def providesMetricsSender(amazonCloudWatch: AmazonCloudWatch) =
    new MetricsSender(awsNamespace(), amazonCloudWatch)

  @Provides
  @Singleton
  def providesAmazonCloudWatch(awsConfig: AWSConfig): AmazonCloudWatch = {
    val standardCloudWatchClient = AmazonCloudWatchClientBuilder.standard
    if (awsEndpoint().isEmpty) {
      standardCloudWatchClient
        .withRegion(awsConfig.region)
        .build()
    } else
      standardCloudWatchClient
        .withEndpointConfiguration(
          new EndpointConfiguration(awsEndpoint(), awsConfig.region))
        .build()
  }
} 
开发者ID:wellcometrust,项目名称:platform-api,代码行数:42,代码来源:AmazonCloudWatchModule.scala



注:本文中的com.twitter.inject.TwitterModule类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala ContentType类代码示例发布时间:2022-05-23
下一篇:
Scala Entity类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap