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

Scala Supplier类代码示例

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

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



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

示例1: AzureQueueSink

//设置package包名称以及导入依赖的类
package akka.stream.alpakka.azure.storagequeue.javadsl

import com.microsoft.azure.storage.queue.{CloudQueue, CloudQueueMessage}
import akka.stream.alpakka.azure.storagequeue.{
  AzureQueueSinkFunctions,
  Delete,
  DeleteOrUpdateMessage,
  UpdateVisibility
}
import akka.stream.javadsl.Sink
import akka.Done
import scala.concurrent.Future
import java.util.concurrent.CompletionStage
import java.util.function.Supplier

object AzureQueueSink {

  
  def create(cloudQueue: Supplier[CloudQueue]): Sink[MessageAndDeleteOrUpdate, CompletionStage[Done]] =
    AzureQueueSink.fromFunction[MessageAndDeleteOrUpdate](
      input => AzureQueueSinkFunctions.deleteOrUpdateMessage(() => cloudQueue.get)(input.message, input.op)
    )
} 
开发者ID:akka,项目名称:alpakka,代码行数:24,代码来源:AzureQueueSink.scala


示例2: CorsDirectives

//设置package包名称以及导入依赖的类
package ch.megard.akka.http.cors.javadsl

import java.util.function.Supplier

import akka.http.javadsl.server.{RejectionHandler, Route}
import akka.http.javadsl.server.directives.RouteAdapter
import ch.megard.akka.http.cors.javadsl.settings.CorsSettings
import ch.megard.akka.http.cors.scaladsl

object CorsDirectives {

  def cors(settings: CorsSettings, inner: Supplier[Route]): Route = RouteAdapter {
    // Currently the easiest way to go from Java models to their Scala equivalent is to cast.
    // See https://github.com/akka/akka-http/issues/661 for a potential opening of the JavaMapping API.
    val scalaSettings = settings.asInstanceOf[scaladsl.settings.CorsSettings]
    scaladsl.CorsDirectives.cors(scalaSettings) {
      inner.get() match {
        case ra: RouteAdapter => ra.delegate
      }
    }
  }

  def corsRejectionHandler: RejectionHandler =
    new RejectionHandler(scaladsl.CorsDirectives.corsRejectionHandler)
} 
开发者ID:lomigmegard,项目名称:akka-http-cors,代码行数:26,代码来源:CorsDirectives.scala


示例3: Server

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

import java.io.File
import java.util.function.Supplier
import java.time.Duration 
import io.atomix.copycat.server.{CopycatServer, StateMachine => CopycatStateMachine}
import io.atomix.copycat.server.storage.{Storage, StorageLevel}
import io.atomix.catalyst.transport.Address

import io.mediachain.protocol.Datastore._
import io.mediachain.copycat.StateMachine._

object Server {
  def build(address: String, logdir: String, datastore: Datastore,
            sslConfig: Option[Transport.SSLConfig] = None,
            blocksize: Int = StateMachine.JournalBlockSize)
  : CopycatServer = {
    def stateMachineSupplier() = {
      new Supplier[CopycatStateMachine] {
        override def get: CopycatStateMachine = {
          new JournalStateMachine(datastore, blocksize)
        }
      }
    }
    
    val server = CopycatServer.builder(new Address(address))
      .withStateMachine(stateMachineSupplier())
      .withStorage(Storage.builder()
        .withDirectory(new File(logdir))
        .withStorageLevel(StorageLevel.DISK)
        .build())
      .withTransport(Transport.build(4, sslConfig))
      .withElectionTimeout(Duration.ofSeconds(15))
      .withHeartbeatInterval(Duration.ofSeconds(1))
      .withSessionTimeout(Duration.ofSeconds(30))
      .build()
    Serializers.register(server.serializer)
    server
  }
} 
开发者ID:mediachain,项目名称:oldchain,代码行数:41,代码来源:Server.scala


示例4: CatalogTypeDeSerializer

//设置package包名称以及导入依赖的类
package de.randombyte.nightmare_ai.config

import java.lang.reflect.Type
import java.util.function.Supplier

import com.google.gson._
import org.spongepowered.api.{CatalogType, GameRegistry}


class CatalogTypeDeSerializer[T <: CatalogType](registry: GameRegistry, classOfT: Class[T])
  extends JsonDeserializer[T] with JsonSerializer[T] {
  override def deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): T = {
    registry.getType[T](classOfT, json.getAsString).orElseThrow(new Supplier[JsonParseException] {
      override def get(): JsonParseException =
        new JsonParseException(s"Couldn't find '${json.getAsString}' in GameRegistry")
    })
  }

  override def serialize(catalogType: T, typeOfSrc: Type, context: JsonSerializationContext): JsonElement =
    new JsonPrimitive(catalogType.getId)
} 
开发者ID:randombyte-developer,项目名称:NightmareAI,代码行数:22,代码来源:CatalogTypeDeSerializer.scala


示例5: Retry

//设置package包名称以及导入依赖的类
package com.lightbend.lagom.internal.javadsl.persistence.jpa

import java.util.concurrent.CompletionStage
import java.util.function.Supplier

import akka.actor.Scheduler
import akka.pattern.after

import scala.concurrent.duration.Duration.fromNanos
import scala.concurrent.duration.FiniteDuration
import scala.concurrent.{ ExecutionContext, Future }
import scala.util.control.NonFatal

// With thanks to https://gist.github.com/viktorklang/9414163
private[lagom] class Retry(delay: FiniteDuration, delayFactor: Double, maxRetries: Int) {
  def apply[T](op: => T)(implicit ec: ExecutionContext, s: Scheduler): Future[T] = {
    def iterate(nextDelay: FiniteDuration, remainingRetries: Int): Future[T] =
      Future(op) recoverWith {
        case NonFatal(throwable) if remainingRetries > 0 => {
          onRetry(throwable, nextDelay, remainingRetries)
          after(nextDelay, s)(iterate(finiteMultiply(nextDelay, delayFactor), remainingRetries - 1))
        }
      }

    iterate(delay, maxRetries)
  }

  // For convenient use from Java 8
  def retry[T](op: Supplier[T])(implicit ec: ExecutionContext, s: Scheduler): CompletionStage[T] = {
    import scala.compat.java8.FutureConverters._

    apply(op.get()).toJava
  }

  protected def onRetry(throwable: Throwable, delay: FiniteDuration, remainingRetries: Int): Unit = ()

  private def finiteMultiply(duration: FiniteDuration, factor: Double): FiniteDuration =
    fromNanos((duration.toNanos * factor).toLong)
}

private[lagom] object Retry {
  def apply[T](delay: FiniteDuration, delayFactor: Double, maxRetries: Int)(op: => T)(implicit ec: ExecutionContext, s: Scheduler): Future[T] =
    (new Retry(delay, delayFactor, maxRetries))(op)
} 
开发者ID:lagom,项目名称:lagom,代码行数:45,代码来源:Retry.scala


示例6: ConfigurationServiceLocatorSpec

//设置package包名称以及导入依赖的类
package com.lightbend.lagom.javadsl.client

import java.net.URI
import java.util.concurrent.{ CompletionStage, TimeUnit }
import java.util.function.Supplier
import com.typesafe.config.ConfigFactory
import org.scalatest.{ Matchers, WordSpec }

import scala.compat.java8.OptionConverters._

class ConfigurationServiceLocatorSpec extends WordSpec with Matchers {

  val serviceLocator = new ConfigurationServiceLocator(ConfigFactory.parseString(
    """
      |lagom.services {
      |  foo = "http://localhost:10001"
      |  bar = "http://localhost:10002"
      |}
    """.stripMargin
  ), new CircuitBreakersPanel {
    override def withCircuitBreaker[T](id: String, body: Supplier[CompletionStage[T]]): CompletionStage[T] = body.get()
  })

  def locate(serviceName: String) =
    serviceLocator.locate(serviceName).toCompletableFuture.get(10, TimeUnit.SECONDS).asScala

  "ConfigurationServiceLocator" should {
    "return a found service" in {
      locate("foo") should contain(URI.create("http://localhost:10001"))
      locate("bar") should contain(URI.create("http://localhost:10002"))
    }
    "return none for not found service" in {
      locate("none") shouldBe None
    }
  }

} 
开发者ID:lagom,项目名称:lagom,代码行数:38,代码来源:ConfigurationServiceLocatorSpec.scala


示例7: ServiceSpecBuilder

//设置package包名称以及导入依赖的类
package com.github.sedovalx.cassandra.service.generation.builders

import java.util.function.Supplier
import javax.lang.model.element.Modifier

import com.datastax.driver.mapping.MappingManager
import com.squareup.javapoet.{ParameterizedTypeName, MethodSpec, ClassName, TypeSpec}
import com.github.sedovalx.cassandra.service.generation.metadata.TableMetadata

import scala.collection.JavaConverters._


class ServiceSpecBuilder(accessor: Option[ClassName], mapper: Option[ClassName], tableMetadata: TableMetadata) {
    def buildSpec(): TypeSpec = {
        var methodSpecs = Seq.empty[MethodSpec]
        val mappingSupplierType = ParameterizedTypeName.get(
            ClassName.get(classOf[Supplier[_]]),
            ClassName.get(classOf[MappingManager])
        )
        var specBuilder = TypeSpec.classBuilder(tableMetadata.entityName + tableMetadata.serviceSuffix)
            .addModifiers(Modifier.PUBLIC)
            .addField(mappingSupplierType, "mappingManagerSupplier", Modifier.PRIVATE)

        val ctrBuilder = MethodSpec.constructorBuilder()
            .addModifiers(Modifier.PUBLIC)
            .addParameter(mappingSupplierType, "mappingManagerSupplier")
            .addStatement("this.mappingManagerSupplier = mappingManagerSupplier")

        if (accessor.isDefined){
            methodSpecs = methodSpecs :+ MethodSpec.methodBuilder("accessor")
                .addModifiers(Modifier.PUBLIC)
                .returns(accessor.get)
                .beginControlFlow("if (this.accessor == null)")
                .addStatement("this.accessor = new $T(this.mappingManagerSupplier.get())", accessor.get)
                .endControlFlow()
                .addStatement("return this.accessor")
                .build()
            specBuilder = specBuilder.addField(accessor.get, "accessor", Modifier.PRIVATE)
        }

        if (mapper.isDefined) {
            methodSpecs = methodSpecs :+ MethodSpec.methodBuilder("mapper")
                .addModifiers(Modifier.PUBLIC)
                .returns(mapper.get)
                .beginControlFlow("if (this.mapper == null)")
                .addStatement("this.mapper = new $T(this.mappingManagerSupplier.get())", mapper.get)
                .endControlFlow()
                .addStatement("return this.mapper")
                .build()
            specBuilder = specBuilder.addField(mapper.get, "mapper", Modifier.PRIVATE)
        }

        specBuilder.addMethod(ctrBuilder.build()).addMethods(methodSpecs.asJava).build()
    }
} 
开发者ID:sedovalx,项目名称:cassandra-service-generator,代码行数:56,代码来源:ServiceSpecBuilder.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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