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

The following examples show how to use reactor.core.publisher.Mono#fromSupplier() . 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: AbstractNamedValueArgumentResolver.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Resolve the default value, if any.
 */
private Mono<Object> getDefaultValue(NamedValueInfo namedValueInfo, MethodParameter parameter,
		BindingContext bindingContext, Model model, ServerWebExchange exchange) {

	return Mono.fromSupplier(() -> {
		Object value = null;
		if (namedValueInfo.defaultValue != null) {
			value = resolveStringValue(namedValueInfo.defaultValue);
		}
		else if (namedValueInfo.required && !parameter.isOptional()) {
			handleMissingValue(namedValueInfo.name, parameter, exchange);
		}
		value = handleNullValue(namedValueInfo.name, value, parameter.getNestedParameterType());
		value = applyConversion(value, namedValueInfo, parameter, bindingContext, exchange);
		handleResolvedValue(value, namedValueInfo.name, parameter, model, exchange);
		return value;
	});
}
 
Example 2
Source File: FixedSizeClientMessage.java    From r2dbc-mysql with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<ByteBuf> encode(ByteBufAllocator allocator, ConnectionContext context) {
    requireNonNull(allocator, "allocator must not be null");
    requireNonNull(context, "context must not be null");

    return Mono.fromSupplier(() -> {
        int s = size();
        ByteBuf buf = allocator.buffer(s, s);

        try {
            writeTo(buf);
            return buf;
        } catch (Throwable e) {
            buf.release();
            throw e;
        }
    });
}
 
Example 3
Source File: EnvelopeClientMessage.java    From r2dbc-mysql with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<ByteBuf> encode(ByteBufAllocator allocator, ConnectionContext context) {
    requireNonNull(allocator, "allocator must not be null");
    requireNonNull(context, "context must not be null");

    return Mono.fromSupplier(() -> {
        ByteBuf buf = allocator.buffer(INITIAL_CAPACITY, Envelopes.MAX_ENVELOPE_SIZE);

        try {
            writeTo(buf, context);
            return buf;
        } catch (Throwable e) {
            buf.release();
            throw e;
        }
    });
}
 
Example 4
Source File: DemoServiceController.java    From java-sdk with MIT License 6 votes vote down vote up
/**
 * Handles a dapr service invocation endpoint on this app.
 * @param body The body of the http message.
 * @param headers The headers of the http message.
 * @return A message containing the time.
 */
@PostMapping(path = "/say")
public Mono<String> handleMethod(@RequestBody(required = false) byte[] body,
                                 @RequestHeader Map<String, String> headers) {
  return Mono.fromSupplier(() -> {
    try {
      String message = body == null ? "" : new String(body, StandardCharsets.UTF_8);

      Calendar utcNow = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
      String utcNowAsString = DATE_FORMAT.format(utcNow.getTime());

      String metadataString = headers == null ? "" : OBJECT_MAPPER.writeValueAsString(headers);

      // Handles the request by printing message.
      System.out.println(
          "Server: " + message + " @ " + utcNowAsString + " and metadata: " + metadataString);

      return utcNowAsString;
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  });
}
 
Example 5
Source File: ActorNoStateTest.java    From java-sdk with MIT License 5 votes vote down vote up
@Override
public Mono<String> stringInStringOut(String s) {
  return Mono.fromSupplier(() -> {
      return s + s;
    }
  );
}
 
Example 6
Source File: DoubleCodec.java    From r2dbc-mysql with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<ByteBuf> publishBinary() {
    return Mono.fromSupplier(() -> {
        ByteBuf buf = allocator.buffer(Double.BYTES);
        try {
            return buf.writeDoubleLE(value);
        } catch (Throwable e) {
            buf.release();
            throw e;
        }
    });
}
 
Example 7
Source File: ImageService.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
public Mono<Resource> findOneImage(String filename) {
	return Mono.fromSupplier(() ->
		resourceLoader.getResource(
			"file:" + UPLOAD_ROOT + "/" + filename));
}
 
Example 8
Source File: DerivedActorTest.java    From java-sdk with MIT License 5 votes vote down vote up
@Override
public Mono<Boolean> stringInBooleanOut(String s) {
  return Mono.fromSupplier(() -> {
    if (s.equals("true")) {
      return true;
    } else {
      return false;
    }
  });
}
 
Example 9
Source File: ImageService.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
public Mono<Resource> findOneImage(String filename) {
	return Mono.fromSupplier(() ->
		resourceLoader.getResource(
			"file:" + UPLOAD_ROOT + "/" + filename));
}
 
Example 10
Source File: ReactiveRedissonTransactionManager.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
protected Mono<Object> doSuspend(TransactionSynchronizationManager synchronizationManager, Object transaction) throws TransactionException {
    return Mono.fromSupplier(() -> {
        ReactiveRedissonTransactionObject to = (ReactiveRedissonTransactionObject) transaction;
        to.setResourceHolder(null);
        return synchronizationManager.unbindResource(redissonClient);
    });
}
 
Example 11
Source File: LoginFlow.java    From r2dbc-mysql with Apache License 2.0 5 votes vote down vote up
private Mono<HandshakeResponse> createHandshakeResponse() {
    return Mono.fromSupplier(() -> {
        MySqlAuthProvider authProvider = getAndNextProvider();

        if (authProvider.isSslNecessary() && !sslCompleted) {
            throw new R2dbcPermissionDeniedException(formatAuthFails(authProvider.getType(), "handshake"), CLI_SPECIFIC_CONDITION);
        }

        String user = this.user;
        if (user == null) {
            throw new IllegalStateException("user must not be null when login");
        }

        byte[] authorization = authProvider.authentication(password, salt, context.getClientCollation());
        String authType = authProvider.getType();

        if (MySqlAuthProvider.NO_AUTH_PROVIDER.equals(authType)) {
            // Authentication type is not matter because of it has no authentication type.
            // Server need send a Change Authentication Message after handshake response.
            authType = MySqlAuthProvider.CACHING_SHA2_PASSWORD;
        }

        return HandshakeResponse.from(
            context.getCapabilities(),
            context.getClientCollation().getId(),
            user,
            authorization,
            authType,
            database,
            ATTRIBUTES
        );
    });
}
 
Example 12
Source File: FloatCodec.java    From r2dbc-mysql with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<ByteBuf> publishBinary() {
    return Mono.fromSupplier(() -> {
        ByteBuf buf = allocator.buffer(Float.BYTES);
        try {
            return buf.writeFloatLE(value);
        } catch (Throwable e) {
            buf.release();
            throw e;
        }
    });
}
 
Example 13
Source File: ActorStatefulTest.java    From java-sdk with MIT License 4 votes vote down vote up
@Override
public Mono<Boolean> isActive() {
  return Mono.fromSupplier(() -> this.activated);
}
 
Example 14
Source File: BootWebfluxApplication.java    From springfox-demos with Apache License 2.0 4 votes vote down vote up
@GetMapping
public Mono<String> hello() {
  return Mono.fromSupplier(() -> "Hello SpringFox!");
}
 
Example 15
Source File: LocalTimeCodec.java    From r2dbc-mysql with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<ByteBuf> publishBinary() {
    return Mono.fromSupplier(() -> encodeBinary(allocator, value));
}
 
Example 16
Source File: LocalTimeCodec.java    From r2dbc-mysql with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<ByteBuf> publishBinary() {
    return Mono.fromSupplier(() -> encodeBinary(allocator, value));
}
 
Example 17
Source File: DefaultEmailNotifierProvider.java    From jetlinks-community with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Mono<DefaultEmailNotifier> createNotifier(@Nonnull NotifierProperties properties) {
    return Mono.fromSupplier(() -> new DefaultEmailNotifier(properties, templateManager));
}
 
Example 18
Source File: InstantCodec.java    From r2dbc-mysql with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<ByteBuf> publishBinary() {
    return Mono.fromSupplier(() -> LocalDateTimeCodec.encodeBinary(allocator, serverValue()));
}
 
Example 19
Source File: ReactiveIdGeneratingBeforeBindCallback.java    From sdn-rx with Apache License 2.0 4 votes vote down vote up
@Override
public Publisher<Object> onBeforeBind(Object entity) {

	return Mono.fromSupplier(() -> idPopulator.populateIfNecessary(entity));
}
 
Example 20
Source File: ActorCustomSerializerTest.java    From java-sdk with MIT License 4 votes vote down vote up
@Override
public Mono<Integer> intInIntOut(int input) {
  return Mono.fromSupplier(() -> input + input);
}