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

Scala ConfigValue类代码示例

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

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



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

示例1: deriveEnumValueSet

//设置package包名称以及导入依赖的类
package wow.common

import com.typesafe.config.{ConfigList, ConfigObject, ConfigValue, ConfigValueType}
import pureconfig.ConvertHelpers._
import pureconfig.error.{ConfigReaderFailures, ConfigValueLocation, WrongType}
import pureconfig.{ConfigConvert, ConfigReader}
import shapeless.Lazy

import scala.collection.JavaConverters._
import scala.collection.mutable


  implicit def deriveEnumValueSet[A <: Enumeration](implicit e: A) = new ConfigReader[e.ValueSet] {
    val valueConvert = deriveEnumValue[A](e)

    override def from(config: ConfigValue): Either[ConfigReaderFailures, e.ValueSet] = {
      config match {
        case co: ConfigList =>
          val baseValue: Either[ConfigReaderFailures, mutable.Builder[e.Value, e.ValueSet]] = Right(e.ValueSet
            .newBuilder)

          // we called all the failures in the list
          co.asScala.foldLeft(baseValue) {
            case (acc, value) =>
              combineResults(acc, valueConvert.from(value)) { case (a, b) => a += e(b.id) }
          }.right.map(_.result())
        case other =>
          fail(WrongType(other.valueType, Set(ConfigValueType.LIST), ConfigValueLocation(other), None))
      }
    }
  }
} 
开发者ID:SKNZ,项目名称:SpinaciCore,代码行数:33,代码来源:package.scala


示例2: 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


示例3: self

//设置package包名称以及导入依赖的类
package gv
package isi
package typesafe.config

import com.typesafe.config.{ Config ? TsConfig, ConfigObject ? TsConfigObject, ConfigValue, ConfigValueType }

trait ConfigDecorationOps extends Any {
  def self: ConfigValue

  final def ifType(t: ConfigValueType): Option[Object] =
    if (self.valueType == t)
      Some(self.unwrapped)
    else
      None

  final def asString: Option[String] = ifType(ConfigValueType.STRING) map (_.asInstanceOf[String])

  final def asConfigObject: Option[TsConfigObject] = ifType(ConfigValueType.OBJECT) map (_ ? self.asInstanceOf[TsConfigObject])

  final def asConfig: Option[TsConfig] = asConfigObject map (_.toConfig)
} 
开发者ID:mouchtaris,项目名称:jleon,代码行数:22,代码来源:ConfigDecorationOps.scala


示例4: FeeSettings

//设置package包名称以及导入依赖的类
package com.wavesplatform.settings

import java.util.Map.Entry
import scala.collection.JavaConverters._
import scala.util.Try
import com.google.common.base.CaseFormat
import com.typesafe.config.ConfigException.BadValue
import com.typesafe.config.{Config, ConfigValue}
import scorex.transaction.TransactionParser.TransactionType

case class FeeSettings(asset: String, fee: Long)

case class FeesSettings(fees: Map[Int, List[FeeSettings]])

object FeesSettings {
  val configPath: String = "waves.fees"

  private val converter = CaseFormat.LOWER_HYPHEN.converterTo(CaseFormat.UPPER_CAMEL)
  private def toTxType(key: String): TransactionType.Value =
    TransactionType.withName(s"${converter.convert(key)}Transaction")

  def fromConfig(config: Config): FeesSettings = {
    val feesEntries = config.entrySet().asScala.filter(_.getKey startsWith configPath)
    val fees = feesEntries.foldLeft(Map[Int, List[FeeSettings]]()) { (map, e) =>
      val p = toFeeSettings(e)
      map.updated(p._1, map.getOrElse(p._1, List()) :+ p._2)
    }

    FeesSettings(fees)
  }

  private def toFeeSettings(e: Entry[String, ConfigValue]): (Int, FeeSettings) = {
    val s = e.getKey.replace(s"$configPath.", "").trim
    val parts = s.split("\\.", 2)
    val (transactionTypeName, asset) = (parts(0), parts(1))
    val transactionType = toTxType(transactionTypeName).id

    val feeString = e.getValue.render
    val triedFee = Try(feeString.toLong)

    if (triedFee.isFailure) throw new BadValue(e.getKey, s"Failed to convert $feeString to long value", triedFee.failed.get)

    transactionType -> FeeSettings(asset, triedFee.get)
  }
} 
开发者ID:wavesplatform,项目名称:Waves,代码行数:46,代码来源:FeesSettings.scala


示例5: 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


示例6: 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


示例7: QuoteProfileTest

//设置package包名称以及导入依赖的类
package models

import com.typesafe.config.{ConfigFactory, ConfigList, ConfigValue, ConfigObject}
import org.scalatest.{FunSpec, Matchers}
import spray.json._

import scala.collection.JavaConverters._

class QuoteProfileTest extends FunSpec with Matchers {
  val thing = ConfigFactory.load("fares").getConfigList("quoteProfiles")
  val vehicles: ConfigList = ConfigFactory.load("fares").getList("quoteProfiles")
  val myList: List[ConfigValue] = ConfigFactory.load("fares").getList("quoteProfiles").asScala.toList
  val any = test.AnySingleton

  describe("testConstructor") {
    val quote: QuoteProfile = QuoteProfile(
      name = "Vehicle Name",
      description = "Vehicle Description",
      vehicleCode = "VEHCODE",
      maxPassengers = 4,
      fareProfiles = List(any.fareProfile)
    )

    val json = quote.toJson.toString

    it("serializes correctly") {
      val qp = json.parseJson.convertTo[QuoteProfile]
      qp shouldEqual quote
    }
  }
  describe("fromConfig") {
    it("works") {
      val vehicles = FareConfig.vehicles
      System.out.println(vehicles)
      true shouldEqual true
    }
  }
} 
开发者ID:greghxc,项目名称:shakespeare,代码行数:39,代码来源:QuoteProfileTest.scala


示例8: parseConfigFile

//设置package包名称以及导入依赖的类
package me.pzang

import com.typesafe.config.{Config, ConfigFactory, ConfigValue}

import scala.collection.JavaConversions._


trait ConfigParser {

  def parseConfigFile(file: String) = {
    val conf: Config = ConfigFactory.load(file)
    val rootMap: Map[String, ConfigValue] = conf.entrySet().map(entry => entry.getKey -> entry.getValue).toMap
    rootMap.map {
      case (key, subConf) => {
        subConf
      }
    }
  }
} 
开发者ID:pzang,项目名称:config-sbt-plugin,代码行数:20,代码来源:ConfigParser.scala


示例9: JtConfig

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

import java.util.Map.Entry

import com.typesafe.config.{ConfigValue, Config, ConfigFactory}


object JtConfig {
  private val appConf = ConfigFactory.load()
  private val refConf = ConfigFactory.defaultReference()
  val config = appConf.withFallback(refConf).resolve()

  def checkValid(config: Config, pathPrefix: String): Unit = {
    config.checkValid(refConf, pathPrefix)
    val configKeys = getConfigKeys(config, pathPrefix)
    val refKeys = getConfigKeys(refConf, pathPrefix)
    val keysNotInRef = configKeys.diff(refKeys)
    if (keysNotInRef.nonEmpty) throw new IllegalArgumentException(s"Unknown config keys: ${keysNotInRef.mkString(", ")}")
  }

  private def getConfigKeys(config: Config, pathPrefix: String): Set[String] = {
    val es = config.entrySet()
    val kvArray: Array[Entry[String, ConfigValue]] = es.toArray(new Array(es.size))
    kvArray.map(_.getKey).filter(_.startsWith(pathPrefix)).toSet
  }

} 
开发者ID:joeytsai,项目名称:mysql-starter,代码行数:28,代码来源:JtConfig.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala Merge类代码示例发布时间:2022-05-23
下一篇:
Scala Consumer类代码示例发布时间: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