<commit_before>/**
 * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.eclipse.smarthome.model.script.internal.actions;

import org.eclipse.xtext.xbase.lib.Procedures.Procedure0;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This is a Quartz {@link Job} which executes the code of a closure that is passed
 * to the createTimer() extension method.
 * 
 * @author <NAME> - Initial contribution and API
 *
 */
public class TimerExecutionJob implements Job {

	private final Logger logger = LoggerFactory.getLogger(TimerExecutionJob.class);
	
	private Procedure0 procedure;
	private TimerImpl timer;

	/**
	 * Runs the configured closure of this job
	 * 
	 * @param context the execution context of the job
	 */
	public void execute(JobExecutionContext context) throws JobExecutionException {
		logger.debug("Executing timer '{}'", context.getJobDetail().getKey().toString());
		procedure.apply();
		timer.setTerminated(true);
	}

	/**
	 * Sets the closure for this job
	 * 
	 * @param procedure a closure without parameters
	 */
	public void setProcedure(Procedure0 procedure) {
		this.procedure = procedure;
	}

	/** 
	 * Sets the {@link TimerImpl} instance that corresponds to this job.
	 * 
	 * @param timer the associated timer instance
	 */
	public void setTimer(TimerImpl timer) {
		this.timer = timer;
	}<commit_msg>fixed NPE when executing timers in rules<commit_after>/**
 * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.eclipse.smarthome.model.script.internal.actions;

import org.eclipse.xtext.xbase.lib.Procedures.Procedure0;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This is a Quartz {@link Job} which executes the code of a closure that is passed
 * to the createTimer() extension method.
 * 
 * @author <NAME> - Initial contribution and API
 *
 */
public class TimerExecutionJob implements Job {

	private final Logger logger = LoggerFactory.getLogger(TimerExecutionJob.class);

	/**
	 * Runs the configured closure of this job
	 * 
	 * @param context the execution context of the job
	 */
	public void execute(JobExecutionContext context) throws JobExecutionException {
		logger.debug("Executing timer '{}'", context.getJobDetail().getKey().toString());
		Procedure0 procedure = (Procedure0) context.getJobDetail().getJobDataMap().get("procedure");
		TimerImpl timer = (TimerImpl) context.getJobDetail().getJobDataMap().get("timer");
		procedure.apply();
		timer.setTerminated(true);
	}

{'fraction_non_alphanumeric': 0.10074626865671642, 'fraction_numerical': 0.010572139303482588, 'mean_word_length': 4.527491408934708, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4270240', 'n_tokens_mistral': 971, 'n_tokens_neox': 896, 'n_words': 292}