本文整理汇总了Java中reactor.core.publisher.Mono.fromCallable方法的典型用法代码示例。如果您正苦于以下问题:Java Mono.fromCallable方法的具体用法?Java Mono.fromCallable怎么用?Java Mono.fromCallable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reactor.core.publisher.Mono
的用法示例。
在下文中一共展示了Mono.fromCallable方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAveAge
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@Override
public Mono<Double> getAveAge() {
ToIntFunction<Employee> sizeEmpArr = (e) -> {
System.out.println("flux:toIntFunction task executor: " + Thread.currentThread().getName());
System.out.println("flux:toIntFunction task executor login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal());
return e.getAge();
};
Callable<Double> task = () ->{
System.out.println("flux:callable task executor: " + Thread.currentThread().getName());
System.out.println("flux:callable task executor login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal());
return employeeDaoImpl.getEmployees().stream()
.mapToInt(sizeEmpArr)
.average()
.getAsDouble();
};
Mono<Double> aveAge= Mono.fromCallable(task);
return aveAge;
}
示例2: getOrCreate
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@GetMapping("expensive/{item}")
public Mono<Object> getOrCreate(@PathVariable String item) {
Mono<Object> expensiveToCalculate = Mono.fromCallable(() -> {
Thread.sleep(2000);
return 42L;
});
return redis.hasKey(item).flatMap(exists -> {
if (exists) {
return redis.opsForValue().get(item);
}
return expensiveToCalculate.flatMap(it -> redis.opsForValue().set(item, it).map(ignored -> (Object) it));
});
}
示例3: readEmployee
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@Override
public Publisher<Employee> readEmployee(Integer empId) {
Callable<Employee> task = () -> employeeDaoImpl.getEmployee(empId);
Publisher<Employee> publishedEmployee = Mono.fromCallable(task);
return publishedEmployee;
}
示例4: requestReply
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@Override
public Mono<SimpleResponse> requestReply(SimpleRequest message, ByteBuf metadata) {
return Mono.fromCallable(
() ->
SimpleResponse.newBuilder()
.setResponseMessageBytes(message.getRequestMessageBytes())
.build());
}
示例5: sayHello
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@Override
public Mono<HelloResponse> sayHello(HelloRequest message, ByteBuf metadata) {
logger.info("received a message -> {}", message.getName());
return Mono.fromCallable(() -> HelloResponse.newBuilder()
.setMessage("Hello, " + message.getName() + "! from " + serviceName)
.build());
}
示例6: readProcessOutput
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
private Mono<ProcessResult> readProcessOutput(Process process) {
return Mono.fromCallable(() -> {
try {
ExecutorService executor = Executors.newFixedThreadPool(2);
int status = process.waitFor();
try (InputStream stdoutStream = process.getInputStream();
InputStream stderrStream = process.getErrorStream()) {
Future<List<String>> stdout = executor.submit(new StreamBoozer(stdoutStream));
Future<List<String>> stderr = executor.submit(new StreamBoozer(stderrStream));
ProcessResultImpl processResult = ProcessResultImpl.builder()
.status(status)
.output(stdout.get())
.errors(stderr.get())
.build();
executor.shutdown();
if (log.isDebugEnabled()) {
log.debug("Command has terminated with status: " + processResult.getStatus());
log.debug("Output:\n" + processResult.getStdoutLines());
log.debug("Error:\n" + processResult.getStderrLines());
}
return processResult;
}
} catch (InterruptedException | ExecutionException | IOException e) {
throw new RuntimeException(e);
}
});
}
示例7: forbidden
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<ResponseEntity<Map<String, Boolean>>> forbidden() {
return Mono.fromCallable(() -> ResponseEntity.notFound().build());
}
示例8: emptyResponse
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<ResponseEntity<String>> emptyResponse(ClientResponse res) {
return Mono.fromCallable(() -> ResponseEntity.status(res.statusCode()).build());
}
示例9: findById
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
public Mono<Category> findById(String id) {
return Mono.fromCallable(() -> {
Thread.sleep(10);
return categories.get(id);
});
}
示例10: monoShouldDeferCallable
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@Test
public void monoShouldDeferCallable() {
String marie = "Marie";
Callable<String> myValue = () -> marie;
Mono<String> mono = Mono.fromCallable(myValue);
verify(mono, marie);
}