Search in sources :

Example 1 with AsyncListenableTaskExecutor

use of org.springframework.core.task.AsyncListenableTaskExecutor in project spring-integration by spring-projects.

the class GatewayProxyFactoryBean method onInit.

@Override
protected void onInit() {
    synchronized (this.initializationMonitor) {
        if (this.initialized) {
            return;
        }
        BeanFactory beanFactory = this.getBeanFactory();
        if (this.channelResolver == null && beanFactory != null) {
            this.channelResolver = new BeanFactoryChannelResolver(beanFactory);
        }
        Class<?> proxyInterface = this.determineServiceInterface();
        Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(proxyInterface);
        for (Method method : methods) {
            MethodInvocationGateway gateway = this.createGatewayForMethod(method);
            this.gatewayMap.put(method, gateway);
        }
        this.serviceProxy = new ProxyFactory(proxyInterface, this).getProxy(this.beanClassLoader);
        if (this.asyncExecutor != null) {
            Callable<String> task = () -> null;
            Future<String> submitType = this.asyncExecutor.submit(task);
            this.asyncSubmitType = submitType.getClass();
            if (this.asyncExecutor instanceof AsyncListenableTaskExecutor) {
                submitType = ((AsyncListenableTaskExecutor) this.asyncExecutor).submitListenable(task);
                this.asyncSubmitListenableType = submitType.getClass();
            }
        }
        this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
        this.initialized = true;
    }
}
Also used : AsyncListenableTaskExecutor(org.springframework.core.task.AsyncListenableTaskExecutor) ProxyFactory(org.springframework.aop.framework.ProxyFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) Method(java.lang.reflect.Method)

Example 2 with AsyncListenableTaskExecutor

use of org.springframework.core.task.AsyncListenableTaskExecutor in project spring-framework by spring-projects.

the class BufferedSimpleAsyncHttpRequestFactoryTests method createRequestFactory.

@Override
protected AsyncClientHttpRequestFactory createRequestFactory() {
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    AsyncListenableTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
    requestFactory.setTaskExecutor(taskExecutor);
    return requestFactory;
}
Also used : AsyncListenableTaskExecutor(org.springframework.core.task.AsyncListenableTaskExecutor) SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor)

Example 3 with AsyncListenableTaskExecutor

use of org.springframework.core.task.AsyncListenableTaskExecutor in project spring-framework by spring-projects.

the class AsyncExecutionAspectSupport method determineAsyncExecutor.

/**
	 * Determine the specific executor to use when executing the given method.
	 * Should preferably return an {@link AsyncListenableTaskExecutor} implementation.
	 * @return the executor to use (or {@code null}, but just if no default executor is available)
	 */
protected AsyncTaskExecutor determineAsyncExecutor(Method method) {
    AsyncTaskExecutor executor = this.executors.get(method);
    if (executor == null) {
        Executor targetExecutor;
        String qualifier = getExecutorQualifier(method);
        if (StringUtils.hasLength(qualifier)) {
            targetExecutor = findQualifiedExecutor(this.beanFactory, qualifier);
        } else {
            targetExecutor = this.defaultExecutor;
            if (targetExecutor == null) {
                synchronized (this.executors) {
                    if (this.defaultExecutor == null) {
                        this.defaultExecutor = getDefaultExecutor(this.beanFactory);
                    }
                    targetExecutor = this.defaultExecutor;
                }
            }
        }
        if (targetExecutor == null) {
            return null;
        }
        executor = (targetExecutor instanceof AsyncListenableTaskExecutor ? (AsyncListenableTaskExecutor) targetExecutor : new TaskExecutorAdapter(targetExecutor));
        this.executors.put(method, executor);
    }
    return executor;
}
Also used : AsyncListenableTaskExecutor(org.springframework.core.task.AsyncListenableTaskExecutor) Executor(java.util.concurrent.Executor) AsyncTaskExecutor(org.springframework.core.task.AsyncTaskExecutor) AsyncListenableTaskExecutor(org.springframework.core.task.AsyncListenableTaskExecutor) TaskExecutor(org.springframework.core.task.TaskExecutor) AsyncTaskExecutor(org.springframework.core.task.AsyncTaskExecutor) TaskExecutorAdapter(org.springframework.core.task.support.TaskExecutorAdapter)

Aggregations

AsyncListenableTaskExecutor (org.springframework.core.task.AsyncListenableTaskExecutor)3 Method (java.lang.reflect.Method)1 Executor (java.util.concurrent.Executor)1 ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 AsyncTaskExecutor (org.springframework.core.task.AsyncTaskExecutor)1 SimpleAsyncTaskExecutor (org.springframework.core.task.SimpleAsyncTaskExecutor)1 TaskExecutor (org.springframework.core.task.TaskExecutor)1 TaskExecutorAdapter (org.springframework.core.task.support.TaskExecutorAdapter)1 BeanFactoryChannelResolver (org.springframework.integration.support.channel.BeanFactoryChannelResolver)1