Java Code Examples for reactor.core.publisher.Mono#fromRunnable()
The following examples show how to use
reactor.core.publisher.Mono#fromRunnable() .
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: ImageService.java From Learning-Spring-Boot-2.0-Second-Edition with MIT License | 6 votes |
public Mono<Void> deleteImage(String filename) { Mono<Void> deleteDatabaseImage = imageRepository .findByName(filename) .flatMap(imageRepository::delete); Mono<Void> deleteFile = Mono.fromRunnable(() -> { try { Files.deleteIfExists( Paths.get(UPLOAD_ROOT, filename)); } catch (IOException e) { throw new RuntimeException(e); } }); return Mono.when(deleteDatabaseImage, deleteFile) .then(); }
Example 2
Source File: ActorRuntimeTest.java From java-sdk with MIT License | 5 votes |
public Mono<Void> onActivate() { return Mono.fromRunnable(() -> { if (this.activated != null) { throw new IllegalStateException("already activated once"); } this.activated = true; }); }
Example 3
Source File: ImageService.java From Learning-Spring-Boot-2.0-Second-Edition with MIT License | 5 votes |
public Mono<Void> deleteImage(String filename) { return Mono.fromRunnable(() -> { try { Files.deleteIfExists(Paths.get(UPLOAD_ROOT, filename)); } catch (IOException e) { throw new RuntimeException(e); } }); }
Example 4
Source File: JpaCurrentQuotaManager.java From james-project with Apache License 2.0 | 5 votes |
@Override public Mono<Void> decrease(QuotaOperation quotaOperation) { return Mono.fromRunnable(() -> transactionRunner.run( entityManager -> { QuotaRoot quotaRoot = quotaOperation.quotaRoot(); JpaCurrentQuota jpaCurrentQuota = Optional.ofNullable(retrieveUserQuota(entityManager, quotaRoot)) .orElse(new JpaCurrentQuota(quotaRoot.getValue(), NO_MESSAGES, NO_STORED_BYTES)); entityManager.merge(new JpaCurrentQuota(quotaRoot.getValue(), jpaCurrentQuota.getMessageCount().asLong() - quotaOperation.count().asLong(), jpaCurrentQuota.getSize().asLong() - quotaOperation.size().asLong())); })); }
Example 5
Source File: StubbedDirectKubeApiServerIntegrator.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Override public Mono<Void> terminateTask(Task task) { return Mono.fromRunnable(() -> { if (podHoldersByTaskId.remove(task.getId()) == null) { throw new IllegalArgumentException("Task not found: " + task.getId()); } }); }
Example 6
Source File: ConfigurationServiceMVStoreImpl.java From alibaba-rsocket-broker with Apache License 2.0 | 5 votes |
@Override public Mono<Void> put(String key, String value) { return Mono.fromRunnable(() -> { String[] parts = key.split(":", 2); if (parts.length == 2) { mvStore.openMap(parts[0]).put(parts[1], value); mvStore.commit(); if (!watchNotification.containsKey(key)) { initNotification(key); } watchNotification.get(key).onNext(value); } }); }
Example 7
Source File: ReactorEntityStore.java From requery with Apache License 2.0 | 5 votes |
@Override public <E extends T> Mono<Void> delete(final Iterable<E> entities) { return Mono.fromRunnable(new Runnable() { @Override public void run() { delegate.delete(entities); } }); }
Example 8
Source File: GrpcClient.java From cloud-spanner-r2dbc with Apache License 2.0 | 5 votes |
@Override public Mono<Void> close() { return Mono.fromRunnable(() -> { if (this.channel != null) { this.channel.shutdownNow(); } }); }
Example 9
Source File: TcpServerDeviceGateway.java From jetlinks-community with Apache License 2.0 | 5 votes |
@Override public Mono<Void> shutdown() { return Mono.fromRunnable(() -> { started.set(false); disposable.forEach(Disposable::dispose); disposable.clear(); }); }
Example 10
Source File: ActorNoStateTest.java From java-sdk with MIT License | 5 votes |
@Override public Mono<Void> stringInVoidOutIntentionallyThrows(String input) { return Mono.fromRunnable(() -> { // IllegalMonitorStateException is being thrown only because it's un unusual exception so it's unlikely // to collide with something else. throw new IllegalMonitorStateException("IntentionalException"); }); }
Example 11
Source File: ReactiveMapSessionRepository.java From spring-session with Apache License 2.0 | 5 votes |
@Override public Mono<Void> save(MapSession session) { return Mono.fromRunnable(() -> { if (!session.getId().equals(session.getOriginalId())) { this.sessions.remove(session.getOriginalId()); } this.sessions.put(session.getId(), new MapSession(session)); }); }
Example 12
Source File: GuildCreateListener.java From Shadbot with GNU General Public License v3.0 | 5 votes |
@Override public Mono<Void> execute(GuildCreateEvent event) { return Mono.fromRunnable(() -> { final long guildId = event.getGuild().getId().asLong(); final int memberCount = event.getGuild().getMemberCount(); DEFAULT_LOGGER.debug("{Guild ID: {}} Connected ({} users)", guildId, memberCount); CacheManager.getInstance().getGuildOwnersCache().save(event.getGuild().getId(), event.getGuild().getOwnerId()); }); }
Example 13
Source File: ExportService.java From james-project with Apache License 2.0 | 5 votes |
private Mono<Void> export(Username username, BlobId blobId) { return Mono.fromRunnable(Throwing.runnable(() -> blobExport.blobId(blobId) .with(usersRepository.getMailAddressFor(username)) .explanation(EXPLANATION) .filePrefix(FILE_PREFIX + username.asString() + "-") .fileExtension(FileExtension.ZIP) .export()) .sneakyThrow()); }
Example 14
Source File: LuceneMessageSearchIndex.java From james-project with Apache License 2.0 | 4 votes |
@Override public Mono<Void> deleteAll(MailboxSession session, MailboxId mailboxId) { return Mono.fromRunnable(Throwing.runnable(() -> delete(mailboxId, MessageRange.all()))); }
Example 15
Source File: UserProvisioner.java From james-project with Apache License 2.0 | 4 votes |
public Mono<Void> provisionUser(MailboxSession session) { if (session != null && !usersRepository.isReadOnly()) { return Mono.fromRunnable(() -> createAccountIfNeeded(session)); } return Mono.empty(); }
Example 16
Source File: BucketGlobalRateLimiter.java From Discord4J with GNU Lesser General Public License v3.0 | 4 votes |
@Override public Mono<Void> rateLimitFor(Duration duration) { return Mono.fromRunnable(() -> limitedUntil = System.nanoTime() + duration.toNanos()); }
Example 17
Source File: LongCodec.java From r2dbc-mysql with Apache License 2.0 | 4 votes |
@Override public Mono<Void> publishText(ParameterWriter writer) { return Mono.fromRunnable(() -> writer.writeLong(value)); }
Example 18
Source File: NullParameter.java From r2dbc-mysql with Apache License 2.0 | 4 votes |
@Override public Mono<Void> publishText(ParameterWriter writer) { return Mono.fromRunnable(writer::writeNull); }
Example 19
Source File: ShardAwareStore.java From Discord4J with GNU Lesser General Public License v3.0 | 4 votes |
private Mono<Void> removeKey(Context ctx, K key) { return Mono.fromRunnable(() -> ctx.<Integer>getOrEmpty(LogUtil.KEY_SHARD_ID) .ifPresent(id -> keyStore.remove(id, key))); }
Example 20
Source File: HttpClientConnect.java From reactor-netty with Apache License 2.0 | 4 votes |
Publisher<Void> requestWithBody(HttpClientOperations ch) { try { ch.resourceUrl = toURI.toExternalForm(); UriEndpoint uri = toURI; HttpHeaders headers = ch.getNettyRequest() .setUri(uri.getPathAndQuery()) .setMethod(method) .setProtocolVersion(HttpVersion.HTTP_1_1) .headers(); ch.path = HttpOperations.resolvePath(ch.uri()); if (defaultHeaders != null) { headers.set(defaultHeaders); } if (!headers.contains(HttpHeaderNames.USER_AGENT)) { headers.set(HttpHeaderNames.USER_AGENT, USER_AGENT); } SocketAddress remoteAddress = uri.getRemoteAddress(); if (!headers.contains(HttpHeaderNames.HOST)) { headers.set(HttpHeaderNames.HOST, resolveHostHeaderValue(remoteAddress)); } if (!headers.contains(HttpHeaderNames.ACCEPT)) { headers.set(HttpHeaderNames.ACCEPT, ALL); } ch.followRedirectPredicate(followRedirectPredicate); if (!Objects.equals(method, HttpMethod.GET) && !Objects.equals(method, HttpMethod.HEAD) && !Objects.equals(method, HttpMethod.DELETE) && !headers.contains(HttpHeaderNames.CONTENT_LENGTH)) { ch.chunkedTransfer(true); } ch.listener().onStateChange(ch, HttpClientState.REQUEST_PREPARED); if (websocketClientSpec != null) { Mono<Void> result = Mono.fromRunnable(() -> ch.withWebsocketSupport(websocketClientSpec, compress)); if (handler != null) { result = result.thenEmpty(Mono.fromRunnable(() -> Flux.concat(handler.apply(ch, ch)))); } return result; } Consumer<HttpClientRequest> consumer = null; if (fromURI != null && !toURI.equals(fromURI)) { if (handler instanceof RedirectSendHandler) { headers.remove(HttpHeaderNames.EXPECT) .remove(HttpHeaderNames.COOKIE) .remove(HttpHeaderNames.AUTHORIZATION) .remove(HttpHeaderNames.PROXY_AUTHORIZATION); } else { consumer = request -> request.requestHeaders() .remove(HttpHeaderNames.EXPECT) .remove(HttpHeaderNames.COOKIE) .remove(HttpHeaderNames.AUTHORIZATION) .remove(HttpHeaderNames.PROXY_AUTHORIZATION); } } if (this.redirectRequestConsumer != null) { consumer = consumer != null ? consumer.andThen(this.redirectRequestConsumer) : this.redirectRequestConsumer; } ch.redirectRequestConsumer(consumer); return handler != null ? handler.apply(ch, ch) : ch.send(); } catch (Throwable t) { return Mono.error(t); } }