本文整理汇总了Java中reactor.core.scheduler.Schedulers.newSingle方法的典型用法代码示例。如果您正苦于以下问题:Java Schedulers.newSingle方法的具体用法?Java Schedulers.newSingle怎么用?Java Schedulers.newSingle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reactor.core.scheduler.Schedulers
的用法示例。
在下文中一共展示了Schedulers.newSingle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readEmployeesByDescAge
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Override
public Flux<Employee> readEmployeesByDescAge() {
Scheduler subWorker = Schedulers.newSingle("sub-thread");
Scheduler pubWorker = Schedulers.newSingle("pub-thread");
Supplier<Flux<Employee>> deferredTask = ()->{
System.out.println("flux:defer task executor: "+ Thread.currentThread().getName());
System.out.println("flux:defer task executor login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal());
return Flux.fromIterable(employeeDaoImpl.getEmployees());
};
Comparator<Employee> descAge = (e1, e2) -> {
System.out.println("flux:sort task executor: " + Thread.currentThread().getName());
System.out.println("flux:sort task executor login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal());
if(e1.getAge().compareTo(e2.getAge()) == 0){
return 0;
} else if(e1.getAge().compareTo(e2.getAge()) > 0){
return -1;
} else return 1;
};
Flux<Employee> deferred = Flux.defer(deferredTask).sort(descAge).subscribeOn(subWorker).publishOn(pubWorker);
return deferred;
}
示例2: readEmployeesFlux
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Override
public Flux<Employee> readEmployeesFlux(int age) {
Scheduler subWorker = Schedulers.newSingle("sub-thread");
Scheduler pubWorker = Schedulers.newSingle("pub-thread");
Predicate<Employee> validAge = (e) -> {
System.out.println("flux:filter task executor: " + Thread.currentThread().getName());
System.out.println("flux:filter task executor login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal());
return e.getAge() > age;
};
Supplier<Flux<Employee>> deferredTask = ()->{
System.out.println("flux:defer task executor: " + Thread.currentThread().getName());
System.out.println("flux:defer task executor login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal());
return Flux.fromIterable(employeeDaoImpl.getEmployees());
};
Flux<Employee> deferred = Flux.defer(deferredTask).filter(validAge).subscribeOn(subWorker).publishOn(pubWorker);
return deferred;
}
示例3: readEmployeesByAscLastName
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Override
public Flux<Employee> readEmployeesByAscLastName() {
Scheduler subWorker = Schedulers.newSingle("sub-thread");
Scheduler pubWorker = Schedulers.newSingle("pub-thread");
Supplier<Flux<Employee>> deferredTask = ()->{
System.out.println("flux:defer task executor: " + Thread.currentThread().getName());
System.out.println("flux:defer task executor login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal());
return Flux.fromIterable(employeeDaoImpl.getEmployees());
};
Comparator<Employee> descLName = (e1, e2) -> {
System.out.println("flux:sort task executor: " + Thread.currentThread().getName());
System.out.println("flux:sort task executor login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal());
return e1.getLastName().compareTo(e2.getLastName());
};
Flux<Employee> deferred = Flux.defer(deferredTask).sort(descLName).subscribeOn(subWorker).publishOn(pubWorker);
return deferred;
}
示例4: onNextOnDisposedSchedulerThrows
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test
public void onNextOnDisposedSchedulerThrows() {
Scheduler scheduler = Schedulers.newSingle("onNextOnDisposedSchedulerThrows");
scheduler.dispose();
Mono<String> source = Mono.just("foo").hide();
try {
StepVerifier.create(new MonoDelayElement<>(source, 2, TimeUnit.SECONDS, scheduler))
.expectSubscription()
.verifyComplete(); //complete not relevant
fail("expected exception here");
}
catch (Throwable e) {
Throwable t = Exceptions.unwrap(e);
assertThat(t).isEqualTo(e)
.isInstanceOf(RejectedExecutionException.class)
.hasMessage("Scheduler unavailable");
assertThat(e).satisfies(Exceptions::isBubbling);
}
}
示例5: createSubscriberThread
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Override
public Flux<Employee> createSubscriberThread() {
Scheduler subWorker = Schedulers.newSingle("sub-thread");
Predicate<Employee> validAge = (e) -> {
System.out.println("filter thread " +Thread.currentThread().getName());
return e.getAge() > 25;
};
Supplier<Flux<Employee>> deferredTask = ()->{
System.out.println("defer thread "+Thread.currentThread().getName());
return Flux.fromIterable(employeeDaoImpl.getEmployees());
};
Flux<Employee> deferred = Flux.defer(deferredTask).filter(validAge).subscribeOn(subWorker);
return deferred;
}
示例6: createPublisherThread
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Override
public Flux<Employee> createPublisherThread() {
Scheduler pubWorker = Schedulers.newSingle("pub-thread");
Predicate<Employee> validAge = (e) -> {
System.out.println("filter thread " +Thread.currentThread().getName());
return e.getAge() > 25;
};
Supplier<Flux<Employee>> deferredTask = ()->{
System.out.println("defer thread "+Thread.currentThread().getName());
return Flux.fromIterable(employeeDaoImpl.getEmployees());
};
Flux<Employee> deferred = Flux.defer(deferredTask).filter(validAge).publishOn(pubWorker);
return deferred;
}
示例7: testThreadAffinity
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test
public void testThreadAffinity() throws InterruptedException {
int count = 10;
Scheduler[] schedulers = new Scheduler[4];
CountDownLatch[] latches = new CountDownLatch[schedulers.length];
for (int i = 0; i < schedulers.length; i++) {
schedulers[i] = Schedulers.newSingle("scheduler" + i + '-');
int expectedCount = i == 1 ? count * 2 : count;
latches[i] = new CountDownLatch(expectedCount);
}
EmitterProcessor<Integer> processor = EmitterProcessor.create();
processor.publishOn(schedulers[0])
.share();
processor.publishOn(schedulers[1])
.subscribe(i -> {
assertThat(Thread.currentThread().getName().contains("scheduler1")).isTrue();
latches[1].countDown();
});
for (int i = 0; i < count; i++)
processor.onNext(i);
processor.publishOn(schedulers[2])
.map(i -> {
assertThat(Thread.currentThread().getName().contains("scheduler2")).isTrue();
latches[2].countDown();
return i;
})
.publishOn(schedulers[3])
.doOnNext(i -> {
assertThat(Thread.currentThread().getName().contains("scheduler3")).isTrue();
latches[3].countDown();
})
.subscribe();
for (int i = 0; i < count; i++)
processor.onNext(i);
processor.onComplete();
for (int i = 1; i < latches.length; i++)
assertThat(latches[i].await(5, TimeUnit.SECONDS)).isTrue();
assertThat(latches[0].getCount()).isEqualTo(count);
}
示例8: gh507
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test
public void gh507() {
Scheduler s = Schedulers.newSingle("subscribe");
Scheduler s2 = Schedulers.newParallel("receive");
Flux.from((Publisher<String>) subscriber -> {
subscriber.onSubscribe(new Subscription() {
private int totalCount;
@Override
public void request(long n) {
for (int i = 0; i < n; i++) {
if (totalCount++ < 317) {
subscriber.onNext(String.valueOf(totalCount));
}
else {
subscriber.onComplete();
}
}
}
@Override
public void cancel() {
// do nothing
}
});
})
.subscribeOn(s)
.limitRate(10)
.doOnNext(d -> {
Mono.fromCallable(() -> d)
.subscribeOn(s2)
.block();
})
.blockLast();
s.dispose();
}
示例9: loginDetailsById
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
public Mono<ServerResponse> loginDetailsById(ServerRequest req) {
Scheduler subWorker = Schedulers.newSingle("sub-thread");
Mono<LoginDetails> login = Mono.defer(() -> Mono.justOrEmpty(logindetailsServiceImpl.findLoginById(Integer.parseInt(req.pathVariable("id"))))).subscribeOn(subWorker);
return ok().contentType(MediaType.APPLICATION_STREAM_JSON).body(login, LoginDetails.class)
.switchIfEmpty(ServerResponse.notFound().build());
}
示例10: saveDepartmentMono
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
public Mono<ServerResponse> saveDepartmentMono(ServerRequest req) {
Scheduler subWorker = Schedulers.newSingle("sub-thread");
Mono<Department> department = req.bodyToMono(Department.class).doOnNext(departmentServiceImpl::saveDeptRec).subscribeOn(subWorker);
return ok().contentType(MediaType.APPLICATION_STREAM_JSON).build(department.then());
}
示例11: chooseEmpById
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
public Mono<ServerResponse> chooseEmpById(ServerRequest req) {
Scheduler subWorker = Schedulers.newSingle("sub-thread");
Mono<Employee> emp = Mono.defer(() -> Mono.justOrEmpty(employeeServiceImpl.findEmployeeByid(Integer.parseInt(req.pathVariable("id"))))).subscribeOn(subWorker);
return ok().contentType(MediaType.APPLICATION_STREAM_JSON).body(emp, Employee.class)
.switchIfEmpty(ServerResponse.notFound().build());
}
示例12: saveEmployeeMono
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
public Mono<ServerResponse> saveEmployeeMono(ServerRequest req) {
Scheduler subWorker = Schedulers.newSingle("sub-thread");
Mono<Employee> employee = req.bodyToMono(Employee.class).doOnNext(employeeServiceImpl::saveEmployeeRec).subscribeOn(subWorker);
return ok().contentType(MediaType.APPLICATION_STREAM_JSON).build(employee.then());
}
示例13: saveLogindetailsMono
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
public Mono<ServerResponse> saveLogindetailsMono(ServerRequest req) {
Scheduler subWorker = Schedulers.newSingle("sub-thread");
Mono<LoginDetails> loginDetails = req.bodyToMono(LoginDetails.class).doOnNext(logindetailsServiceImpl::saveLogindetails).subscribeOn(subWorker);
return ok().contentType(MediaType.APPLICATION_STREAM_JSON).build(loginDetails.then());
}
示例14: userDetailsById
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
public Mono<ServerResponse> userDetailsById(ServerRequest req) {
Scheduler subWorker = Schedulers.newSingle("sub-thread");
Mono<UserDetails> user = Mono.defer(() -> Mono.justOrEmpty(userdetailsServiceImpl.findUserById(Integer.parseInt(req.pathVariable("id"))))).subscribeOn(subWorker);
return ok().contentType(MediaType.APPLICATION_STREAM_JSON).body(user, UserDetails.class)
.switchIfEmpty(ServerResponse.notFound().build());
}
示例15: saveUserdetailsMono
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
public Mono<ServerResponse> saveUserdetailsMono(ServerRequest req) {
Scheduler subWorker = Schedulers.newSingle("sub-thread");
Mono<UserDetails> loginDetails = req.bodyToMono(UserDetails.class).doOnNext(userdetailsServiceImpl::saveUserdetails).subscribeOn(subWorker);
return ok().contentType(MediaType.APPLICATION_STREAM_JSON).build(loginDetails.then());
}