You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by sg...@apache.org on 2007/09/09 19:13:40 UTC
svn commit: r574030 - in /turbine/fulcrum/trunk/yaafi:
src/java/org/apache/fulcrum/yaafi/interceptor/jamon/ xdocs/
xdocs/interceptors/
Author: sgoeschl
Date: Sun Sep 9 10:13:35 2007
New Revision: 574030
URL: http://svn.apache.org/viewvc?rev=574030&view=rev
Log:
First cut of fixing the JAMon 2.x interop prolems - the implementation works for JAMon 1.x but for 2.x I want to have a better integration.
Added:
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/Jamon1PerformanceMonitorImpl.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/JamonPerformanceMonitor.java
Modified:
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/JamonInterceptorServiceImpl.java
turbine/fulcrum/trunk/yaafi/xdocs/changes.xml
turbine/fulcrum/trunk/yaafi/xdocs/interceptors/jamoninterceptor.xml
Added: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/Jamon1PerformanceMonitorImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/Jamon1PerformanceMonitorImpl.java?rev=574030&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/Jamon1PerformanceMonitorImpl.java (added)
+++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/Jamon1PerformanceMonitorImpl.java Sun Sep 9 10:13:35 2007
@@ -0,0 +1,76 @@
+package org.apache.fulcrum.yaafi.interceptor.jamon;
+
+import com.jamonapi.Monitor;
+import com.jamonapi.MonitorFactory;
+import org.apache.fulcrum.yaafi.interceptor.util.MethodToStringBuilderImpl;
+
+import java.lang.reflect.Method;
+
+/**
+ * Ecapsulating the JAMon 1.x related API calls
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+
+public class Jamon1PerformanceMonitorImpl implements JamonPerformanceMonitor
+{
+ /** is monitoring enabled */
+ private boolean isActive;
+
+ /** the method currenty monitored */
+ private Method method;
+
+ /** the global JAMON monitor */
+ private Monitor monitor;
+
+ /**
+ * Constructor.
+ *
+ * @param serviceName the service name of the service being monitored
+ * @param method the method to be monitored
+ * @param isActive is this an active monitor
+ */
+ public Jamon1PerformanceMonitorImpl(String serviceName, Method method, Boolean isActive) {
+ this.method = method;
+ this.isActive = isActive.booleanValue();
+ }
+
+ /**
+ * Start the monitor.
+ */
+ public void start()
+ {
+ if(this.isActive)
+ {
+ MethodToStringBuilderImpl methodToStringBuilder = new MethodToStringBuilderImpl(this.method, 0);
+ String methodSignature = methodToStringBuilder.toString();
+ this.monitor = MonitorFactory.start(methodSignature);
+ }
+ }
+
+ /**
+ * Start the monitor.
+ */
+ public void stop()
+ {
+ if(this.isActive)
+ {
+ this.monitor.stop();
+ }
+ }
+
+ /**
+ * Stop the monitor based on an Throwable.
+ */
+ public void stop(Throwable throwable)
+ {
+ this.stop();
+ }
+
+ /**
+ * Create a performance report
+ */
+ public String createReport() {
+ return MonitorFactory.getRootMonitor().getReport();
+ }
+}
Modified: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/JamonInterceptorServiceImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/JamonInterceptorServiceImpl.java?rev=574030&r1=574029&r2=574030&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/JamonInterceptorServiceImpl.java (original)
+++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/JamonInterceptorServiceImpl.java Sun Sep 9 10:13:35 2007
@@ -19,11 +19,6 @@
* under the License.
*/
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.PrintWriter;
-import java.lang.reflect.Method;
-
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configuration;
@@ -33,7 +28,11 @@
import org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorContext;
import org.apache.fulcrum.yaafi.framework.reflection.Clazz;
import org.apache.fulcrum.yaafi.interceptor.baseservice.BaseInterceptorServiceImpl;
-import org.apache.fulcrum.yaafi.interceptor.util.MethodToStringBuilderImpl;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.PrintWriter;
+import java.lang.reflect.Method;
/**
* A service using JAMon for performance monitoring. The implementation
@@ -61,11 +60,17 @@
/** the time when the next report is due */
private long nextReportTimestamp;
- /** the class for JAMon MonitorFactory */
- private Class monitorFactoryClass;
+ /** the implementation class name for the performance monitor */
+ private String performanceMonitorClassName;
+
+ /** the implementation class name for the performance monitor */
+ private Class performanceMonitorClass;
+
+ /** the class name of the JAMon MonitorFactory */
+ private static final String MONITORFACTORY_CLASSNAME = "com.jamonapi.MonitorFactory";
/** the class name of the JAMon MonitorFactory */
- private static final String MONITORFACTOTY_CLASSNAME = "com.jamonapi.MonitorFactory";
+ private static final String DEFAULT_PERFORMANCEMONITOR_CLASSNAME = "org.apache.fulcrum.yaafi.interceptor.jamon.Jamon1PerformanceMonitorImpl";
/////////////////////////////////////////////////////////////////////////
// Avalon Service Lifecycle Implementation
@@ -84,22 +89,20 @@
*/
public void configure(Configuration configuration) throws ConfigurationException
{
- String reportFileName = null;
-
super.configure(configuration);
this.reportTimeout = configuration.getChild("reportTimeout").getValueAsLong(0);
- // parse the report file name
+ // parse the performance monitor class name
+ this.performanceMonitorClassName = configuration.getChild("performanceMonitorClassName").getValue(DEFAULT_PERFORMANCEMONITOR_CLASSNAME);
- reportFileName = configuration.getChild("reportFile").getValue("./jamon.html");
+ // parse the report file name
+ String reportFileName = configuration.getChild("reportFile").getValue("./jamon.html");
this.reportFile = this.makeAbsoluteFile( reportFileName );
// determine when to create the next report
-
this.nextReportTimestamp = System.currentTimeMillis() + this.reportTimeout;
// do we create a report on disposal
-
this.reportOnExit = configuration.getChild("reportOnExit").getValueAsBoolean(false);
}
@@ -110,21 +113,37 @@
{
ClassLoader classLoader = this.getClassLoader();
- if (Clazz.hasClazz(classLoader, MONITORFACTOTY_CLASSNAME))
+ if (!Clazz.hasClazz(classLoader, MONITORFACTORY_CLASSNAME))
{
- this.monitorFactoryClass = Clazz.getClazz(
- classLoader,
- MONITORFACTOTY_CLASSNAME
- );
-
- this.isJamonAvailable = true;
+ String msg = "The JamonInterceptorService is disabled since the JAMON classes are not found in the classpath";
+ this.getLogger().warn(msg);
+ this.isJamonAvailable = false;
+ return;
}
- else
+
+ if (!Clazz.hasClazz(classLoader, this.performanceMonitorClassName))
{
- String msg = "The JamonInterceptorService is disabled since the JAMON classes are not found in the classpath";
+ String msg = "The JamonInterceptorService is disabled since the performance monitor class is not found in the classpath";
this.getLogger().warn(msg);
this.isJamonAvailable = false;
+ return;
}
+
+ // load the performance monitor class
+ this.performanceMonitorClass = Clazz.getClazz(this.getClassLoader(), this.performanceMonitorClassName);
+
+ // check if we can create an instance of the performance monitor class
+ JamonPerformanceMonitor testMonitor = this.createJamonPerformanceMonitor(null, null, true);
+ if(testMonitor == null)
+ {
+ String msg = "The JamonInterceptorService is disabled since the performance monitor can't be instantiated";
+ this.getLogger().warn(msg);
+ this.isJamonAvailable = false;
+ return;
+ }
+
+ this.getLogger().debug("The JamonInterceptorService is enabled");
+ this.isJamonAvailable = true;
}
/**
@@ -143,11 +162,9 @@
{
if( this.reportOnExit )
{
- this.getLogger().debug( "Creating JAMOM report ..." );
this.run();
}
- this.monitorFactoryClass = null;
this.reportFile = null;
}
@@ -160,35 +177,42 @@
*/
public void onEntry(AvalonInterceptorContext interceptorContext)
{
- this.writeReport();
-
- if( this.isJamonAvailable() && this.isServiceMonitored(interceptorContext ) )
+ if( this.isJamonAvailable() )
{
- this.createMonitor(interceptorContext);
+ this.writeReport();
+
+ String serviceShortHand = interceptorContext.getServiceShorthand();
+ Method serviceMethod = interceptorContext.getMethod();
+ boolean isEnabled = this.isServiceMonitored(interceptorContext );
+ JamonPerformanceMonitor monitor = this.createJamonPerformanceMonitor(serviceShortHand, serviceMethod, isEnabled);
+ monitor.start();
+ interceptorContext.getRequestContext().put(this.getServiceName(), monitor);
}
}
/**
- * @see org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorService#onError(org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorContext, java.lang.Throwable)
+ * @see org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorService#onExit(org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorContext, java.lang.Object)
*/
- public void onError(AvalonInterceptorContext interceptorContext,Throwable t)
+ public void onExit(AvalonInterceptorContext interceptorContext, Object result)
{
- if( this.isJamonAvailable() && this.isServiceMonitored(interceptorContext) )
+ if( this.isJamonAvailable() )
{
- Object monitor = this.getMonitor(interceptorContext);
- this.stopMonitor(monitor);
+ JamonPerformanceMonitor monitor;
+ monitor = (JamonPerformanceMonitor) interceptorContext.getRequestContext().remove(this.getServiceName());
+ monitor.stop();
}
}
/**
- * @see org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorService#onExit(org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorContext, java.lang.Object)
+ * @see org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorService#onError(org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorContext, java.lang.Throwable)
*/
- public void onExit(AvalonInterceptorContext interceptorContext, Object result)
+ public void onError(AvalonInterceptorContext interceptorContext,Throwable t)
{
- if( this.isJamonAvailable() && this.isServiceMonitored(interceptorContext) )
+ if( this.isJamonAvailable() )
{
- Object monitor = this.getMonitor(interceptorContext);
- this.stopMonitor(monitor);
+ JamonPerformanceMonitor monitor;
+ monitor = (JamonPerformanceMonitor) interceptorContext.getRequestContext().remove(this.getServiceName());
+ monitor.stop(t);
}
}
@@ -209,38 +233,36 @@
/**
* @return Returns the isJamonAvailable.
*/
- protected boolean isJamonAvailable()
+ protected final boolean isJamonAvailable()
{
return this.isJamonAvailable;
}
/**
- * Creates a JAMON monitor
+ * Factory method for creating an implementation of a JamonPerformanceMonitor.
*
- * @param interceptorContext the current interceptor context
+ * @param serviceName the service name
+ * @param method the method
+ * @param isEnabled is the monitor enabled
+ * @return the instance or <b>null</b> if the creation failed
*/
- protected void createMonitor(
- AvalonInterceptorContext interceptorContext )
+ protected JamonPerformanceMonitor createJamonPerformanceMonitor(String serviceName, Method method, boolean isEnabled)
{
- Method method = interceptorContext.getMethod();
- MethodToStringBuilderImpl methodToStringBuilder = new MethodToStringBuilderImpl(method,0);
- String monitorCategory = methodToStringBuilder.toString();
- Object monitor = this.createMonitor(monitorCategory);
- interceptorContext.getRequestContext().put(this.getServiceName(),monitor);
- }
+ JamonPerformanceMonitor result = null;
- /**
- * Gets the JAMON Monitor
- *
- * @param interceptorContext the current interceptor context
- * @return the monitor
- */
- protected Object getMonitor(
- AvalonInterceptorContext interceptorContext )
- {
- return interceptorContext.getRequestContext().remove(
- this.getServiceName()
- );
+ try
+ {
+ Class[] signature = { String.class, Method.class, Boolean.class };
+ Object[] args = { serviceName, method, (isEnabled) ? Boolean.TRUE : Boolean.FALSE};
+ result = (JamonPerformanceMonitor) Clazz.newInstance(this.performanceMonitorClass, signature, args);
+ return result;
+ }
+ catch(Exception e)
+ {
+ String msg = "Failed to create a performance monitor instance : " + this.performanceMonitorClassName;
+ this.getLogger().error(msg, e);
+ return result;
+ }
}
/**
@@ -267,11 +289,10 @@
*/
protected void writeReport( File reportFile )
{
+ PrintWriter printWriter = null;
+
if( this.isJamonAvailable() )
{
- PrintWriter printWriter = null;
- String report = null;
-
try
{
if( this.getLogger().isDebugEnabled() )
@@ -281,7 +302,8 @@
FileOutputStream fos = new FileOutputStream( reportFile );
printWriter = new PrintWriter( fos );
- report = this.createReport();
+ JamonPerformanceMonitor monitor = this.createJamonPerformanceMonitor(null, null, true);
+ String report = monitor.createReport();
printWriter.write( report );
printWriter.close();
}
@@ -295,90 +317,8 @@
if( printWriter != null )
{
printWriter.close();
- printWriter = null;
}
}
}
- }
-
- /**
- * Creates a JAMON monitor for the category name.
- *
- * @param category the category name
- * @return the monitor
- */
- private Object createMonitor(String category)
- {
- Object result = null;
- String methodName = "start";
- Class[] signature = { String.class };
- Object[] args = { category };
-
- // invoke MonitorFactory.start(String);
-
- try
- {
- result = Clazz.invoke( this.monitorFactoryClass, methodName, signature, args );
- }
- catch (Exception e)
- {
- String msg = "Invoking com.jamonapi.MonitorFactory.start() failed";
- this.getLogger().error( msg, e );
- }
-
- return result;
- }
-
- /**
- * Stop the JAMON monitor.
- *
- * @param monitor the monitor to be stopped
- */
- private void stopMonitor( Object monitor )
- {
- String methodName = "stop";
- Class[] signature = {};
- Object[] args = {};
-
- // invoke MonitorFactory.start(String);
-
- try
- {
- Clazz.invoke(monitor, methodName, signature, args);
- }
- catch (Throwable t)
- {
- String msg = "Invoking com.jamonapi.MonitorFactory.start() failed";
- this.getLogger().error(msg,t);
- }
- }
-
- /**
- * Create a JAMON report.
- *
- * @return the report
- */
- private String createReport()
- {
- String result = null;
- Object rootMonitor = null;
- Class[] signature = {};
- Object[] args = {};
-
- try
- {
- // invoke MonitorFactory.getRootMonitor().getReport()
-
- rootMonitor = Clazz.invoke(this.monitorFactoryClass, "getRootMonitor", signature, args);
- result = (String) Clazz.invoke(rootMonitor, "getReport", signature, args);
- }
- catch (Throwable t)
- {
- String msg = "Invoking com.jamonapi.MonitorFactory.getRootMonitor().getReport()() failed";
- this.getLogger().error(msg,t);
- result = "<" + t + ">";
- }
-
- return result;
}
}
Added: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/JamonPerformanceMonitor.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/JamonPerformanceMonitor.java?rev=574030&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/JamonPerformanceMonitor.java (added)
+++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/JamonPerformanceMonitor.java Sun Sep 9 10:13:35 2007
@@ -0,0 +1,29 @@
+package org.apache.fulcrum.yaafi.interceptor.jamon;
+
+/**
+ * Expose the start()/stop() methods for performance monitors independent from their concrete
+ * implementation.
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+
+public interface JamonPerformanceMonitor
+{
+ /** Start the monitor. */
+ public void start();
+
+ /** Stop the monitor. */
+ public void stop();
+
+ /**
+ * Stop the monitor based on an Throwable.
+ * @param throwable the throwable
+ */
+ public void stop(Throwable throwable);
+
+ /**
+ * Create a performance report
+ * @return the textual performance report
+ */
+ public String createReport();
+}
Modified: turbine/fulcrum/trunk/yaafi/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/xdocs/changes.xml?rev=574030&r1=574029&r2=574030&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/xdocs/changes.xml (original)
+++ turbine/fulcrum/trunk/yaafi/xdocs/changes.xml Sun Sep 9 10:13:35 2007
@@ -25,10 +25,14 @@
<body>
<release version="1.0.5-dev" date="as in SVN">
+ <action dev="sgoeschl" type="fix">
+ Fixing broken JAMon 2.x integration. To decouple the service framework
+ from the JAMon library reflection was used but broke with JAMon 2.x.
+ </action>
<action dev="sgoeschl" type="add">
Added componentConfiguration.properties to resolve custom properties
- used for expanding the componentConfiguration.xml. Furthermore added
- a resolver functionality to allow to use commons-configuration.
+ used for expanding the componentConfiguration.xml. Furthermore added
+ a resolver functionality to allow to use commons-configuration.
</action>
<action dev="sgoeschl" type="add">
Added JamonInterceptorService to capture statistical performance data
Modified: turbine/fulcrum/trunk/yaafi/xdocs/interceptors/jamoninterceptor.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/xdocs/interceptors/jamoninterceptor.xml?rev=574030&r1=574029&r2=574030&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/xdocs/interceptors/jamoninterceptor.xml (original)
+++ turbine/fulcrum/trunk/yaafi/xdocs/interceptors/jamoninterceptor.xml Sun Sep 9 10:13:35 2007
@@ -51,11 +51,19 @@
invocations. </td>
</tr>
<tr>
+ <td>performanceMonitorClassName</td>
+ <td>String</td>
+ <td>[0|1]</td>
+ <td> The implementation class doing the JAMon API calls. If no value is supplied then
+ "org.apache.fulcrum.yaafi.interceptor.jamon.Jamon1PerformanceMonitorImpl" providing
+ out of the box JAMon 1.x and 2.x integration</td>
+ </tr>
+ <tr>
<td>reportTimeout</td>
<td>Long</td>
<td>[0|1]</td>
<td> The report timeout to generate a HTML report. If the value "0" is used than no periodic reports are
- generated. If no value is supplied than "0" is used. </td>
+ generated. If no value is supplied then "0" is used. </td>
</tr>
<tr>
<td>reportFile</td>