当前位置: 首页>>代码示例>>Java>>正文


Java Mono.fromCallable方法代码示例

本文整理汇总了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;
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:20,代码来源:EmployeeServiceImpl.java

示例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));
	});
}
 
开发者ID:mp911de,项目名称:reactive-spring,代码行数:18,代码来源:CachingController.java

示例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;
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:8,代码来源:EmployeeStreamServiceImpl.java

示例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());
}
 
开发者ID:netifi,项目名称:proteus-java,代码行数:9,代码来源:SimpleServiceTest.java

示例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());
}
 
开发者ID:netifi,项目名称:proteus-quickstart,代码行数:8,代码来源:DefaultHelloService.java

示例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);
        }
    });
}
 
开发者ID:amvnetworks,项目名称:amv-highmobility-cryptotool-wrapper,代码行数:33,代码来源:BinaryExecutorImpl.java

示例7: forbidden

import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<ResponseEntity<Map<String, Boolean>>> forbidden() {
	return Mono.fromCallable(() -> ResponseEntity.notFound().build());
}
 
开发者ID:making,项目名称:spring-boot-actuator-dashboard,代码行数:4,代码来源:PseudoCloudController.java

示例8: emptyResponse

import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<ResponseEntity<String>> emptyResponse(ClientResponse res) {
	return Mono.fromCallable(() -> ResponseEntity.status(res.statusCode()).build());
}
 
开发者ID:making,项目名称:spring-boot-actuator-dashboard,代码行数:4,代码来源:ProxyController.java

示例9: findById

import reactor.core.publisher.Mono; //导入方法依赖的package包/类
public Mono<Category> findById(String id) {
    return Mono.fromCallable(() -> {
        Thread.sleep(10);
        return categories.get(id);
    });
}
 
开发者ID:adaikiss,项目名称:mustache-showcase,代码行数:7,代码来源:CategoryRepository.java

示例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);
}
 
开发者ID:mp911de,项目名称:reactive-spring,代码行数:12,代码来源:Step1Mono.java


注:本文中的reactor.core.publisher.Mono.fromCallable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。