/**
 * DelayAction.java
 * Created Feb 16, 2007
 * Copyright (C) Tandberg Television 2007
 */
package com.tandbergtv.workflow.exe.timer;

import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;

/**
 * Sleeps for a configurable duration that is specified in milliseconds
 * 
 * @author Sahil Verma
 */
public class DelayAction implements ActionHandler {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -4630191336045158834L;
	
	private String delay;
	
	private static final Long DEFAULT_DELAY = 15L * 1000;

	/**
	 * @param delay the delay to set
	 */
	public void setDelay(String delay) {
		this.delay = delay;
	}

	/* (non-Javadoc)
	 * @see org.jbpm.graph.def.ActionHandler#execute(org.jbpm.graph.exe.ExecutionContext)
	 */
	public void execute(ExecutionContext executionContext) throws Exception {
		Long interval = DEFAULT_DELAY;
		
		if (this.delay != null && this.delay.length() > 0)
			interval = Long.valueOf(delay) * 1000;
		
		Thread.sleep(interval);
	}
}
