Example usage for org.springframework.scheduling.support CronSequenceGenerator CronSequenceGenerator

List of usage examples for org.springframework.scheduling.support CronSequenceGenerator CronSequenceGenerator

Introduction

In this page you can find the example usage for org.springframework.scheduling.support CronSequenceGenerator CronSequenceGenerator.

Prototype

public CronSequenceGenerator(String expression) 

Source Link

Document

Construct a CronSequenceGenerator from the pattern provided, using the default TimeZone .

Usage

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

private void deploy(final AgentDeployment deployment) {
    DeploymentStatus status = deployment.getDeploymentStatus();
    if (!status.equals(DeploymentStatus.DISABLED) && !status.equals(DeploymentStatus.REQUEST_DISABLE)
            && !status.equals(DeploymentStatus.REQUEST_REMOVE)) {
        try {/*from   ww w.j  a  v  a  2 s . c  o  m*/
            log.info("Deploying '{}' to '{}'", deployment.getFlow().toString(), agent.getName());

            deployResources(deployment.getFlow());

            if (scheduledFlows.get(deployment) == null) {
                scheduledFlows.put(deployment, Collections.synchronizedList(new ArrayList<FlowRuntime>()));
            }

            doComponentDeploymentEvent(deployment, (l, f, s, c) -> l.onDeploy(agent, deployment, f, s, c));

            if (deployment.asStartType() == StartType.ON_DEPLOY) {
                scheduleNow(deployment);
            } else if (deployment.asStartType() == StartType.SCHEDULED_CRON) {
                String cron = deployment.getStartExpression();
                log.info(
                        "Scheduling '{}' on '{}' with a cron expression of '{}'  The next run time should be at: {}",
                        new Object[] { deployment.getFlow().toString(), agent.getName(), cron,
                                new CronSequenceGenerator(cron).next(new Date()) });

                ScheduledFuture<?> future = this.flowExecutionScheduler.schedule(
                        new FlowRunner(deployment, UUID.randomUUID().toString()), new CronTrigger(cron));
                scheduledDeployments.put(deployment, future);
            }

            deployment.setStatus(DeploymentStatus.DEPLOYED.name());
            deployment.setMessage("");
            log.info("Flow '{}' has been deployed", deployment.getFlow().getName());
        } catch (Exception e) {
            log.warn("Failed to start '{}'", deployment.getFlow().getName(), e);
            deployment.setStatus(DeploymentStatus.ERROR.name());
            deployment.setMessage(ExceptionUtils.getRootCauseMessage(e));
        }
        configurationService.save(deployment);
    }
}