本文整理了Java中reactor.core.publisher.Mono.just()
方法的一些代码示例,展示了Mono.just()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mono.just()
方法的具体详情如下:
包路径:reactor.core.publisher.Mono
类名称:Mono
方法名:just
[英]Create a new Mono that emits the specified item, which is captured at instantiation time.
[中]创建一个新的Mono,该Mono发出指定的项,该项在实例化时被捕获。
代码示例来源:origin: spring-projects/spring-security
public final Mono<AbstractAuthenticationToken> convert(Jwt jwt) {
return Mono.just(jwt).map(this.delegate::convert);
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Return a filter that generates an error signal when the given
* {@link HttpStatus} predicate matches.
* @param statusPredicate the predicate to check the HTTP status with
* @param exceptionFunction the function that to create the exception
* @return the filter to generate an error signal
*/
public static ExchangeFilterFunction statusError(Predicate<HttpStatus> statusPredicate,
Function<ClientResponse, ? extends Throwable> exceptionFunction) {
Assert.notNull(statusPredicate, "Predicate must not be null");
Assert.notNull(exceptionFunction, "Function must not be null");
return ExchangeFilterFunction.ofResponseProcessor(
response -> (statusPredicate.test(response.statusCode()) ?
Mono.error(exceptionFunction.apply(response)) : Mono.just(response)));
}
代码示例来源:origin: spring-projects/spring-data-redis
/**
* Get multiple values in one batch.
*
* @param keys must not be {@literal null}.
* @return
* @see <a href="http://redis.io/commands/mget">Redis Documentation: MGET</a>
*/
default Mono<List<ByteBuffer>> mGet(List<ByteBuffer> keys) {
Assert.notNull(keys, "Keys must not be null!");
return mGet(Mono.just(keys)).next().map(MultiValueResponse::getOutput);
}
代码示例来源:origin: codecentric/spring-boot-admin
/**
* Register instance.
*
* @param registration instance to be registered.
* @return the if of the registered instance.
*/
public Mono<InstanceId> register(Registration registration) {
Assert.notNull(registration, "'registration' must not be null");
InstanceId id = generator.generateId(registration);
Assert.notNull(id, "'id' must not be null");
return repository.compute(id, (key, instance) -> {
if (instance == null) {
instance = Instance.create(key);
}
return Mono.just(instance.register(registration));
}).map(Instance::getId);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Inserter to write the given {@code Resource}.
* <p>If the resource can be resolved to a {@linkplain Resource#getFile() file}, it will
* be copied using <a href="https://en.wikipedia.org/wiki/Zero-copy">zero-copy</a>.
* @param resource the resource to write to the output message
* @param <T> the type of the {@code Resource}
* @return the inserter to write a {@code Publisher}
*/
public static <T extends Resource> BodyInserter<T, ReactiveHttpOutputMessage> fromResource(T resource) {
Assert.notNull(resource, "Resource must not be null");
return (outputMessage, context) -> {
ResolvableType elementType = RESOURCE_TYPE;
HttpMessageWriter<Resource> writer = findWriter(context, elementType, null);
return write(Mono.just(resource), elementType, null, outputMessage, context, writer);
};
}
代码示例来源:origin: spring-projects/spring-framework
@Nullable
private String formatBody(@Nullable MediaType contentType, Mono<byte[]> body) {
return body
.map(bytes -> {
if (contentType == null) {
return bytes.length + " bytes of content (unknown content-type).";
}
Charset charset = contentType.getCharset();
if (charset != null) {
return new String(bytes, charset);
}
if (PRINTABLE_MEDIA_TYPES.stream().anyMatch(contentType::isCompatibleWith)) {
return new String(bytes, StandardCharsets.UTF_8);
}
return bytes.length + " bytes of content.";
})
.defaultIfEmpty("No content")
.onErrorResume(ex -> Mono.just("Failed to obtain content: " + ex.getMessage()))
.block(this.timeout);
}
代码示例来源:origin: spring-projects/spring-data-redis
/**
* Delete {@literal key}.
*
* @param key must not be {@literal null}.
* @return
* @see <a href="http://redis.io/commands/del">Redis Documentation: DEL</a>
*/
default Mono<Long> del(ByteBuffer key) {
Assert.notNull(key, "Key must not be null!");
return del(Mono.just(new KeyCommand(key))).next().map(NumericResponse::getOutput);
}
代码示例来源:origin: spring-projects/spring-framework
private Mono<DataBuffer> encodeText(CharSequence text, MediaType mediaType, DataBufferFactory bufferFactory) {
Assert.notNull(mediaType.getCharset(), "Expected MediaType with charset");
byte[] bytes = text.toString().getBytes(mediaType.getCharset());
return Mono.defer(() ->
Mono.just(bufferFactory.allocateBuffer(bytes.length).write(bytes)));
}
代码示例来源:origin: codecentric/spring-boot-admin
/**
* Remove a specific instance from services
*
* @param id the instances id to unregister
* @return the id of the unregistered instance
*/
public Mono<InstanceId> deregister(InstanceId id) {
return repository.computeIfPresent(id, (key, instance) -> Mono.just(instance.deregister()))
.map(Instance::getId);
}
}
代码示例来源:origin: spring-projects/spring-data-redis
/**
* Increment value of {@literal key} by 1.
*
* @param key must not be {@literal null}.
* @return
* @see <a href="http://redis.io/commands/incr">Redis Documentation: INCR</a>
*/
default Mono<Long> incr(ByteBuffer key) {
Assert.notNull(key, "Key must not be null!");
return incr(Mono.just(new KeyCommand(key))).next().map(NumericResponse::getOutput);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<Void> write(Publisher<? extends MultiValueMap<String, String>> inputStream,
ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message,
Map<String, Object> hints) {
mediaType = getMediaType(mediaType);
message.getHeaders().setContentType(mediaType);
Charset charset = mediaType.getCharset();
Assert.notNull(charset, "No charset"); // should never occur
return Mono.from(inputStream).flatMap(form -> {
logFormData(form, hints);
String value = serializeForm(form, charset);
ByteBuffer byteBuffer = charset.encode(value);
DataBuffer buffer = message.bufferFactory().wrap(byteBuffer);
message.getHeaders().setContentLength(byteBuffer.remaining());
return message.writeWith(Mono.just(buffer));
});
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected Mono<String> resolveUrlPathInternal(String resourceUrlPath,
List<? extends Resource> locations, ResourceResolverChain chain) {
return chain.resolveUrlPath(resourceUrlPath, locations)
.flatMap(baseUrl -> {
if (StringUtils.hasText(baseUrl)) {
VersionStrategy strategy = getStrategyForPath(resourceUrlPath);
if (strategy == null) {
return Mono.just(baseUrl);
}
return chain.resolveResource(null, baseUrl, locations)
.flatMap(resource -> strategy.getResourceVersion(resource)
.map(version -> strategy.addVersion(baseUrl, version)));
}
return Mono.empty();
});
}
代码示例来源:origin: spring-projects/spring-data-redis
/**
* Determine the type stored at {@literal key}.
*
* @param key must not be {@literal null}.
* @return
* @see <a href="http://redis.io/commands/type">Redis Documentation: TYPE</a>
*/
default Mono<DataType> type(ByteBuffer key) {
Assert.notNull(key, "Key must not be null!");
return type(Mono.just(new KeyCommand(key))).next().map(CommandResponse::getOutput);
}
代码示例来源:origin: org.springframework/spring-web
private Mono<DataBuffer> encodeText(CharSequence text, MediaType mediaType, DataBufferFactory bufferFactory) {
Assert.notNull(mediaType.getCharset(), "Expected MediaType with charset");
byte[] bytes = text.toString().getBytes(mediaType.getCharset());
return Mono.defer(() ->
Mono.just(bufferFactory.allocateBuffer(bytes.length).write(bytes)));
}
代码示例来源:origin: spring-projects/spring-framework
private Mono<? extends Resource> transform(String content, Resource resource,
ResourceTransformerChain chain, ServerWebExchange exchange) {
if (!content.startsWith(MANIFEST_HEADER)) {
if (logger.isTraceEnabled()) {
logger.trace(exchange.getLogPrefix() +
"Skipping " + resource + ": Manifest does not start with 'CACHE MANIFEST'");
}
return Mono.just(resource);
}
return Flux.generate(new LineInfoGenerator(content))
.concatMap(info -> processLine(info, exchange, resource, chain))
.reduce(new ByteArrayOutputStream(), (out, line) -> {
writeToByteArrayOutputStream(out, line + "\n");
return out;
})
.map(out -> {
String hash = DigestUtils.md5DigestAsHex(out.toByteArray());
writeToByteArrayOutputStream(out, "\n" + "# Hash: " + hash);
return new TransformedResource(resource, out.toByteArray());
});
}
代码示例来源:origin: spring-projects/spring-data-redis
/**
* Remove the expiration from given {@code key}.
*
* @param key must not be {@literal null}.
* @return
* @see <a href="http://redis.io/commands/persist">Redis Documentation: PERSIST</a>
*/
default Mono<Boolean> persist(ByteBuffer key) {
Assert.notNull(key, "Key must not be null!");
return persist(Mono.just(new KeyCommand(key))).next().map(BooleanResponse::getOutput);
}
代码示例来源:origin: spring-projects/spring-data-redis
/**
* Get key set (fields) of hash at {@literal key}.
*
* @param key must not be {@literal null}.
* @return
* @see <a href="http://redis.io/commands/hkeys">Redis Documentation: HKEYS</a>
*/
default Flux<ByteBuffer> hKeys(ByteBuffer key) {
Assert.notNull(key, "Key must not be null!");
return hKeys(Mono.just(new KeyCommand(key))).flatMap(CommandResponse::getOutput);
}
代码示例来源:origin: spring-projects/spring-framework
private Mono<? extends Resource> transformContent(String cssContent, Resource resource,
ResourceTransformerChain chain, ServerWebExchange exchange) {
List<ContentChunkInfo> contentChunkInfos = parseContent(cssContent);
if (contentChunkInfos.isEmpty()) {
return Mono.just(resource);
}
return Flux.fromIterable(contentChunkInfos)
.concatMap(contentChunkInfo -> {
String contentChunk = contentChunkInfo.getContent(cssContent);
if (contentChunkInfo.isLink() && !hasScheme(contentChunk)) {
String link = toAbsolutePath(contentChunk, exchange);
return resolveUrlPath(link, exchange, resource, chain).defaultIfEmpty(contentChunk);
}
else {
return Mono.just(contentChunk);
}
})
.reduce(new StringWriter(), (writer, chunk) -> {
writer.write(chunk);
return writer;
})
.map(writer -> {
byte[] newContent = writer.toString().getBytes(DEFAULT_CHARSET);
return new TransformedResource(resource, newContent);
});
}
代码示例来源:origin: spring-projects/spring-data-redis
/**
* Get the size of the stream stored at {@literal key}.
*
* @param key must not be {@literal null}.
* @return {@link Mono} emitting the length of the stream.
* @see <a href="http://redis.io/commands/xlen">Redis Documentation: XLEN</a>
*/
default Mono<Long> xLen(ByteBuffer key) {
Assert.notNull(key, "Key must not be null!");
return xLen(Mono.just(new KeyCommand(key))).next().map(NumericResponse::getOutput);
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public Flux<CommandResponse<SUnionCommand, Flux<ByteBuffer>>> sUnion(Publisher<SUnionCommand> commands) {
return getConnection().execute(cmd -> Flux.from(commands).concatMap(command -> {
Assert.notNull(command.getKeys(), "Keys must not be null!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(command.getKeys())) {
return super.sUnion(Mono.just(command));
}
Flux<ByteBuffer> result = Flux.merge(command.getKeys().stream().map(cmd::smembers).collect(Collectors.toList()))
.distinct();
return Mono.just(new CommandResponse<>(command, result));
}));
}
内容来源于网络,如有侵权,请联系作者删除!