package org.bench4q.agent.plugin.basic.timer;

import org.apache.log4j.Logger;
import org.bench4q.agent.plugin.Constructor;
import org.bench4q.agent.plugin.Parameter;
import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.plugin.behavior.Behavior;
import org.bench4q.agent.plugin.behavior.BehaviorType;
import org.bench4q.agent.utils.Type.SupportTypes;

@Plugin("ConstantTimer")
public class ConstantTimerPlugin {
	private Logger logger = Logger.getLogger(ConstantTimerPlugin.class);

	@Constructor
	public ConstantTimerPlugin() {

	}

	@Behavior(value = "Sleep", type = BehaviorType.TIMER_BEHAVIOR)
	public TimerReturn sleep(
			@Parameter(value = "time", type = SupportTypes.Field) int time) {
		try {
			Thread.sleep(time);
			return new TimerReturn(true);
		} catch (Exception e) {
			logger.info("sleep interrupted!");
			return new TimerReturn(false);
		}
	}
}
