1 package org.tigris.scarab.pipeline; 2 3 48 49 import java.io.IOException ; 50 51 import org.apache.log4j.Logger; 52 import org.apache.turbine.RunData; 53 import org.apache.turbine.TurbineException; 54 import org.apache.turbine.ValveContext; 55 import org.apache.turbine.modules.Module; 56 import org.apache.turbine.pipeline.AbstractValve; 57 import org.tigris.scarab.tools.ScarabRequestTool; 58 59 71 public class TimingInfoValve 72 extends AbstractValve 73 { 74 private static final Logger LOG = 75 Logger.getLogger(TimingInfoValve.class); 76 77 private static String KEY; 78 79 private static final boolean DEBUG = false; 80 81 public void initialize() throws Exception { 82 super.initialize(); 83 KEY = TimingInfoValve.class.getName() + ".start"; 84 85 } 86 87 90 public void invoke(RunData data, ValveContext context) 91 throws IOException , TurbineException 92 { 93 if (DEBUG) 94 { 95 Long start = (Long )data.getRequest().getAttribute(KEY); 96 if (start == null) 97 { 98 try 99 { 100 data.getResponse().setBufferSize(10000000); 101 } 102 catch (Exception e) 103 { 104 LOG.debug("Could not set high buffer size so client may " + 105 "affect timing results."); 106 } 107 ((ScarabRequestTool)Module.getTemplateContext(data) 108 .get("scarabR")).startTimer(); 109 data.getRequest() 110 .setAttribute(KEY, new Long (System.currentTimeMillis())); 111 } 112 else 113 { 114 String s = "Action=" + data.getAction() + " and template=" + 115 data.getTarget() + " took: " + 116 (System.currentTimeMillis() - start.longValue()) + " ms"; 117 LOG.debug(s); 118 try 119 { 120 data.getResponse().getWriter().println(s); 121 } 122 catch (Exception ignore) 123 { 124 } 127 } 128 } 129 130 context.invokeNext(data); 132 } 133 } 134 | Popular Tags |