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

The following examples show how to use reactor.core.publisher.Mono#fromSupplier() . 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
/**
 * 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
@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
@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 Project: java-sdk   File: DemoServiceController.java    License: 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 Project: java-sdk   File: ActorNoStateTest.java    License: MIT License 5 votes vote down vote up
@Override
public Mono<String> stringInStringOut(String s) {
  return Mono.fromSupplier(() -> {
      return s + s;
    }
  );
}
 
Example 6
Source Project: r2dbc-mysql   File: DoubleCodec.java    License: 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 Project: java-sdk   File: DerivedActorTest.java    License: 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 8
Source Project: r2dbc-mysql   File: LoginFlow.java    License: 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 9
Source Project: r2dbc-mysql   File: FloatCodec.java    License: 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 10
@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 Project: java-sdk   File: ActorCustomSerializerTest.java    License: MIT License 4 votes vote down vote up
@Override
public Mono<Integer> intInIntOut(int input) {
  return Mono.fromSupplier(() -> input + input);
}
 
Example 12
@Override
public Publisher<Object> onBeforeBind(Object entity) {

	return Mono.fromSupplier(() -> idPopulator.populateIfNecessary(entity));
}
 
Example 13
public Mono<Resource> findOneImage(String filename) {
	return Mono.fromSupplier(() ->
		resourceLoader.getResource(
			"file:" + UPLOAD_ROOT + "/" + filename));
}
 
Example 14
public Mono<Resource> findOneImage(String filename) {
	return Mono.fromSupplier(() ->
		resourceLoader.getResource(
			"file:" + UPLOAD_ROOT + "/" + filename));
}
 
Example 15
Source Project: r2dbc-mysql   File: InstantCodec.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Mono<ByteBuf> publishBinary() {
    return Mono.fromSupplier(() -> LocalDateTimeCodec.encodeBinary(allocator, serverValue()));
}
 
Example 16
@Nonnull
@Override
public Mono<DefaultEmailNotifier> createNotifier(@Nonnull NotifierProperties properties) {
    return Mono.fromSupplier(() -> new DefaultEmailNotifier(properties, templateManager));
}
 
Example 17
Source Project: r2dbc-mysql   File: LocalTimeCodec.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Mono<ByteBuf> publishBinary() {
    return Mono.fromSupplier(() -> encodeBinary(allocator, value));
}
 
Example 18
Source Project: r2dbc-mysql   File: LocalTimeCodec.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Mono<ByteBuf> publishBinary() {
    return Mono.fromSupplier(() -> encodeBinary(allocator, value));
}
 
Example 19
@GetMapping
public Mono<String> hello() {
  return Mono.fromSupplier(() -> "Hello SpringFox!");
}
 
Example 20
Source Project: java-sdk   File: ActorStatefulTest.java    License: MIT License 4 votes vote down vote up
@Override
public Mono<Boolean> isActive() {
  return Mono.fromSupplier(() -> this.activated);
}