Java Code Examples for reactor.core.publisher.Mono#fromRunnable()

The following examples show how to use reactor.core.publisher.Mono#fromRunnable() . These examples are extracted from open source projects. 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
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 Project: java-sdk   File: ActorNoStateTest.java    License: MIT License 5 votes vote down vote up
@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 3
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
@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
@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
@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 Project: requery   File: ReactorEntityStore.java    License: Apache License 2.0 5 votes vote down vote up
@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
@Override
public Mono<Void> shutdown() {
    return Mono.fromRunnable(() -> {
        started.set(false);

        disposable.forEach(Disposable::dispose);

        disposable.clear();
    });
}
 
Example 9
@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 10
Source Project: james-project   File: ExportService.java    License: Apache License 2.0 5 votes vote down vote up
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 11
@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 Project: cloud-spanner-r2dbc   File: GrpcClient.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Mono<Void> close() {
  return Mono.fromRunnable(() -> {
    if (this.channel != null) {
      this.channel.shutdownNow();
    }
  });
}
 
Example 13
Source Project: java-sdk   File: ActorRuntimeTest.java    License: MIT License 5 votes vote down vote up
public Mono<Void> onActivate() {
  return Mono.fromRunnable(() -> {
    if (this.activated != null) {
      throw new IllegalStateException("already activated once");
    }

    this.activated = true;
  });
}
 
Example 14
Source Project: reactor-netty   File: HttpClientConnect.java    License: Apache License 2.0 4 votes vote down vote up
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);
	}
}
 
Example 15
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 16
@Override
public Mono<Void> deleteAll(MailboxSession session, MailboxId mailboxId) {
    return Mono.fromRunnable(Throwing.runnable(() -> delete(mailboxId, MessageRange.all())));
}
 
Example 17
Source Project: r2dbc-mysql   File: NullParameter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Mono<Void> publishText(ParameterWriter writer) {
    return Mono.fromRunnable(writer::writeNull);
}
 
Example 18
Source Project: r2dbc-mysql   File: LongCodec.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Mono<Void> publishText(ParameterWriter writer) {
    return Mono.fromRunnable(() -> writer.writeLong(value));
}
 
Example 19
@Override
public Mono<Void> rateLimitFor(Duration duration) {
    return Mono.fromRunnable(() -> limitedUntil = System.nanoTime() + duration.toNanos());
}
 
Example 20
Source Project: james-project   File: UserProvisioner.java    License: Apache License 2.0 4 votes vote down vote up
public Mono<Void> provisionUser(MailboxSession session) {
    if (session != null && !usersRepository.isReadOnly()) {
        return Mono.fromRunnable(() -> createAccountIfNeeded(session));
    }
    return Mono.empty();
}