Java Code Examples for reactor.core.publisher.MonoProcessor#peek()

The following examples show how to use reactor.core.publisher.MonoProcessor#peek() . 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: SyncInvocableHandlerMethod.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Invoke the method for the given exchange.
 * @param exchange the current exchange
 * @param bindingContext the binding context to use
 * @param providedArgs optional list of argument values to match by type
 * @return a Mono with a {@link HandlerResult}.
 * @throws ServerErrorException if method argument resolution or method invocation fails
 */
@Nullable
public HandlerResult invokeForHandlerResult(ServerWebExchange exchange,
		BindingContext bindingContext, Object... providedArgs) {

	MonoProcessor<HandlerResult> processor = MonoProcessor.create();
	this.delegate.invoke(exchange, bindingContext, providedArgs).subscribeWith(processor);

	if (processor.isTerminated()) {
		Throwable ex = processor.getError();
		if (ex != null) {
			throw (ex instanceof ServerErrorException ? (ServerErrorException) ex :
					new ServerErrorException("Failed to invoke: " + getShortLogMessage(), getMethod(), ex));
		}
		return processor.peek();
	}
	else {
		// Should never happen...
		throw new IllegalStateException(
				"SyncInvocableHandlerMethod should have completed synchronously.");
	}
}
 
Example 2
Source File: Decoder.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Decode a data buffer to an Object of type T. This is useful when the input
 * stream consists of discrete messages (or events) and the content for each
 * can be decoded on its own.
 * @param buffer the {@code DataBuffer} to decode
 * @param targetType the expected output type
 * @param mimeType the MIME type associated with the data
 * @param hints additional information about how to do encode
 * @return the decoded value, possibly {@code null}
 * @since 5.2
 */
@SuppressWarnings("ConstantConditions")
default T decode(DataBuffer buffer, ResolvableType targetType,
		@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) throws DecodingException {

	MonoProcessor<T> processor = MonoProcessor.create();
	decodeToMono(Mono.just(buffer), targetType, mimeType, hints).subscribeWith(processor);

	Assert.state(processor.isTerminated(), "DataBuffer decoding should have completed.");
	Throwable ex = processor.getError();
	if (ex != null) {
		throw (ex instanceof CodecException ? (CodecException) ex :
				new DecodingException("Failed to decode: " + ex.getMessage(), ex));
	}
	return processor.peek();
}
 
Example 3
Source File: SyncInvocableHandlerMethod.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Invoke the method for the given exchange.
 * @param exchange the current exchange
 * @param bindingContext the binding context to use
 * @param providedArgs optional list of argument values to match by type
 * @return a Mono with a {@link HandlerResult}.
 * @throws ServerErrorException if method argument resolution or method invocation fails
 */
@Nullable
public HandlerResult invokeForHandlerResult(ServerWebExchange exchange,
		BindingContext bindingContext, Object... providedArgs) {

	MonoProcessor<HandlerResult> processor = MonoProcessor.create();
	this.delegate.invoke(exchange, bindingContext, providedArgs).subscribeWith(processor);

	if (processor.isTerminated()) {
		Throwable ex = processor.getError();
		if (ex != null) {
			throw (ex instanceof ServerErrorException ? (ServerErrorException) ex :
					new ServerErrorException("Failed to invoke: " + getShortLogMessage(), getMethod(), ex));
		}
		return processor.peek();
	}
	else {
		// Should never happen...
		throw new IllegalStateException(
				"SyncInvocableHandlerMethod should have completed synchronously.");
	}
}