001 package railo.runtime.monitor; 002 003 import java.io.IOException; 004 import java.util.ArrayList; 005 import java.util.Iterator; 006 import java.util.List; 007 008 import railo.commons.lang.ExceptionUtil; 009 import railo.runtime.PageContext; 010 import railo.runtime.config.ConfigServer; 011 import railo.runtime.config.ConfigWeb; 012 013 public class ActionMonitorCollectorImpl implements ActionMonitorCollector { 014 015 private List<ActionMonitor> monitors; 016 017 @Override 018 public void addMonitor(ConfigServer cs,Object oMonitor, String name, boolean log) throws IOException { 019 ActionMonitor monitor; 020 try { 021 monitor = (ActionMonitor) oMonitor; 022 } catch (Throwable t) { 023 throw ExceptionUtil.toIOException(t); 024 } 025 monitor.init(cs,name,log); 026 if(monitors==null) monitors=new ArrayList<ActionMonitor>(); 027 monitors.add(monitor); 028 } 029 030 /** 031 * logs certain action within a Request 032 * @param pc 033 * @param ar 034 * @throws IOException 035 */ 036 public void log(PageContext pc, String type, String label, long executionTime, Object data) { 037 if(monitors==null) return ; 038 039 Iterator<ActionMonitor> it = monitors.iterator(); 040 while(it.hasNext()){ 041 try { 042 it.next().log(pc, type, label, executionTime, data); 043 } catch (Throwable t) { 044 t.printStackTrace(); 045 } 046 } 047 } 048 public void log(ConfigWeb config, String type, String label, long executionTime, Object data) { 049 if(monitors==null) return ; 050 051 Iterator<ActionMonitor> it = monitors.iterator(); 052 while(it.hasNext()){ 053 try { 054 it.next().log(config, type, label, executionTime, data); 055 } catch (Throwable t) { 056 t.printStackTrace(); 057 } 058 } 059 } 060 061 @Override 062 public Object getActionMonitor(String name) { 063 Iterator<ActionMonitor> it = monitors.iterator(); 064 ActionMonitor am; 065 while(it.hasNext()){ 066 am = it.next(); 067 if(name.equalsIgnoreCase(am.getName())) return am; 068 } 069 return null; 070 } 071 072 }