/**
 * InitializePitchStatusNodeVariables.java
 * Created on Aug 11, 2008
 * (C) Copyright TANDBERG Television Ltd.
 */
package com.tandbergtv.watchpoint.pmm.action.asset.distribution.mediapath;

import org.apache.log4j.Logger;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;

/**
 * @author Vlada Jakobac
 *
 */
public class InitializePitchStatusNodeVariables implements ActionHandler {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	//max_counter value is max number of loop iteration in the super state node 
	private static final int MAX_COUNTER = 480;
	
	/* The logger */
	private static final Logger logger = Logger.getLogger(InitializePitchStatusNodeVariables.class);


	/* (non-Javadoc)
	 * @see org.jbpm.graph.def.ActionHandler#execute(org.jbpm.graph.exe.ExecutionContext)
	 */
	public void execute(ExecutionContext ec) throws Exception {
		/* Initialize the counts */
		Integer zeroValue = new Integer(0);
		ec.setVariable(AssetDistributionVariables.COUNTER.toString(), zeroValue);
		
		//with a delay of 60 s, maxCnt = PitchDuration [min]
		String fileSize = (String)ec.getVariable(AssetDistributionVariables.FILE_SIZE.toString());//in bytes
		int maxCnt = PitchDurationEstimator.maxPitchDurationInMin(fileSize);
		if (maxCnt > MAX_COUNTER)
			maxCnt = MAX_COUNTER;
		ec.setVariable(AssetDistributionVariables.MAX_CNT.toString(), new Integer(maxCnt));
		logger.debug("maxCnt="+maxCnt);
	}

}
