Example usage for org.joda.time.base AbstractInstant toString

List of usage examples for org.joda.time.base AbstractInstant toString

Introduction

In this page you can find the example usage for org.joda.time.base AbstractInstant toString.

Prototype

@ToString
public String toString() 

Source Link

Document

Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZZ).

Usage

From source file:org.eclipse.smarthome.model.script.actions.ScriptExecution.java

License:Open Source License

/**
 * Schedules a block of code for later execution.
 * /*  www.  j a va2  s .  c om*/
 * @param instant the point in time when the code should be executed
 * @param closure the code block to execute
 * 
 * @return a handle to the created timer, so that it can be canceled or rescheduled
 * @throws ScriptExecutionException if an error occurs during the execution
 */
public static Timer createTimer(AbstractInstant instant, Procedure0 closure) {
    Logger logger = LoggerFactory.getLogger(ScriptExecution.class);
    JobKey jobKey = new JobKey(instant.toString() + ": " + closure.toString());
    Trigger trigger = newTrigger().startAt(instant.toDate()).build();
    Timer timer = new TimerImpl(jobKey, trigger.getKey(), instant);
    try {
        JobDataMap dataMap = new JobDataMap();
        dataMap.put("procedure", closure);
        dataMap.put("timer", timer);
        JobDetail job = newJob(TimerExecutionJob.class).withIdentity(jobKey).usingJobData(dataMap).build();
        TimerImpl.scheduler.scheduleJob(job, trigger);
        logger.debug("Scheduled code for execution at {}", instant.toString());
        return timer;
    } catch (SchedulerException e) {
        logger.error("Failed to schedule code for execution.", e);
        return null;
    }
}

From source file:org.openhab.core.jsr223.internal.shared.Openhab.java

License:Open Source License

private static Timer makeTimer(AbstractInstant instant, String closure, JobDataMap dataMap) {
    JobKey jobKey = new JobKey(instant.toString() + ": " + closure.toString());
    Trigger trigger = newTrigger().startAt(instant.toDate()).build();
    Timer timer = new Timer(jobKey, trigger.getKey(), instant);
    dataMap.put("timer", timer);
    try {//w w  w . j  a v  a  2 s. co m
        JobDetail job = newJob(TimerExecutionJob.class).withIdentity(jobKey).usingJobData(dataMap).build();
        Timer.scheduler.scheduleJob(job, trigger);
        logger.debug("Scheduled code for execution at {}", instant.toString());
        return timer;
    } catch (SchedulerException e) {
        logger.error("Failed to schedule code for execution.", e);
        return null;
    }
}

From source file:org.openhab.model.script.actions.ScriptExecution.java

License:Open Source License

/**
 * helper function to create the timer/*from w  w  w  .java2  s .  c  o m*/
 * @param instant the point in time when the code should be executed
 * @param closure string for job id
 * @param dataMap job data map, preconfigured with arguments
 * @return
 */

private static Timer makeTimer(AbstractInstant instant, String closure, JobDataMap dataMap) {
    JobKey jobKey = new JobKey(instant.toString() + ": " + closure.toString());
    Trigger trigger = newTrigger().startAt(instant.toDate()).build();
    Timer timer = new TimerImpl(jobKey, trigger.getKey(), instant);
    dataMap.put("timer", timer);
    try {
        JobDetail job = newJob(TimerExecutionJob.class).withIdentity(jobKey).usingJobData(dataMap).build();
        TimerImpl.scheduler.scheduleJob(job, trigger);
        logger.debug("Scheduled code for execution at {}", instant.toString());
        return timer;
    } catch (SchedulerException e) {
        logger.error("Failed to schedule code for execution.", e);
        return null;
    }
}