Example usage for org.springframework.core.task SimpleAsyncTaskExecutor SimpleAsyncTaskExecutor

List of usage examples for org.springframework.core.task SimpleAsyncTaskExecutor SimpleAsyncTaskExecutor

Introduction

In this page you can find the example usage for org.springframework.core.task SimpleAsyncTaskExecutor SimpleAsyncTaskExecutor.

Prototype

public SimpleAsyncTaskExecutor(ThreadFactory threadFactory) 

Source Link

Document

Create a new SimpleAsyncTaskExecutor with the given external thread factory.

Usage

From source file:com.github.ljtfreitas.restify.http.spring.client.call.exec.ListenableFutureEndpointCallExecutableFactory.java

public ListenableFutureEndpointCallExecutableFactory() {
    this(new SimpleAsyncTaskExecutor("ListenableFutureEndpointCallExecutable"));
}

From source file:org.zalando.spring.boot.async.AsyncExecutorConfiguration.java

@Override
public Executor getAsyncExecutor() {
    if (properties.isEnabled()) {
        if (executor != null) {
            return executor;
        } else {//from  www.j  a v a2s.  co  m
            throw new BeanCreationException("Expecting a 'ThreadPoolTaskExecutor' injected, but was 'null'");
        }
    } else {
        log.info(
                "'AsyncExecutorConfiguration' is disabled, so create 'SimpleAsyncTaskExecutor' with 'threadNamePrefix' - '{}'",
                properties.getThreadNamePrefix());
        return new SimpleAsyncTaskExecutor(properties.getThreadNamePrefix());
    }
}

From source file:com.qpark.eip.core.spring.lockedoperation.AbstractAsyncLockableOperation.java

/**
 * Invoke the real logic of the {@link LockableOperation}.
 *
 * @param context/*www  . ja  v  a2s  . c  o  m*/
 *            the {@link LockableOperationContext} (could be
 *            <code>null</code>) to pass to the {@link LockableOperation}.
 */
@Override
protected final void invokeOperation(final LockableOperationContext context) {
    this.getLogger().debug("Create AsyncRunner for the operation {} ({})",
            new Object[] { this.getName(), this.getUUID() });
    AutowireCapableBeanFactory beanFactory = this.applicationContext.getAutowireCapableBeanFactory();
    AsyncLockableOperationRunner operationRunner = beanFactory.createBean(AsyncLockableOperationRunner.class);
    beanFactory.initializeBean(operationRunner,
            new StringBuffer(this.getName()).append(System.currentTimeMillis()).toString());

    operationRunner.setOperation(this);
    operationRunner.setContext(context);

    SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(
            new StringBuffer("exec").append(this.getName()).toString());
    executor.submit(operationRunner);
    this.getLogger().debug("AsyncRunner of operation {} ({}) started with SimpleAsyncTaskExecutor",
            new Object[] { this.getName(), this.getUUID() });
}

From source file:org.apache.servicemix.jbi.cluster.requestor.AbstractJmsRequestorPool.java

/**
 * Create a default TaskExecutor. Called if no explicit TaskExecutor has been specified.
 * <p>The default implementation builds a {@link org.springframework.core.task.SimpleAsyncTaskExecutor}
 * with the specified bean name (or the class name, if no bean name specified) as thread name prefix.
 * @see org.springframework.core.task.SimpleAsyncTaskExecutor#SimpleAsyncTaskExecutor(String)
 *//*w  ww  .  j  a  v  a  2  s .  c  o m*/
protected TaskExecutor createDefaultTaskExecutor() {
    String beanName = getBeanName();
    String threadNamePrefix = (beanName != null ? beanName + "-" : DEFAULT_THREAD_NAME_PREFIX);
    return new SimpleAsyncTaskExecutor(threadNamePrefix);
}

From source file:org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.java

/**
 * Initialize this container.//from   w  ww.ja  v a2  s. c  o m
 * <p>
 * Creates a Rabbit Connection and calls {@link #doInitialize()}.
 */
public void initialize() {
    try {
        synchronized (this.lifecycleMonitor) {
            this.lifecycleMonitor.notifyAll();
        }
        initializeProxy(this.delegate);
        doInitialize();
        if (!this.isExposeListenerChannel() && this.transactionManager != null) {
            logger.warn("exposeListenerChannel=false is ignored when using a TransactionManager");
        }
        if (!this.taskExecutorSet && StringUtils.hasText(this.getBeanName())) {
            this.taskExecutor = new SimpleAsyncTaskExecutor(this.getBeanName() + "-");
            this.taskExecutorSet = true;
        }
        if (this.transactionManager != null) {
            if (!isChannelTransacted()) {
                logger.debug(
                        "The 'channelTransacted' is coerced to 'true', when 'transactionManager' is provided");
                setChannelTransacted(true);
            }

        }
    } catch (Exception ex) {
        throw convertRabbitAccessException(ex);
    }
}

From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.java

/**
 * Creates the specified number of concurrent consumers, in the form of a Rabbit Channel plus associated
 * MessageConsumer./* w  ww .j a v  a2  s  .c o  m*/
 * @throws Exception Any Exception.
 */
@Override
protected void doInitialize() throws Exception {
    checkMissingQueuesFatal();
    if (!this.isExposeListenerChannel() && this.transactionManager != null) {
        logger.warn("exposeListenerChannel=false is ignored when using a TransactionManager");
    }
    if (!this.taskExecutorSet && StringUtils.hasText(this.getBeanName())) {
        this.taskExecutor = new SimpleAsyncTaskExecutor(this.getBeanName() + "-");
        this.taskExecutorSet = true;
    }
    if (this.transactionManager != null) {
        if (!isChannelTransacted()) {
            logger.debug("The 'channelTransacted' is coerced to 'true', when 'transactionManager' is provided");
            setChannelTransacted(true);
        }

    }
}

From source file:org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer.java

/**
 * Creates a default TaskExecutor. Called if no explicit TaskExecutor has been specified.
 * <p>The default implementation builds a {@link org.springframework.core.task.SimpleAsyncTaskExecutor}
 * with the specified bean name (or the class name, if no bean name specified) as thread name prefix.
 * @see org.springframework.core.task.SimpleAsyncTaskExecutor#SimpleAsyncTaskExecutor(String)
 *//*from  w  w  w  .j  a v  a  2  s. c  om*/
protected TaskExecutor createDefaultTaskExecutor() {
    String threadNamePrefix = (beanName != null ? beanName + "-" : DEFAULT_THREAD_NAME_PREFIX);
    return new SimpleAsyncTaskExecutor(threadNamePrefix);
}

From source file:org.springframework.kafka.listener.KafkaMessageListenerContainer.java

@Override
protected void doStart() {
    if (isRunning()) {
        return;/*w  ww  .  j  a v  a2  s  .com*/
    }
    ContainerProperties containerProperties = getContainerProperties();

    if (!this.consumerFactory.isAutoCommit()) {
        AckMode ackMode = containerProperties.getAckMode();
        if (ackMode.equals(AckMode.COUNT) || ackMode.equals(AckMode.COUNT_TIME)) {
            Assert.state(containerProperties.getAckCount() > 0, "'ackCount' must be > 0");
        }
        if ((ackMode.equals(AckMode.TIME) || ackMode.equals(AckMode.COUNT_TIME))
                && containerProperties.getAckTime() == 0) {
            containerProperties.setAckTime(5000);
        }
    }

    Object messageListener = containerProperties.getMessageListener();
    Assert.state(messageListener != null, "A MessageListener is required");
    if (messageListener instanceof GenericAcknowledgingMessageListener) {
        this.acknowledgingMessageListener = (GenericAcknowledgingMessageListener<?>) messageListener;
    } else if (messageListener instanceof GenericMessageListener) {
        this.listener = (GenericMessageListener<?>) messageListener;
    } else {
        throw new IllegalStateException("messageListener must be 'MessageListener' "
                + "or 'AcknowledgingMessageListener', not " + messageListener.getClass().getName());
    }
    if (containerProperties.getConsumerTaskExecutor() == null) {
        SimpleAsyncTaskExecutor consumerExecutor = new SimpleAsyncTaskExecutor(
                (getBeanName() == null ? "" : getBeanName()) + "-kafka-consumer-");
        containerProperties.setConsumerTaskExecutor(consumerExecutor);
    }
    if (containerProperties.getListenerTaskExecutor() == null) {
        SimpleAsyncTaskExecutor listenerExecutor = new SimpleAsyncTaskExecutor(
                (getBeanName() == null ? "" : getBeanName()) + "-kafka-listener-");
        containerProperties.setListenerTaskExecutor(listenerExecutor);
    }
    this.listenerConsumer = new ListenerConsumer(this.listener, this.acknowledgingMessageListener);
    setRunning(true);
    this.listenerConsumerFuture = containerProperties.getConsumerTaskExecutor()
            .submitListenable(this.listenerConsumer);
}

From source file:org.springframework.xd.dirt.integration.rabbit.RabbitMessageBus.java

private void doRegisterConsumer(String name, MessageChannel moduleInputChannel, Queue queue,
        RabbitPropertiesAccessor properties, boolean isPubSub) {
    // Fix for XD-2503
    // Temporarily overrides the thread context classloader with the one where the SimpleMessageListenerContainer is defined
    // This allows for the proxying that happens while initializing the SimpleMessageListenerContainer to work correctly
    ClassLoader originalClassloader = Thread.currentThread().getContextClassLoader();
    try {//from w  w w  .j  a va2 s  . c  om
        ClassUtils.overrideThreadContextClassLoader(SimpleMessageListenerContainer.class.getClassLoader());
        SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(
                this.connectionFactory);
        listenerContainer.setAcknowledgeMode(properties.getAcknowledgeMode(this.defaultAcknowledgeMode));
        listenerContainer.setChannelTransacted(properties.getTransacted(this.defaultChannelTransacted));
        listenerContainer
                .setDefaultRequeueRejected(properties.getRequeueRejected(this.defaultDefaultRequeueRejected));
        if (!isPubSub) {
            int concurrency = properties.getConcurrency(this.defaultConcurrency);
            concurrency = concurrency > 0 ? concurrency : 1;
            listenerContainer.setConcurrentConsumers(concurrency);
            int maxConcurrency = properties.getMaxConcurrency(this.defaultMaxConcurrency);
            if (maxConcurrency > concurrency) {
                listenerContainer.setMaxConcurrentConsumers(maxConcurrency);
            }
        }
        listenerContainer.setPrefetchCount(properties.getPrefetchCount(this.defaultPrefetchCount));
        listenerContainer.setTxSize(properties.getTxSize(this.defaultTxSize));
        listenerContainer.setTaskExecutor(new SimpleAsyncTaskExecutor(queue.getName() + "-"));
        listenerContainer.setQueues(queue);
        int maxAttempts = properties.getMaxAttempts(this.defaultMaxAttempts);
        if (maxAttempts > 1) {
            RetryOperationsInterceptor retryInterceptor = RetryInterceptorBuilder.stateless()
                    .maxAttempts(maxAttempts)
                    .backOffOptions(properties.getBackOffInitialInterval(this.defaultBackOffInitialInterval),
                            properties.getBackOffMultiplier(this.defaultBackOffMultiplier),
                            properties.getBackOffMaxInterval(this.defaultBackOffMaxInterval))
                    .recoverer(new RejectAndDontRequeueRecoverer()).build();
            listenerContainer.setAdviceChain(new Advice[] { retryInterceptor });
        }
        listenerContainer.setAfterReceivePostProcessors(this.decompressingPostProcessor);
        listenerContainer.setMessagePropertiesConverter(RabbitMessageBus.inboundMessagePropertiesConverter);
        listenerContainer.afterPropertiesSet();
        AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter(listenerContainer);
        adapter.setBeanFactory(this.getBeanFactory());
        DirectChannel bridgeToModuleChannel = new DirectChannel();
        bridgeToModuleChannel.setBeanFactory(this.getBeanFactory());
        bridgeToModuleChannel.setBeanName(name + ".bridge");
        adapter.setOutputChannel(bridgeToModuleChannel);
        adapter.setBeanName("inbound." + name);
        DefaultAmqpHeaderMapper mapper = new DefaultAmqpHeaderMapper();
        mapper.setRequestHeaderNames(properties.getRequestHeaderPattens(this.defaultRequestHeaderPatterns));
        mapper.setReplyHeaderNames(properties.getReplyHeaderPattens(this.defaultReplyHeaderPatterns));
        adapter.setHeaderMapper(mapper);
        adapter.afterPropertiesSet();
        Binding consumerBinding = Binding.forConsumer(name, adapter, moduleInputChannel, properties);
        addBinding(consumerBinding);
        ReceivingHandler convertingBridge = new ReceivingHandler();
        convertingBridge.setOutputChannel(moduleInputChannel);
        convertingBridge.setBeanName(name + ".convert.bridge");
        convertingBridge.afterPropertiesSet();
        bridgeToModuleChannel.subscribe(convertingBridge);
        consumerBinding.start();
    } finally {
        Thread.currentThread().setContextClassLoader(originalClassloader);
    }
}