本文整理了Java中reactor.core.scheduler.Schedulers.addExecutorServiceDecorator()
方法的一些代码示例,展示了Schedulers.addExecutorServiceDecorator()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Schedulers.addExecutorServiceDecorator()
方法的具体详情如下:
包路径:reactor.core.scheduler.Schedulers
类名称:Schedulers
方法名:addExecutorServiceDecorator
[英]Set up an additional ScheduledExecutorService decorator for a given key only if that key is not already present. Note that the Factory's legacy Factory#decorateExecutorService(String,Supplier) method will always be invoked last after applying the decorators added via this method.
The decorator is a BiFunction taking the Scheduler and the backing ScheduledExecutorService as second argument. It returns the decorated ScheduledExecutorService.
[中]仅当给定密钥尚未存在时,才为该密钥设置额外的ScheduledExecutorService装饰器。请注意,工厂的旧工厂#decorateExecutorService(String,Supplier)方法将始终在应用通过此方法添加的decorators后最后调用。
decorator是一个双函数,将调度器和支持的ScheduledExecutorService作为第二个参数。它返回修饰的ScheduledExecutorService。
代码示例来源:origin: reactor/reactor-core
/**
* If Micrometer is available, set-up a decorator that will instrument any
* {@link ExecutorService} that backs a {@link Scheduler}.
* No-op if Micrometer isn't available.
*
* This instrumentation sends data to the Micrometer Global Registry.
*
* @implNote Note that this is added as a decorator via Schedulers when enabling metrics for schedulers, which doesn't change the Factory.
*/
public static void enableMetrics() {
if (Metrics.isInstrumentationAvailable()) {
addExecutorServiceDecorator(SchedulerMetricDecorator.METRICS_DECORATOR_KEY, new SchedulerMetricDecorator());
}
}
代码示例来源:origin: reactor/reactor-core
@Test
public void schedulerDecoratorAddsSameIfDifferentKeys() {
AtomicInteger tracker = new AtomicInteger();
BiFunction<Scheduler, ScheduledExecutorService, ScheduledExecutorService> decorator = (scheduler, serv) -> {
tracker.addAndGet(1);
return serv;
};
//decorators are cleared after test
Schedulers.addExecutorServiceDecorator("k1", decorator);
Schedulers.addExecutorServiceDecorator("k2", decorator);
Schedulers.addExecutorServiceDecorator("k3", decorator);
//trigger the decorators
Schedulers.newSingle("foo").dispose();
assertThat(tracker).as("decorator invoked three times").hasValue(3);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void schedulerDecoratorIsAdditive() throws InterruptedException {
AtomicInteger tracker = new AtomicInteger();
BiFunction<Scheduler, ScheduledExecutorService, ScheduledExecutorService> decorator1 = (scheduler, serv) -> {
tracker.addAndGet(1);
return serv;
};
BiFunction<Scheduler, ScheduledExecutorService, ScheduledExecutorService> decorator2 = (scheduler, serv) -> {
tracker.addAndGet(10);
return serv;
};
BiFunction<Scheduler, ScheduledExecutorService, ScheduledExecutorService> decorator3 = (scheduler, serv) -> {
tracker.addAndGet(100);
return serv;
};
//decorators are cleared after test
Schedulers.addExecutorServiceDecorator("k1", decorator1);
Schedulers.addExecutorServiceDecorator("k2", decorator2);
Schedulers.addExecutorServiceDecorator("k3", decorator3);
//trigger the decorators
Schedulers.newSingle("foo").dispose();
assertThat(tracker).as("3 decorators invoked").hasValue(111);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void schedulerDecoratorAddsOnceIfSameKey() {
AtomicInteger tracker = new AtomicInteger();
BiFunction<Scheduler, ScheduledExecutorService, ScheduledExecutorService> decorator1 = (scheduler, serv) -> {
tracker.addAndGet(1);
return serv;
};
BiFunction<Scheduler, ScheduledExecutorService, ScheduledExecutorService> decorator2 = (scheduler, serv) -> {
tracker.addAndGet(10);
return serv;
};
//decorators are cleared after test
Schedulers.addExecutorServiceDecorator("k1", decorator1);
Schedulers.addExecutorServiceDecorator("k1", decorator2);
//trigger the decorators
Schedulers.newSingle("foo").dispose();
assertThat(tracker).as("decorator invoked once").hasValue(1);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void schedulerDecoratorDisposedWhenRemoved() {
AtomicBoolean disposeTracker = new AtomicBoolean();
class DisposableDecorator implements BiFunction<Scheduler, ScheduledExecutorService, ScheduledExecutorService>,
Disposable {
@Override
public ScheduledExecutorService apply(Scheduler scheduler,
ScheduledExecutorService service) {
return service;
}
@Override
public void dispose() {
disposeTracker.set(true);
}
}
DisposableDecorator decorator = new DisposableDecorator();
Schedulers.addExecutorServiceDecorator("k1", decorator);
assertThat(Schedulers.removeExecutorServiceDecorator("k1"))
.as("decorator removed")
.isSameAs(decorator);
assertThat(disposeTracker)
.as("decorator disposed")
.isTrue();
}
代码示例来源:origin: io.projectreactor/reactor-core
/**
* If Micrometer is available, set-up a decorator that will instrument any
* {@link ExecutorService} that backs a {@link Scheduler}.
* No-op if Micrometer isn't available.
*
* This instrumentation sends data to the Micrometer Global Registry.
*
* @implNote Note that this is added as a decorator via Schedulers when enabling metrics for schedulers, which doesn't change the Factory.
*/
public static void enableMetrics() {
if (Metrics.isInstrumentationAvailable()) {
addExecutorServiceDecorator(SchedulerMetricDecorator.METRICS_DECORATOR_KEY, new SchedulerMetricDecorator());
}
}
内容来源于网络,如有侵权,请联系作者删除!