本文整理汇总了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)
}
}
}
示例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))
}
示例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
)