Java Code Examples for reactor.core.scheduler.Schedulers#elastic()

The following examples show how to use reactor.core.scheduler.Schedulers#elastic() . 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: ReactiveInvocationHandlerTest.java    From feign with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void invokeOnSubscribeReactor() throws Throwable {
  given(this.methodHandler.invoke(any())).willReturn("Result");
  ReactorInvocationHandler handler = new ReactorInvocationHandler(this.target,
      Collections.singletonMap(method, this.methodHandler), Schedulers.elastic());

  Object result = handler.invoke(method, this.methodHandler, new Object[] {});
  assertThat(result).isInstanceOf(Mono.class);
  verifyZeroInteractions(this.methodHandler);

  /* subscribe and execute the method */
  StepVerifier.create((Mono) result)
      .expectNext("Result")
      .expectComplete()
      .verify();
  verify(this.methodHandler, times(1)).invoke(any());
}
 
Example 2
Source File: ReactiveInvocationHandlerTest.java    From feign with Apache License 2.0 6 votes vote down vote up
@Test
public void invokeOnSubscribeEmptyReactor() throws Throwable {
  given(this.methodHandler.invoke(any())).willReturn(null);
  ReactorInvocationHandler handler = new ReactorInvocationHandler(this.target,
      Collections.singletonMap(method, this.methodHandler), Schedulers.elastic());

  Object result = handler.invoke(method, this.methodHandler, new Object[] {});
  assertThat(result).isInstanceOf(Mono.class);
  verifyZeroInteractions(this.methodHandler);

  /* subscribe and execute the method */
  StepVerifier.create((Mono) result)
      .expectComplete()
      .verify();
  verify(this.methodHandler, times(1)).invoke(any());
}
 
Example 3
Source File: ReactiveInvocationHandlerTest.java    From feign with Apache License 2.0 6 votes vote down vote up
@Test
public void invokeFailureReactor() throws Throwable {
  given(this.methodHandler.invoke(any())).willThrow(new IOException("Could Not Decode"));
  ReactorInvocationHandler handler = new ReactorInvocationHandler(this.target,
      Collections.singletonMap(this.method, this.methodHandler), Schedulers.elastic());

  Object result = handler.invoke(this.method, this.methodHandler, new Object[] {});
  assertThat(result).isInstanceOf(Mono.class);
  verifyZeroInteractions(this.methodHandler);

  /* subscribe and execute the method, should result in an error */
  StepVerifier.create((Mono) result)
      .expectError(IOException.class)
      .verify();
  verify(this.methodHandler, times(1)).invoke(any());
}
 
Example 4
Source File: SoulWebHandler.java    From soul with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a new Soul web handler.
 *
 * @param plugins the plugins
 */
public SoulWebHandler(final List<SoulPlugin> plugins) {
    this.plugins = plugins;
    String schedulerType = System.getProperty("soul.scheduler.type", "fixed");
    if (Objects.equals(schedulerType, "fixed")) {
        int threads = Integer.parseInt(System.getProperty(
                "soul.work.threads", "" + Math.max((Runtime.getRuntime().availableProcessors() << 1) + 1, 16)));
        scheduler = Schedulers.newParallel("soul-work-threads", threads);
    } else {
        scheduler = Schedulers.elastic();
    }
}
 
Example 5
Source File: ReactiveRepositoryAdapterFactory.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
@Override
public ResourceRepositoryAdapter decorate(ResourceRepositoryAdapter adapter) {
	Object implementation = adapter.getImplementation();
	if (implementation instanceof ReactiveResourceRepository) {
		return adapter;
	}

	boolean immediate = implementation.getClass().getAnnotation(ImmediateRepository.class) != null;
	LOGGER.debug("wrapping non-reactive repository {}, immediate={}", implementation, immediate);
	Scheduler scheduler = immediate ? Schedulers.immediate() : Schedulers.elastic();
	return new WorkerResourceRepositoryAdapter(adapter, scheduler, moduleRegistry.getHttpRequestContextProvider());
}
 
Example 6
Source File: ResettableIntervalTest.java    From Discord4J with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void test() {
    ResettableInterval interval = new ResettableInterval(Schedulers.elastic());
    StepVerifier.withVirtualTime(() -> interval.ticks()
            .doOnSubscribe(s -> interval.start(Duration.ZERO, Duration.ofSeconds(1))))
            .expectSubscription()
            .expectNoEvent(Duration.ofSeconds(1))
            .expectNext(0L)
            .then(interval::stop)
            .then(() -> interval.start(Duration.ZERO, Duration.ofSeconds(2)))
            .expectNoEvent(Duration.ofSeconds(2))
            .expectNext(1L)
            .thenCancel()
            .verify();
}
 
Example 7
Source File: ReactiveDbApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Bean
public Scheduler scheduler() {
	return Schedulers.elastic();
}
 
Example 8
Source File: GossipApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Bean 
public Scheduler scheduler() {
	return Schedulers.elastic();
}
 
Example 9
Source File: GossipApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Bean 
public Scheduler scheduler() {
	return Schedulers.elastic();
}
 
Example 10
Source File: ReactiveDbApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Bean
public Scheduler scheduler() {
	return Schedulers.elastic();
}
 
Example 11
Source File: MesosModule.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
public LocalScheduler getLocalScheduler(TitusRuntime titusRuntime) {
    return new DefaultLocalScheduler(Duration.ofMillis(100), Schedulers.elastic(), titusRuntime.getClock(), titusRuntime.getRegistry());
}
 
Example 12
Source File: MailDispatcher.java    From james-project with Apache License 2.0 4 votes vote down vote up
private MailDispatcher(MailStore mailStore, boolean consume, MailetContext mailetContext) {
    this.mailStore = mailStore;
    this.consume = consume;
    this.mailetContext = mailetContext;
    this.scheduler = Schedulers.elastic();
}
 
Example 13
Source File: PeriodicalHealthChecks.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Inject
PeriodicalHealthChecks(Set<HealthCheck> healthChecks, PeriodicalHealthChecksConfiguration configuration) {
    this.healthChecks = healthChecks;
    this.scheduler = Schedulers.elastic();
    this.configuration = configuration;
}
 
Example 14
Source File: R051_WhatIsAscheduler.java    From reactor-workshop with GNU General Public License v3.0 2 votes vote down vote up
/**
 * TODO Implement custom bound scheduler.
 * It must contain 10 threads named "Custom-" and a sequence number.
 * @see Executors#newFixedThreadPool(int)
 * @see ExecutorService
 * @see ThreadFactoryBuilder
 * @see Schedulers#fromExecutorService(ExecutorService)
 */
private Scheduler customScheduler() {
	return Schedulers.elastic();
}