Example usage for org.springframework.scheduling.concurrent ThreadPoolTaskScheduler ThreadPoolTaskScheduler

List of usage examples for org.springframework.scheduling.concurrent ThreadPoolTaskScheduler ThreadPoolTaskScheduler

Introduction

In this page you can find the example usage for org.springframework.scheduling.concurrent ThreadPoolTaskScheduler ThreadPoolTaskScheduler.

Prototype

ThreadPoolTaskScheduler

Source Link

Usage

From source file:com.joshlong.esb.springintegration.modules.net.sftp.config.SFTPMessageSourceFactoryBean.java

@Override
protected SFTPMessageSource createInstance() throws Exception {
    try {//ww  w  .  ja va 2s .  c o  m
        if ((localWorkingDirectory == null) || StringUtils.isEmpty(localWorkingDirectory)) {
            File tmp = SystemUtils.getJavaIoTmpDir();
            File sftpTmp = new File(tmp, "sftpInbound");
            this.localWorkingDirectory = "file://" + sftpTmp.getAbsolutePath();
        }
        assert !StringUtils
                .isEmpty(this.localWorkingDirectory) : "the local working directory mustn't be null!";

        // resource for local directory
        ResourceEditor editor = new ResourceEditor(this.resourceLoader);
        editor.setAsText(this.localWorkingDirectory);
        this.localDirectoryResource = (Resource) editor.getValue();

        fileReadingMessageSource = new FileReadingMessageSource();

        synchronizer = new SFTPInboundSynchronizer();

        if (null == taskScheduler) {
            Map<String, TaskScheduler> tss = null;

            if ((tss = applicationContext.getBeansOfType(TaskScheduler.class)).keySet().size() != 0) {
                taskScheduler = tss.get(tss.keySet().iterator().next());
            }
        }

        if (null == taskScheduler) {
            ThreadPoolTaskScheduler ts = new ThreadPoolTaskScheduler();
            ts.setPoolSize(10);
            ts.setErrorHandler(new ErrorHandler() {
                public void handleError(Throwable t) {
                    // todo make this forward a message onto the error channel (how does that work?)
                    logger.debug("error! ", t);
                }
            });

            ts.setWaitForTasksToCompleteOnShutdown(true);
            ts.initialize();
            this.taskScheduler = ts;
        }

        SFTPSessionFactory sessionFactory = SFTPSessionUtils.buildSftpSessionFactory(this.getHost(),
                this.getPassword(), this.getUsername(), this.getKeyFile(), this.getKeyFilePassword(),
                this.getPort());

        QueuedSFTPSessionPool pool = new QueuedSFTPSessionPool(15, sessionFactory);
        pool.afterPropertiesSet();
        synchronizer.setRemotePath(this.getRemoteDirectory());
        synchronizer.setPool(pool);
        synchronizer.setAutoCreatePath(this.isAutoCreateDirectories());
        synchronizer.setShouldDeleteDownloadedRemoteFiles(this.isAutoDeleteRemoteFilesOnSync());

        SFTPMessageSource sftpMessageSource = new SFTPMessageSource(fileReadingMessageSource, synchronizer);

        sftpMessageSource.setTaskScheduler(taskScheduler);

        if (null != this.trigger) {
            sftpMessageSource.setTrigger(trigger);
        }

        sftpMessageSource.setLocalDirectory(this.localDirectoryResource);
        sftpMessageSource.afterPropertiesSet();
        sftpMessageSource.start();

        return sftpMessageSource;
    } catch (Throwable thr) {
        logger.debug("error occurred when trying to configure SFTPmessageSource ", thr);
    }

    return null;
}

From source file:de.codecentric.boot.admin.config.AdminServerWebConfiguration.java

@Bean
@Qualifier("updateTaskScheduler")
public TaskScheduler updateTaskScheduler() {
    ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
    taskScheduler.setPoolSize(1);/*from   w  ww .ja va2 s.  com*/
    taskScheduler.setRemoveOnCancelPolicy(true);
    taskScheduler.setThreadNamePrefix("updateTask");
    return taskScheduler;
}

From source file:com.kurento.kmf.jsonrpcconnector.internal.server.config.JsonRpcConfiguration.java

@Bean(destroyMethod = "shutdown")
public TaskScheduler jsonrpcTaskScheduler() {
    return new ThreadPoolTaskScheduler();
}

From source file:com.netflix.genie.core.configs.ServicesConfigTest.java

/**
 * Default task scheduler.
 * @return task scheduler
 */
@Bean
public TaskScheduler taskScheduler() {
    return new ThreadPoolTaskScheduler();
}

From source file:ch.rasc.wampspring.config.DefaultWampConfiguration.java

/**
 * The default TaskScheduler to use if none is configured via
 * {@link SockJsServiceRegistration#setTaskScheduler(org.springframework.scheduling.TaskScheduler)}
 * , i.e.//w w  w  . j  a va2 s.  c  om
 *
 * <pre class="code">
 * &#064;Configuration
 * public class WampConfig extends DefaultWampConfiguration {
 * 
 *    public void registerWampEndpoints(WampEndpointRegistry registry) {
 *       registry.addEndpoint(&quot;/wamp&quot;).withSockJS().setTaskScheduler(myScheduler());
 *    }
 * 
 *    // ...
 * }
 * </pre>
 */
@Bean
public ThreadPoolTaskScheduler messageBrokerSockJsTaskScheduler() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setThreadNamePrefix("WampSockJS-");
    scheduler.setPoolSize(Runtime.getRuntime().availableProcessors());
    scheduler.setRemoveOnCancelPolicy(true);
    return scheduler;
}

From source file:org.jumpmind.metl.core.persist.AbstractExecutionService.java

public AbstractExecutionService(IPersistenceManager persistenceManager, String tablePrefix, Environment env) {
    super(persistenceManager, tablePrefix);
    this.environment = env;
    this.purgeScheduler = new ThreadPoolTaskScheduler();
    this.purgeScheduler.setThreadNamePrefix("execution-purge-job-");
    this.purgeScheduler.setPoolSize(1);
    this.purgeScheduler.initialize();
    this.purgeScheduler.setDaemon(true);
    this.purgeScheduler.scheduleWithFixedDelay(new PurgeExecutionHandler(), 60000 * 5);
}

From source file:org.jumpmind.metl.core.runtime.AgentRuntime.java

public synchronized void start() {
    if (!started && !starting) {
        starting = true;/*from  w ww  .  ja v  a  2s. c o  m*/
        log.info("Agent '{}' is being started", agent);

        executionService.markAbandoned(agent.getId());

        String agentName = agent.getName().toLowerCase();
        if (agentName.startsWith("<")) {
            agentName = agentName.substring(1);
        }
        if (agentName.endsWith(">")) {
            agentName = agentName.substring(0, agentName.length() - 1);
        }
        if (agentName.indexOf(".") > 0) {
            agentName = agentName.substring(0, agentName.indexOf("."));
        }
        final String namePrefix = LogUtils.normalizeName(agentName);

        this.flowStepsExecutionThreads = ThreadUtils.createUnboundedThreadPool(namePrefix);

        this.flowExecutionScheduler = new ThreadPoolTaskScheduler();
        this.flowExecutionScheduler.setDaemon(true);
        this.flowExecutionScheduler.setThreadNamePrefix(namePrefix + "-job-");
        /*
         * Threads are not pre-created. Set this big enough for a typical flow but not too
         * big since every agent gets their own pool. Additional threads can be obtained if
         * the entire pool is used.
         * A common Linux thread limit is 1024 per user.
         */
        this.flowExecutionScheduler.setPoolSize(20);
        this.flowExecutionScheduler.initialize();

        this.globalSettings = configurationService.findGlobalSettingsAsMap();

        List<AgentDeployment> deployments = new ArrayList<AgentDeployment>(agent.getAgentDeployments());
        for (AgentDeployment deployment : deployments) {
            deploy(deployment);
        }

        agentRequestHandler = this.flowExecutionScheduler.scheduleWithFixedDelay(new AgentRequestHandler(),
                10000);

        agent.setAgentStatus(AgentStatus.RUNNING);
        configurationService.save(agent);

        started = true;
        starting = false;
        log.info("Agent '{}' has been started", agent);
    }
}

From source file:org.springframework.amqp.rabbit.AsyncRabbitTemplate.java

@Override
public synchronized void start() {
    if (!this.running) {
        if (this.taskScheduler == null) {
            ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
            scheduler.setThreadNamePrefix(getBeanName() == null ? "asyncTemplate-" : (getBeanName() + "-"));
            scheduler.afterPropertiesSet();
            this.taskScheduler = scheduler;
        }/*from   ww  w  .  j a v  a2  s  .c o  m*/
        if (this.container != null) {
            this.container.start();
        }
        if (this.directReplyToContainer != null) {
            this.directReplyToContainer.setTaskScheduler(this.taskScheduler);
            this.directReplyToContainer.start();
        }
    }
    this.running = true;
}

From source file:org.springframework.amqp.rabbit.core.BatchingRabbitTemplateTests.java

@Before
public void setup() {
    this.connectionFactory = new CachingConnectionFactory();
    this.connectionFactory.setHost("localhost");
    this.connectionFactory.setPort(BrokerTestUtils.getPort());
    scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(1);//  w  ww  .  j a va2  s  . c  o  m
    scheduler.initialize();
}