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


Scala JsonDeserialize类代码示例

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


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

示例1: TracelogInitializer

//设置package包名称以及导入依赖的类
package io.buoyant.telemetry

import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.twitter.finagle.Stack
import com.twitter.finagle.buoyant.Sampler
import com.twitter.finagle.stats.NullStatsReceiver
import com.twitter.finagle.tracing.{Record, Trace, TraceId, Tracer}
import com.twitter.logging.{Level, Logger}

class TracelogInitializer extends TelemeterInitializer {
  type Config = TracelogConfig
  val configClass = classOf[TracelogConfig]
  override val configId = "io.l5d.tracelog"
}

case class TracelogConfig(
  @JsonDeserialize(contentAs = classOf[java.lang.Double]) sampleRate: Option[Double],
  level: Option[Level]
) extends TelemeterConfig {

  private[this] val sampleRateD: Double =
    sampleRate.getOrElse(1.0).min(1.0).max(0.0)

  private[this] val logger = Logger.get("io.l5d.tracelog")
  def mk(params: Stack.Params): TracelogTelemeter =
    new TracelogTelemeter(logger, level.getOrElse(Level.INFO), Sampler(sampleRateD.toFloat))
}

class TracelogTelemeter(logger: Logger, level: Level, sampler: Sampler) extends Telemeter {
  val stats = NullStatsReceiver
  lazy val tracer = new TracelogTracer(logger, level, sampler)
  def run() = Telemeter.nopRun
}

class TracelogTracer(logger: Logger, level: Level, sample: Sampler) extends Tracer {

  // This tracer doesn't influence downstream tracing.
  def sampleTrace(id: TraceId): Option[Boolean] = None

  def record(record: Record): Unit = {
    val id = record.traceId
    if (id.sampled.getOrElse(sample(id.traceId.toLong))) {
      logger.log(level, "%s", record)
    }
  }

} 
开发者ID:linkerd,项目名称:linkerd,代码行数:48,代码来源:TracelogInitializer.scala

示例2: RecentRequestsInitializer

//设置package包名称以及导入依赖的类
package io.buoyant.telemetry.recentRequests

import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.twitter.finagle.Stack.Params
import io.buoyant.telemetry.{Telemeter, TelemeterConfig, TelemeterInitializer}

class RecentRequestsInitializer extends TelemeterInitializer {
  type Config = RecentRequestsConfig
  override val configId = "io.l5d.recentRequests"
  val configClass = classOf[RecentRequestsConfig]
}

case class RecentRequestsConfig(
  @JsonDeserialize(contentAs = classOf[java.lang.Double]) sampleRate: Option[Double],
  capacity: Option[Int] = None
) extends TelemeterConfig {
  @JsonIgnore
  private[this] val _sampleRate = sampleRate
    .filter(r => r >= 0.0 && r <= 1.0)
    .getOrElse(throw new IllegalArgumentException("sampleRate must be between 0.0 and 1.0"))

  @JsonIgnore
  override def mk(params: Params): Telemeter =
    new RecentRequestsTelemeter(_sampleRate, capacity.getOrElse(10))
} 
开发者ID:linkerd,项目名称:linkerd,代码行数:27,代码来源:RecentRequestsInitializer.scala

示例3: RetryBudgetModule

//设置package包名称以及导入依赖的类
package io.buoyant.router

import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.twitter.conversions.time._
import com.twitter.finagle.{ServiceFactory, Stack}
import com.twitter.finagle.service.{Backoff, Retries, RetryBudget}
import com.twitter.util.Duration

object RetryBudgetModule {

  val Role = Stack.Role("RetryBudget")

  def module[Req, Rsp] = new Stack.Module[ServiceFactory[Req, Rsp]] {
    override val role = RetryBudgetModule.Role
    override val description = "Instantiate a new retry budget"
    override val parameters = Seq(implicitly[Stack.Param[RetryBudgetConfig]])

    def make(params: Stack.Params, next: Stack[ServiceFactory[Req, Rsp]]): Stack[ServiceFactory[Req, Rsp]] = {
      // The backoff here is a _requeue_ backoff and not used by the path stack.
      // See ClassifieredRetries.Backoffs for the backoff that is actually used in
      // the path stack.
      val budget = Retries.Budget(mkBudget(params[RetryBudgetConfig]), Backoff.constant(Duration.Zero))
      Stack.Leaf(role, next.make(params + budget))
    }
  }

  implicit val param: Stack.Param[RetryBudgetConfig] = Stack.Param(RetryBudgetConfig())

  private def mkBudget(config: RetryBudgetConfig): RetryBudget = {
    val ttl = config.ttlSecs.map(_.seconds).getOrElse(10.seconds)
    RetryBudget(ttl, config.minRetriesPerSec.getOrElse(10), config.percentCanRetry.getOrElse(0.2))
  }
}

case class RetryBudgetConfig(
  ttlSecs: Option[Int] = None,
  minRetriesPerSec: Option[Int] = None,
  @JsonDeserialize(contentAs = classOf[java.lang.Double]) percentCanRetry: Option[Double] = None
) 
开发者ID:linkerd,项目名称:linkerd,代码行数:40,代码来源:RetryBudgetModule.scala


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