Java Code Examples for reactor.core.publisher.Mono#using()
The following examples show how to use
reactor.core.publisher.Mono#using() .
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: SerialTaskManagerWorker.java From james-project with Apache License 2.0 | 7 votes |
@Override public Mono<Task.Result> executeTask(TaskWithId taskWithId) { if (!cancelledTasks.remove(taskWithId.getId())) { Mono<Task.Result> taskMono = Mono.fromCallable(() -> runWithMdc(taskWithId, listener)).subscribeOn(taskExecutor); CompletableFuture<Task.Result> future = taskMono.toFuture(); runningTask.set(Tuples.of(taskWithId.getId(), future)); return Mono.using( () -> pollAdditionalInformation(taskWithId).subscribe(), ignored -> Mono.fromFuture(future) .onErrorResume(exception -> Mono.from(handleExecutionError(taskWithId, listener, exception)) .thenReturn(Task.Result.PARTIAL)), Disposable::dispose); } else { return Mono.from(listener.cancelled(taskWithId.getId(), taskWithId.getTask().details())) .then(Mono.empty()); } }
Example 2
Source File: MovieRepository.java From sdn-rx with Apache License 2.0 | 5 votes |
public Mono<Movie> findByTitle(String title) { return Mono.using(driver::rxSession, session -> Mono.from( session.run("MATCH (m:Movie {title: $title}) RETURN m", Values.parameters("title", title)) .records()).map(MovieRepository::mapToMovie), RxSession::close); }
Example 3
Source File: MovieRepository.java From sdn-rx with Apache License 2.0 | 5 votes |
public Mono<Movie> save(Movie movie) { return Mono.using(driver::rxSession, session -> Mono.from( session.run("CREATE (m:Movie {title: $title, tagline: $tagline}) RETURN m", Values.parameters("title", movie.getTitle(), "tagline", movie.getTagline())) .records()).map(MovieRepository::mapToMovie), RxSession::close); }
Example 4
Source File: NettyOutboundTest.java From reactor-netty with Apache License 2.0 | 5 votes |
static<S> Mono<Void> mockSendUsing(Connection c, Callable<? extends S> sourceInput, BiFunction<? super Connection, ? super S, ?> mappedInput, Consumer<? super S> sourceCleanup) { return Mono.using( sourceInput, s -> FutureMono.from(c.channel() .writeAndFlush(mappedInput.apply(c, s))), sourceCleanup ); }
Example 5
Source File: JamesMailSpooler.java From james-project with Apache License 2.0 | 5 votes |
private Mono<Void> processMail(MailQueueItem queueItem) { return Mono .using( queueItem::getMail, mail -> Mono.fromRunnable(() -> performProcessMail(queueItem, mail)), LifecycleUtil::dispose); }
Example 6
Source File: AwsS3ObjectStorage.java From james-project with Apache License 2.0 | 5 votes |
@Override public Mono<BlobId> putAndComputeId(ObjectStorageBucketName bucketName, Blob initialBlob, Supplier<BlobId> blobIdSupplier) { return Mono.using( () -> copyToTempFile(initialBlob), file -> putByFile(bucketName, blobIdSupplier, file), this::deleteFileAsync); }
Example 7
Source File: CassandraDumbBlobStore.java From james-project with Apache License 2.0 | 5 votes |
@Override public Mono<Void> save(BucketName bucketName, BlobId blobId, ByteSource content) { return Mono.using(content::openBufferedStream, stream -> save(bucketName, blobId, stream), Throwing.consumer(InputStream::close).sneakyThrow(), LAZY); }
Example 8
Source File: CassandraBlobStore.java From james-project with Apache License 2.0 | 5 votes |
@Override public Mono<BlobId> save(BucketName bucketName, InputStream data, StoragePolicy storagePolicy) { Preconditions.checkNotNull(bucketName); Preconditions.checkNotNull(data); HashingInputStream hashingInputStream = new HashingInputStream(Hashing.sha256(), data); return Mono.using( () -> new FileBackedOutputStream(FILE_THRESHOLD), fileBackedOutputStream -> saveAndGenerateBlobId(bucketName, hashingInputStream, fileBackedOutputStream), Throwing.consumer(FileBackedOutputStream::reset).sneakyThrow(), LAZY_RESOURCE_CLEANUP); }
Example 9
Source File: DefaultMultipartMessageReader.java From spring-analysis-note with MIT License | 4 votes |
@Override public Mono<Void> transferTo(Path dest) { return Mono.using(() -> AsynchronousFileChannel.open(dest, StandardOpenOption.WRITE), this::writeBody, this::close); }