/**
 * 
 */
package com.trendrr.oss.taskprocessor;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.trendrr.oss.executionreport.ExecutionReport;




/**
 * @author Dustin Norlander
 * @created Sep 24, 2012
 * 
 */
class TaskFilterRunner implements Runnable {

	protected static Log log = LogFactory.getLog(TaskFilterRunner.class);

	Task task;
	
	TaskFilterRunner(Task task) {
		this.task = task;
	}
	
	@Override
	public void run() {
		Task t = task;
		if (t == null) {
			log.error("Task is null, can't run anything..");
			return;
		}
		TaskFilter f = t.popFilter();
		Exception error = null;
		while(f != null && error == null) {
			Date start = new Date();
			
			try {
				Task newT = f.doFilter(t);
				if (newT == null) {
					if (!t.asynch) {
						t.getProcessor().taskComplete(t);
					}
					return;
				}
				t = newT;
				
			} catch (Exception x) {
				log.error("Caught",x);
				error = x;
			} finally {
				ExecutionReport report = ExecutionReport.instance("TaskProcessor");
				report.inc(t.getProcessor().getName() + "." + f.getClass().getSimpleName(), start);
			}
			
			if (t.asynch) {
				return;
			}
			
			if (error == null) {
				f = t.popFilter();
			}
			
		}
		if (error != null) {
			t.getProcessor().taskError(t, error);
		} else if (!t.asynch) {
			t.getProcessor().taskComplete(t);
		}
	}
}

@@ -603,16 +603,86 @@
 rn;%0A%09%09%7D%0A
+%09%09ExecutionReport report = ExecutionReport.instance(%22TaskProcessor%22);%0A
 %09%09TaskFi
@@ -705,16 +705,16 @@
 lter();%0A
-
 %09%09Except
@@ -1060,80 +1060,8 @@
 y %7B%0A
-%09%09%09%09ExecutionReport report = ExecutionReport.instance(%22TaskProcessor%22);%0A
 %09%09%09%09
@@ -1339,24 +1339,24 @@
 t.asynch) %7B%0A
-
 %09%09%09t.getProc
@@ -1380,16 +1380,77 @@
 ete(t);%0A
+%09%09%09report.inc(t.getProcessor().getName(), t.getSubmitted());%0A
 %09%09%7D%0A%09%7D%0A%7D

add more to execution report