Java Code Examples for reactor.core.publisher.Mono#thenReturn()
The following examples show how to use
reactor.core.publisher.Mono#thenReturn() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LifecycleDispatchHandlers.java From Discord4J with GNU Lesser General Public License v3.0 | 6 votes |
static Mono<ReadyEvent> ready(DispatchContext<Ready> context) { GatewayDiscordClient gateway = context.getGateway(); Ready dispatch = context.getDispatch(); UserData userData = dispatch.user(); long userId = Snowflake.asLong(userData.id()); User self = new User(gateway, userData); Set<ReadyEvent.Guild> guilds = dispatch.guilds() .stream() .map(g -> new ReadyEvent.Guild(Snowflake.asLong(g.id()), !g.unavailable().get())) .collect(Collectors.toSet()); Mono<Void> saveUser = context.getStateHolder().getUserStore() .save(userId, userData); return saveUser .thenReturn(new ReadyEvent(gateway, context.getShardInfo(), dispatch.v(), self, guilds, dispatch.sessionId(), dispatch.trace())); }
Example 2
Source File: MessageDispatchHandlers.java From Discord4J with GNU Lesser General Public License v3.0 | 6 votes |
static Mono<ReactionRemoveAllEvent> messageReactionRemoveAll(DispatchContext<MessageReactionRemoveAll> context) { GatewayDiscordClient gateway = context.getGateway(); long channelId = Snowflake.asLong(context.getDispatch().channelId()); long messageId = Snowflake.asLong(context.getDispatch().messageId()); Long guildId = context.getDispatch().guildId() .toOptional() .map(Snowflake::asLong) .orElse(null); Mono<Void> removeAllFromMessage = context.getStateHolder().getMessageStore() .find(messageId) .map(message -> MessageData.builder() .from(message) .reactions(Possible.absent()) .build()) .flatMap(message -> context.getStateHolder().getMessageStore().save(messageId, message)); return removeAllFromMessage.thenReturn(new ReactionRemoveAllEvent(gateway, context.getShardInfo(), channelId, messageId, guildId)); }
Example 3
Source File: RequestStream.java From Discord4J with GNU Lesser General Public License v3.0 | 5 votes |
public RequestSubscriber(RateLimitStrategy strategy) { this.responseFunction = response -> { HttpClientResponse httpResponse = response.getHttpResponse(); if (log.isDebugEnabled()) { Instant requestTimestamp = Instant.ofEpochMilli(httpResponse.currentContext().get(DiscordWebClient.KEY_REQUEST_TIMESTAMP)); Duration responseTime = Duration.between(requestTimestamp, Instant.now()); LogUtil.traceDebug(log, trace -> format(httpResponse.currentContext(), "Read " + httpResponse.status() + " in " + responseTime + (!trace ? "" : " with headers: " + httpResponse.responseHeaders()))); } Duration nextReset = strategy.apply(httpResponse); if (!nextReset.isZero()) { if (log.isDebugEnabled()) { log.debug(format(httpResponse.currentContext(), "Delaying next request by {}"), nextReset); } sleepTime = nextReset; } boolean global = Boolean.parseBoolean(httpResponse.responseHeaders().get("X-RateLimit-Global")); Mono<Void> action = Mono.empty(); if (global) { long retryAfter = Long.parseLong(httpResponse.responseHeaders().get("Retry-After")); Duration fixedBackoff = Duration.ofMillis(retryAfter); action = globalRateLimiter.rateLimitFor(fixedBackoff) .doOnTerminate(() -> log.debug(format(httpResponse.currentContext(), "Globally rate limited for {}"), fixedBackoff)); } if (httpResponse.status().code() >= 400) { return action.then(response.createException().flatMap(Mono::error)); } else { return action.thenReturn(response); } }; }
Example 4
Source File: CassandraDumbBlobStore.java From james-project with Apache License 2.0 | 5 votes |
private Mono<?> writePart(BucketName bucketName, BlobId blobId, int position, ByteBuffer data) { Mono<?> write; if (isDefaultBucket(bucketName)) { write = defaultBucketDAO.writePart(data, blobId, position); } else { write = bucketDAO.writePart(data, bucketName, blobId, position); } int anyNonEmptyValue = 1; return write.thenReturn(anyNonEmptyValue); }