当前位置: 首页>>代码示例>>Scala>>正文


Scala TwitterModule类代码示例

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


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


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