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