@@ -0,0 +1,2392 @@
+/**%0A * %0A */%0Apackage com.trendrr.strest.contrib.filters;%0A%0Aimport java.util.Date;%0A%0Aimport org.apache.commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;%0Aimport org.jboss.netty.handler.codec.http.HttpResponse;%0A%0Aimport com.trendrr.strest.StrestException;%0Aimport com.trendrr.strest.server.StrestController;%0Aimport com.trendrr.strest.server.StrestControllerFilter;%0A%0A%0A/**%0A * @author Dustin Norlander%0A * @created May 17, 2011%0A * %0A */%0Apublic class TimingFilter implements StrestControllerFilter %7B%0A%0A%09protected Log log = LogFactory.getLog(TimingFilter.class);%0A%0A%09/* (non-Javadoc)%0A%09 * @see com.trendrr.strest.server.StrestControllerFilter#before(com.trendrr.strest.server.StrestController)%0A%09 */%0A%09@Override%0A%09public void before(StrestController controller) throws StrestException %7B%0A%09%09controller.getTxnStorage().put(%22timing_filter_start%22, new Date());%0A%09%09System.out.println(%22timing start%22);%0A%09%7D%0A%0A%09/* (non-Javadoc)%0A%09 * @see com.trendrr.strest.server.StrestControllerFilter#after(com.trendrr.strest.server.StrestController)%0A%09 */%0A%09@Override%0A%09public void after(StrestController controller) throws StrestException %7B%0A%09%09System.out.println(%22timing start%22);%0A%09%09Date start = (Date)controller.getTxnStorage().remove(%22timing_filter_start%22);%0A%09%09if (start == null)%0A%09%09%09return;%0A%09%09this.timingResult(controller, new Date().getTime()-start.getTime());%0A%09%7D%0A%0A%09/**%0A%09 * Override this to do something else with the timing information.%0A%09 * %0A%09 * Examples: logging, tracking long running actions, ect.%0A%09 * %0A%09 * @param controller%0A%09 * @param millis%0A%09 */%0A%09public void timingResult(StrestController controller, long millis) %7B%0A%09%09System.out.println(millis);%0A%09%09%0A%09%09StringBuilder str = new StringBuilder();%0A%09%09str.append(%22*************** Action COMPLETE ****%5Cn%22);%0A%09%09str.append(%22Route : %22 );%0A%09%09for (String r : controller.routes()) %7B%0A%09%09%09str.append(r + %22,%22);%0A%09%09%7D%0A%09%09str.append(%22%5CnParams: %22);%0A%09%09str.append( controller.getParams().toJSONString());%0A%09%09str.append(%22%5CnMillis: %22);%0A%09%09str.append(millis);%0A%09%09str.append(%22%5Cn************************************%5Cn%22);%0A%09%09log.info(str.toString());%0A%09%7D%0A%09%0A%09/* (non-Javadoc)%0A%09 * @see com.trendrr.strest.server.StrestControllerFilter#error(com.trendrr.strest.server.StrestController, org.jboss.netty.handler.codec.http.HttpResponse, java.lang.Exception)%0A%09 */%0A%09@Override%0A%09public void error(StrestController controller, HttpResponse response,%0A%09%09%09Exception exception) %7B%0A%09%09// TODO Auto-generated method stub%0A%0A%09%7D%0A%7D%0A

Add a filter to measure number of millis a controller takes