use of org.mule.runtime.api.scheduler.Scheduler in project mule by mulesoft.
the class DefaultSchedulerMessageSourceTestCase method disposeScheduler.
@Test
public void disposeScheduler() throws Exception {
SchedulerService schedulerService = muleContext.getSchedulerService();
reset(schedulerService);
AtomicReference<Scheduler> pollScheduler = new AtomicReference<>();
doAnswer(invocation -> {
Scheduler scheduler = (Scheduler) invocation.callRealMethod();
pollScheduler.set(scheduler);
return scheduler;
}).when(schedulerService).cpuLightScheduler();
DefaultSchedulerMessageSource schedulerMessageSource = createMessageSource();
verify(schedulerService).cpuLightScheduler();
schedulerMessageSource.start();
verify(pollScheduler.get()).scheduleAtFixedRate(any(), anyLong(), anyLong(), any());
schedulerMessageSource.stop();
schedulerMessageSource.dispose();
verify(pollScheduler.get()).stop();
}
use of org.mule.runtime.api.scheduler.Scheduler in project mule by mulesoft.
the class WorkQueueProcessingStrategyTestCase method blockingRejectedExecution.
@Test
@Description("If IO pool is busy OVERLOAD error is thrown")
public void blockingRejectedExecution() throws Exception {
Scheduler blockingSchedulerSpy = spy(blocking);
Scheduler rejectingSchedulerSpy = spy(new RejectingScheduler(blockingSchedulerSpy));
flow = flowBuilder.get().processors(blockingProcessor).processingStrategyFactory((context, prefix) -> new WorkQueueProcessingStrategy(() -> rejectingSchedulerSpy)).build();
flow.initialise();
flow.start();
expectRejected();
processFlow(testEvent());
}
use of org.mule.runtime.api.scheduler.Scheduler in project mule by mulesoft.
the class SimpleRetryPolicy method applyPolicy.
@Override
public <T> Publisher<T> applyPolicy(Publisher<T> publisher, Predicate<Throwable> shouldRetry, Consumer<Throwable> onExhausted, Function<Throwable, Throwable> errorFunction, Scheduler retryScheduler) {
return from(publisher).onErrorResume(e -> {
if (shouldRetry.test(e)) {
Retry<T> retry = (Retry<T>) onlyIf(ctx -> shouldRetry.test(unwrap(ctx.exception()))).backoff(ctx -> new BackoffDelay(frequency, ZERO, ZERO));
if (count != RETRY_COUNT_FOREVER) {
retry = retry.retryMax(count - 1);
}
reactor.core.scheduler.Scheduler reactorRetryScheduler = fromExecutorService(new ConditionalExecutorServiceDecorator(retryScheduler, s -> isTransactionActive()));
Mono<T> retryMono = from(publisher).retryWhen(retry.withBackoffScheduler(reactorRetryScheduler)).doOnError(e2 -> onExhausted.accept(unwrap(e2))).onErrorMap(RetryExhaustedException.class, e2 -> errorFunction.apply(unwrap(e2.getCause())));
return delay(frequency, reactorRetryScheduler).then(isTransactionActive() ? just(retryMono.block()) : retryMono);
} else {
e = unwrap(e);
onExhausted.accept(e);
return error(errorFunction.apply(e));
}
});
}
use of org.mule.runtime.api.scheduler.Scheduler in project mule by mulesoft.
the class MuleObjectStoreManager method dispose.
@Override
public void dispose() {
for (Scheduler scheduler : expirationSchedulers.values()) {
scheduler.stop();
}
expirationSchedulers.clear();
basePersistentPartition = null;
baseTransientPartition = null;
basePersistentStore = null;
baseTransientStore = null;
stores.values().forEach(store -> disposeIfNeeded(store, LOGGER));
stores.clear();
}
use of org.mule.runtime.api.scheduler.Scheduler in project mule by mulesoft.
the class MuleObjectStoreManager method disposeStore.
/**
* {@inheritDoc}
*/
@Override
public void disposeStore(String name) throws ObjectStoreException {
if (basePersistentStoreKey.equals(name) || baseTransientStoreKey.equals(name)) {
return;
}
ObjectStore store = stores.remove(name);
if (store == null) {
throw noSuchStoreException(name);
}
try {
if (store instanceof ObjectStorePartition) {
ObjectStorePartition partition = (ObjectStorePartition) store;
String partitionName = partition.getPartitionName();
partition.getBaseStore().disposePartition(partitionName);
Scheduler scheduler = expirationSchedulers.remove(partitionName);
if (scheduler != null) {
scheduler.stop();
}
} else {
try {
store.clear();
} catch (UnsupportedOperationException e) {
LOGGER.warn(format("ObjectStore of class %s does not support clearing", store.getClass().getCanonicalName()), e);
}
}
} finally {
disposeIfNeeded(store, LOGGER);
}
}
Aggregations