Search in sources :

Example 6 with Scheduler

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();
}
Also used : SchedulerService(org.mule.runtime.api.scheduler.SchedulerService) DefaultSchedulerMessageSource(org.mule.runtime.core.internal.source.scheduler.DefaultSchedulerMessageSource) Scheduler(org.mule.runtime.api.scheduler.Scheduler) FixedFrequencyScheduler(org.mule.runtime.core.api.source.scheduler.FixedFrequencyScheduler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 7 with Scheduler

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());
}
Also used : WorkQueueProcessingStrategy(org.mule.runtime.core.internal.processor.strategy.WorkQueueProcessingStrategyFactory.WorkQueueProcessingStrategy) Scheduler(org.mule.runtime.api.scheduler.Scheduler) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 8 with Scheduler

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));
        }
    });
}
Also used : BackoffDelay(reactor.retry.BackoffDelay) Disposable(reactor.core.Disposable) Schedulers.fromExecutorService(reactor.core.scheduler.Schedulers.fromExecutorService) Exceptions.unwrap(org.mule.runtime.core.api.rx.Exceptions.unwrap) Thread.currentThread(java.lang.Thread.currentThread) Function(java.util.function.Function) TransactionCoordination.isTransactionActive(org.mule.runtime.core.api.transaction.TransactionCoordination.isTransactionActive) DEFAULT_RETRY_COUNT(org.mule.runtime.core.api.retry.policy.SimpleRetryPolicyTemplate.DEFAULT_RETRY_COUNT) Scheduler(org.mule.runtime.api.scheduler.Scheduler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Retry.onlyIf(reactor.retry.Retry.onlyIf) RetryPolicy(org.mule.runtime.core.api.retry.policy.RetryPolicy) Duration(java.time.Duration) Mono.from(reactor.core.publisher.Mono.from) Mono.just(reactor.core.publisher.Mono.just) Thread.sleep(java.lang.Thread.sleep) DEFAULT_FREQUENCY(org.mule.runtime.core.api.retry.policy.SimpleRetryPolicyTemplate.DEFAULT_FREQUENCY) Retry(reactor.retry.Retry) Mono.error(reactor.core.publisher.Mono.error) Logger(org.slf4j.Logger) ConditionalExecutorServiceDecorator(org.mule.runtime.core.internal.util.rx.ConditionalExecutorServiceDecorator) Predicate(java.util.function.Predicate) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) PolicyStatus(org.mule.runtime.core.api.retry.policy.PolicyStatus) RetryExhaustedException(reactor.retry.RetryExhaustedException) Mono.delay(reactor.core.publisher.Mono.delay) Schedulers.immediate(reactor.core.scheduler.Schedulers.immediate) ZERO(java.time.Duration.ZERO) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Duration.ofMillis(java.time.Duration.ofMillis) RETRY_COUNT_FOREVER(org.mule.runtime.core.api.retry.policy.SimpleRetryPolicyTemplate.RETRY_COUNT_FOREVER) DEFAULT_RETRY_COUNT(org.mule.runtime.core.api.retry.policy.SimpleRetryPolicyTemplate.DEFAULT_RETRY_COUNT) BackoffDelay(reactor.retry.BackoffDelay) ConditionalExecutorServiceDecorator(org.mule.runtime.core.internal.util.rx.ConditionalExecutorServiceDecorator) Retry(reactor.retry.Retry)

Example 9 with Scheduler

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();
}
Also used : Scheduler(org.mule.runtime.api.scheduler.Scheduler)

Example 10 with Scheduler

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);
    }
}
Also used : PartitionableObjectStore(org.mule.runtime.api.store.PartitionableObjectStore) ObjectStore(org.mule.runtime.api.store.ObjectStore) PartitionableExpirableObjectStore(org.mule.runtime.api.store.PartitionableExpirableObjectStore) Scheduler(org.mule.runtime.api.scheduler.Scheduler)

Aggregations

Scheduler (org.mule.runtime.api.scheduler.Scheduler)11 Test (org.junit.Test)6 Description (io.qameta.allure.Description)4 Callable (java.util.concurrent.Callable)3 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)2 SchedulerService (org.mule.runtime.api.scheduler.SchedulerService)2 PartitionableExpirableObjectStore (org.mule.runtime.api.store.PartitionableExpirableObjectStore)2 ProactorStreamProcessingStrategy (org.mule.runtime.core.internal.processor.strategy.ProactorStreamProcessingStrategyFactory.ProactorStreamProcessingStrategy)2 Thread.currentThread (java.lang.Thread.currentThread)1 Thread.sleep (java.lang.Thread.sleep)1 Duration (java.time.Duration)1 ZERO (java.time.Duration.ZERO)1 Duration.ofMillis (java.time.Duration.ofMillis)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Lock (java.util.concurrent.locks.Lock)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1