本文整理汇总了Scala中com.typesafe.config.ConfigObject类的典型用法代码示例。如果您正苦于以下问题:Scala ConfigObject类的具体用法?Scala ConfigObject怎么用?Scala ConfigObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigObject类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: DbDriversBuilder
//设置package包名称以及导入依赖的类
package com.criteo.qwebmon.drivers
import java.util.Properties
import javax.sql.DataSource
import com.criteo.qwebmon.DbDriver
import com.mchange.v2.c3p0.ComboPooledDataSource
import com.typesafe.config.{Config, ConfigObject, ConfigValueType}
import scala.collection.JavaConverters._
class DbDriversBuilder(config: Config) {
val dbDrivers: Map[String, DbDriver] = config.getObject("targets")
.entrySet().asScala
.foldLeft(Map.empty[String, DbDriver]) { case (acc, entry) =>
val targetName = entry.getKey
val targetConfig = entry.getValue match {
case c if c.valueType() == ConfigValueType.OBJECT => c.asInstanceOf[ConfigObject].toConfig
case x => sys.error(s"illegal config syntax at $x")
}
targetConfig.getString("driver") match {
case "fake-db" => acc + (targetName -> new FakeDbDriver(targetName))
case "mysql" => acc + (targetName -> new MysqlDbDriver(targetName, buildDataSource(targetConfig)))
case "vertica" => acc + (targetName -> new VerticaDbDriver(targetName, buildDataSource(targetConfig)))
case x => sys.error(s"unknown driver supplied: $x, for target named: $targetName, with config: $targetConfig")
}
}
private def buildDataSource(config: Config): DataSource = {
val dataSource = new ComboPooledDataSource()
if (config.hasPath("properties")) {
val connectionProps = new Properties()
config.getConfig("properties").entrySet().asScala.foreach { entry =>
val key = entry.getKey
val value = entry.getValue.unwrapped().toString
connectionProps.setProperty(key, value)
}
dataSource.setProperties(connectionProps)
}
dataSource.setJdbcUrl(config.getString("url"))
dataSource.setUser(config.getString("user"))
dataSource.setPassword(config.getString("password"))
dataSource
}
}
开发者ID:jqcoffey,项目名称:qwebmon,代码行数:53,代码来源:DbDriversBuilder.scala
示例2: RegionSource
//设置package包名称以及导入依赖的类
package au.csiro.data61.magda.spatial
import java.net.URL
import au.csiro.data61.magda.AppConfig
import com.typesafe.config.{ Config, ConfigObject }
import scala.collection.JavaConversions._
case class RegionSource(
name: String,
url: URL,
idProperty: String,
nameProperty: String,
includeIdInName: Boolean,
disabled: Boolean,
order: Int)
object RegionSource {
def generateRegionId(regionType: String, id: String) = s"${regionType}/$id".toLowerCase
}
class RegionSources(config: Config) {
val sources = loadFromConfig(config)
private lazy val lookup = sources.groupBy(_.name.toLowerCase).mapValues(_.head)
def forName(name: String): Option[RegionSource] = lookup.get(name.toLowerCase)
private def loadFromConfig(config: Config): Seq[RegionSource] = {
config.root().map {
case (name: String, config: ConfigObject) =>
val regionSourceConfig = config.toConfig()
RegionSource(
name = name,
url = new URL(regionSourceConfig.getString("url")),
idProperty = regionSourceConfig.getString("idField"),
nameProperty = regionSourceConfig.getString("nameField"),
includeIdInName = if (regionSourceConfig.hasPath("includeIdInName")) regionSourceConfig.getBoolean("includeIdInName") else false,
disabled = regionSourceConfig.hasPath("disabled") && regionSourceConfig.getBoolean("disabled"),
order = regionSourceConfig.getInt("order"))
}.toSeq.filterNot(_.disabled)
}
}
开发者ID:TerriaJS,项目名称:magda,代码行数:45,代码来源:RegionSource.scala
示例3: indexVersions
//设置package包名称以及导入依赖的类
package au.csiro.data61.magda.search.elasticsearch
import scala.collection.JavaConversions._
import com.sksamuel.elastic4s.ElasticDsl._
import com.sksamuel.elastic4s.IndexesAndTypes
import com.typesafe.config.Config
import com.typesafe.config.ConfigObject
import au.csiro.data61.magda.model.misc._
trait Indices {
def indexVersions(config: Config) = config.getConfig("elasticSearch.indices").root().map {
case (name: String, config: ConfigObject) => name -> config.toConfig.getInt("version")
}
def getIndex(config: Config, index: Indices.Index): String = {
(index.name + indexVersions(config)(index.name))
}
def getType(`type`: Indices.IndexType) = `type`.name
def typeForFacet(facetType: FacetType) = facetType match {
case Format => Indices.FormatsIndexType
case Publisher => Indices.PublisherIndexType
case Year => throw new RuntimeException("No type for year")
}
}
object DefaultIndices extends Indices {}
object Indices {
sealed trait Index {
def name: String
}
case object DataSetsIndex extends Index {
override def name = "datasets"
}
case object RegionsIndex extends Index {
override def name = "regions"
}
sealed trait IndexType {
def name: String
}
case object DataSetsIndexType extends IndexType {
override def name() = "datasets"
}
case object RegionsIndexType extends IndexType {
override def name() = "regions"
}
case object FormatsIndexType extends IndexType {
override def name() = Format.id
}
case object PublisherIndexType extends IndexType {
override def name() = Publisher.id
}
}
开发者ID:TerriaJS,项目名称:magda,代码行数:60,代码来源:Indices.scala
示例4: MagdaApp
//设置package包名称以及导入依赖的类
package au.csiro.data61.magda
import akka.actor.{ Actor, ActorLogging, ActorSystem, DeadLetter, Props }
import akka.event.Logging
import akka.stream.ActorMaterializer
import au.csiro.data61.magda.api.Api
import au.csiro.data61.magda.crawler.Supervisor
import au.csiro.data61.magda.external.InterfaceConfig
import com.typesafe.config.{ ConfigObject, ConfigValue }
import scala.collection.JavaConversions._
object MagdaApp extends App {
implicit val system = ActorSystem()
implicit val executor = system.dispatcher
implicit val materializer = ActorMaterializer()
implicit val config = AppConfig.conf
val logger = Logging(system, getClass)
logger.info("Starting MAGDA CKAN Crawler with env {}", AppConfig.env)
val listener = system.actorOf(Props(classOf[Listener]))
system.eventStream.subscribe(listener, classOf[DeadLetter])
val interfaceConfigs = config.getConfig("indexedServices").root().map {
case (name: String, serviceConfig: ConfigValue) =>
InterfaceConfig(serviceConfig.asInstanceOf[ConfigObject].toConfig)
}.toSeq
val supervisor = system.actorOf(Props(new Supervisor(system, config, interfaceConfigs)))
// Index erryday
// system.scheduler.schedule(0 millis, 1 days, supervisor, Start(List((ExternalInterfaceType.CKAN, new URL(config.getString("services.dga-api.baseUrl"))))))
val api = new Api()
}
class Listener extends Actor with ActorLogging {
def receive = {
case d: DeadLetter => log.debug(d.message.toString())
}
}
开发者ID:TerriaJS,项目名称:magda-ckan,代码行数:44,代码来源:MagdaApp.scala
示例5: ActorServerModules
//设置package包名称以及导入依赖的类
package im.actor.server
import akka.actor._
import com.typesafe.config.{ ConfigException, ConfigObject, Config }
import im.actor.server.api.rpc.RpcApiExtension
import scala.collection.JavaConversions._
import scala.util.{ Failure, Success, Try }
object ActorServerModules extends ExtensionId[ActorServerModules] with ExtensionIdProvider {
override def createExtension(system: ExtendedActorSystem): ActorServerModules = new ActorServerModules(system)
override def lookup(): ExtensionId[_ <: Extension] = ActorServerModules
}
final class ActorServerModules(system: ExtendedActorSystem) extends Extension {
private val RpcServiceClazz = classOf[im.actor.api.rpc.Service]
def startModules(): Unit =
system.settings.config.getObject("modules") foreach {
case (n, c: ConfigObject) ? startModule(n, c.toConfig)
case (_, c) ?
throw new RuntimeException(s"Module have to be a config but got: ${c.getClass.getName}")
}
def startModule(name: String, config: Config): Unit = {
system.log.debug("Starting module {}", name)
(for {
fqcn ? Try(config.getString("rpc"))
clazz ? Try(Class.forName(fqcn).asSubclass(RpcServiceClazz))
} yield RpcApiExtension(system).register(clazz)) match {
case Success(_) ?
case Failure(_: ConfigException.Missing) ?
case Failure(_: ClassCastException) ?
throw new RuntimeException(s"rpc should extend im.actor.api.rpc.Service")
case Failure(e) ? throw e
}
(for {
fqcn ? Try(config.getString("extension"))
obj ? system.dynamicAccess.getObjectFor[AnyRef](fqcn)
} yield obj) match {
case Success(eid: ExtensionId[_]) ? startExtension(eid)
case Success(_) ?
throw new RuntimeException(s"extension should extend akka.actor.Extension")
case Failure(_: ConfigException.Missing) ?
case Failure(e) ? throw e
}
}
private def startExtension[T <: Extension](ext: ExtensionId[T]): T = ext.apply(system)
}
开发者ID:wex5,项目名称:dangchat-server,代码行数:54,代码来源:ActorServerModules.scala
示例6: CacheDefinition
//设置package包名称以及导入依赖的类
package de.zalando.cachecool
import com.typesafe.config.{Config, ConfigObject, ConfigValue}
case class CacheDefinition(factoryName: String, isDefault: Boolean, factoryConfig: ConfigObject)
object CacheDefinition {
def apply(configValue: ConfigValue): CacheDefinition = {
val c: Config = configValue.atKey("c")
val factoryName: String = c.getString("c.factory")
val isDefault: Boolean = c.hasPath("c.default") match {
case true => c.getBoolean("c.default")
case _ => false
}
val factoryConfig = c.getObject("c.config")
CacheDefinition(factoryName, isDefault, factoryConfig)
}
}
开发者ID:psycho-ir,项目名称:cachecool,代码行数:21,代码来源:CacheDefinition.scala
示例7: CachecoolModule
//设置package包名称以及导入依赖的类
package de.zalando.cachecool.playmodule
import com.google.inject.name.Names
import com.typesafe.config.{ConfigObject, ConfigValue}
import de.zalando.cachecool.{CacheDefinition, GenericCache, CachecoolFactory}
import play.api.{Configuration, Environment, Logger}
import play.api.inject.{Binding, Module}
import scala.collection.JavaConverters._
class CachecoolModule extends Module {
private val logger = Logger(this.getClass.getName)
override def bindings(environment: Environment, configuration: Configuration): Seq[Binding[_]] = {
val factories = loadCacheFactories(environment, configuration)
val cachecoolCachesConfig: ConfigObject = configuration.getObject("cachecool.caches").getOrElse(throw new RuntimeException("Please provide cache configs"))
val caches = cachecoolCachesConfig.asScala
caches.flatMap { case (name, config) => buildCache(name, config, factories)
}.toSeq
}
def buildCache(name: String, config: ConfigValue, factories: Map[String, CachecoolFactory]): Seq[Binding[_]] = {
val cacheDef = CacheDefinition(config)
val factory = factories.get(cacheDef.factoryName).getOrElse(throw new RuntimeException(s"No factory is defined for ${cacheDef.factoryName}"))
val cache = factory.build(name, cacheDef.factoryConfig, factories)
val default = cacheDef.isDefault match {
case true => Some(bind(classOf[GenericCache]).toInstance(cache))
case _ => None
}
Seq(Some(bind(classOf[GenericCache]).qualifiedWith(Names.named(name)).toInstance(cache)), default).flatten
}
private def loadCacheFactories(environment: Environment, configuration: Configuration): Map[String, CachecoolFactory] = {
val factoriesDefinition = configuration.getObject("cachecool.factories").getOrElse(throw new RuntimeException("Please provide cache factories in config file")).asScala
(factoriesDefinition map {
case (name, className) => {
val clazz: Class[_] = environment.classLoader.loadClass(className.unwrapped().toString)
logger.info(s"Loading cache factory with name:$name and class:${clazz}")
val constructor = clazz.getConstructor(classOf[ClassLoader])
val factoryInstance: CachecoolFactory = constructor.newInstance(environment.classLoader).asInstanceOf[CachecoolFactory]
(name -> factoryInstance)
}
}).toMap
}
}
开发者ID:psycho-ir,项目名称:cachecool,代码行数:53,代码来源:CachecoolModule.scala
示例8: fileWithScalaJSStageSuffix
//设置package包名称以及导入依赖的类
// Project: sbt-node
// Module:
// Description:
package de.surfice.sbtnpm
import sbt._
import Keys._
import Cache._
import com.typesafe.config.{Config, ConfigFactory, ConfigObject}
package object utils {
def fileWithScalaJSStageSuffix(dir: File, filePrefix: String, stage: Scoped, fileSuffix: String): File =
dir / (filePrefix + stage.key.toString.dropRight(2).toLowerCase() + fileSuffix)
implicit final class RichConfig(val config: Config) extends AnyVal {
import collection.JavaConverters._
def getStringMap(path: String): Map[String,String] = config.withOnlyPath(path).entrySet().asScala
.map(p => keySuffix(path,p.getKey) -> config.getString(p.getKey))
.toMap
def getConfigMap(path: String): Map[String,Config] =
config.getObject(path).asScala.map(p => p._1 -> p._2).map {
case (key,obj:ConfigObject) => (key,obj.toConfig)
}.toMap
private def stripQuotes(key: String): String = key.replaceAll("\"","")
private def keySuffix(path: String, key: String): String = stripQuotes(key).stripPrefix(path+".")
}
}
开发者ID:jokade,项目名称:sbt-node,代码行数:31,代码来源:package.scala
示例9: ConfigTemplatesTest
//设置package包名称以及导入依赖的类
package com.vivint.ceph.views
import org.scalatest.{FunSpec, Matchers}
import com.typesafe.config.{ConfigFactory,ConfigObject}
import configs.syntax._
class ConfigTemplatesTest extends FunSpec with Matchers {
val config = ConfigFactory.parseString("""
auth {
number = 1
double = 1.5
boolean = false
string = "very string"
}
""")
describe("renderingSettings") {
it("renders various keys of a config object") {
val cObj = config.get[ConfigObject]("auth").value
ConfigTemplates.renderSettings(cObj) shouldBe (
"""boolean = false
|double = 1.5
|number = 1
|string = "very string"
|""".stripMargin)
}
}
}
开发者ID:vivint-smarthome,项目名称:ceph-on-mesos,代码行数:29,代码来源:ConfigTemplatesTest.scala
注:本文中的com.typesafe.config.ConfigObject类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论