Search in sources :

Example 11 with ManagedExecutor

use of org.eclipse.microprofile.context.ManagedExecutor in project quarkus-jberet by quarkiverse.

the class JBeretRecorder method initJobOperator.

public void initJobOperator(final JBeretConfig config, final ThreadPoolConfig threadPoolConfig, final BeanContainer beanContainer) {
    ManagedExecutor managedExecutor = beanContainer.instance(ManagedExecutor.class);
    TransactionManager transactionManager = beanContainer.instance(TransactionManager.class);
    QuarkusJobOperator operator = new QuarkusJobOperator(config, threadPoolConfig, managedExecutor, transactionManager, JBeretDataHolder.getJobs());
    JobOperatorContext operatorContext = JobOperatorContext.create(operator);
    JobOperatorContext.setJobOperatorContextSelector(() -> operatorContext);
}
Also used : TransactionManager(javax.transaction.TransactionManager) JobOperatorContext(org.jberet.spi.JobOperatorContext) ManagedExecutor(org.eclipse.microprofile.context.ManagedExecutor)

Example 12 with ManagedExecutor

use of org.eclipse.microprofile.context.ManagedExecutor in project mega by Gepardec.

the class EmployeeServiceImpl method updateEmployeesReleaseDate.

@Override
public List<String> updateEmployeesReleaseDate(List<Employee> employees) {
    final List<String> failedUserIds = new LinkedList<>();
    /*
        workaround until we can configure the managed executor in quarkus environment.
        at the moment, employees list is partitioned by 10 and therefore 10 requests to zep are started at a time.
         */
    Iterables.partition(Optional.ofNullable(employees).orElseThrow(() -> new ZepServiceException("no employees to update")), employeeUpdateParallelExecutions).forEach((partition) -> {
        try {
            CompletableFuture.allOf(partition.stream().map((employee) -> CompletableFuture.runAsync(() -> updateEmployeeReleaseDate(employee.getUserId(), employee.getReleaseDate()), managedExecutor).handle((aVoid, throwable) -> {
                Optional.ofNullable(throwable).ifPresent((t) -> {
                    logger.error(String.format("error updating %s", employee.getUserId()), t);
                    failedUserIds.add(employee.getUserId());
                });
                return null;
            })).toArray(CompletableFuture[]::new)).get();
        } catch (ExecutionException e) {
            logger.error("error updating employees", e);
            failedUserIds.addAll(getUserIds(partition));
        } catch (InterruptedException e) {
            logger.error("error updating employees", e);
            failedUserIds.addAll(getUserIds(partition));
            Thread.currentThread().interrupt();
        }
    });
    return failedUserIds;
}
Also used : Iterables(com.google.common.collect.Iterables) ZepServiceException(com.gepardec.mega.zep.ZepServiceException) Logger(org.slf4j.Logger) Employee(com.gepardec.mega.domain.model.Employee) CompletableFuture(java.util.concurrent.CompletableFuture) Collectors(java.util.stream.Collectors) EmployeeService(com.gepardec.mega.service.api.EmployeeService) Inject(javax.inject.Inject) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) ManagedExecutor(org.eclipse.microprofile.context.ManagedExecutor) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ZepService(com.gepardec.mega.zep.ZepService) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) LinkedList(java.util.LinkedList) ZepServiceException(com.gepardec.mega.zep.ZepServiceException) ExecutionException(java.util.concurrent.ExecutionException) LinkedList(java.util.LinkedList)

Example 13 with ManagedExecutor

use of org.eclipse.microprofile.context.ManagedExecutor in project kogito-runtimes by kiegroup.

the class RestClientBuilderFactory method build.

public static RestClientBuilder build(Class<?> restClass) {
    RegisterRestClient annotation = restClass.getAnnotation(RegisterRestClient.class);
    RestClientBuilderFactory instance = new RestClientBuilderFactory(restClass, annotation.baseUri(), annotation.configKey());
    RestClientBuilder builder = RestClientBuilder.newBuilder();
    instance.configureBaseUrl(builder);
    instance.configureTimeouts(builder);
    instance.configureProviders(builder);
    instance.configureSsl(builder);
    instance.configureProxy(builder);
    instance.configureRedirects(builder);
    instance.configureQueryParamStyle(builder);
    instance.configureCustomProperties(builder);
    // If we have context propagation, then propagate context to the async client threads
    InstanceHandle<ManagedExecutor> managedExecutor = Arc.container().instance(ManagedExecutor.class);
    if (managedExecutor.isAvailable()) {
        builder.executorService(managedExecutor.get());
    }
    return builder;
}
Also used : RegisterRestClient(org.eclipse.microprofile.rest.client.inject.RegisterRestClient) RestClientBuilder(org.eclipse.microprofile.rest.client.RestClientBuilder) ManagedExecutor(org.eclipse.microprofile.context.ManagedExecutor)

Aggregations

ManagedExecutor (org.eclipse.microprofile.context.ManagedExecutor)13 Path (javax.ws.rs.Path)4 SystemException (javax.transaction.SystemException)3 Transaction (javax.transaction.Transaction)3 Transactional (javax.transaction.Transactional)3 POST (javax.ws.rs.POST)3 Produces (javax.ws.rs.Produces)3 Test (org.junit.jupiter.api.Test)3 SmallRyeManagedExecutor (io.smallrye.context.SmallRyeManagedExecutor)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Inject (javax.inject.Inject)2 ContextManagerProvider (org.eclipse.microprofile.context.spi.ContextManagerProvider)2 Employee (com.gepardec.mega.domain.model.Employee)1 EmployeeService (com.gepardec.mega.service.api.EmployeeService)1 ZepService (com.gepardec.mega.zep.ZepService)1 ZepServiceException (com.gepardec.mega.zep.ZepServiceException)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1