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 2015/08/06 23:50:57 UTC
svn commit: r1694578 - in /turbine/fulcrum/trunk/yaafi: ./
src/java/org/apache/fulcrum/yaafi/framework/component/
src/java/org/apache/fulcrum/yaafi/framework/interceptor/
src/java/org/apache/fulcrum/yaafi/interceptor/jamon/
src/java/org/apache/fulcrum/...
Author: sgoeschl
Date: Thu Aug 6 21:50:57 2015
New Revision: 1694578
URL: http://svn.apache.org/r1694578
Log:
TRB-97 Integrate JavaSimon for performance monitoring
Added:
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimon4PerformanceMonitorImpl.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimonInterceptorService.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimonInterceptorServiceImpl.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimonPerformanceMonitor.java
Modified:
turbine/fulcrum/trunk/yaafi/pom.xml
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/component/ServiceComponentImpl.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/interceptor/AvalonInterceptorFactory.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/interceptor/AvalonInterceptorInvocationHandler.java
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/Jamon2PerformanceMonitorImpl.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/JamonInterceptorServiceImpl.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/JamonPerformanceMonitor.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/util/MethodToStringBuilderImpl.java
turbine/fulcrum/trunk/yaafi/src/test/TestComponentConfig.xml
turbine/fulcrum/trunk/yaafi/src/test/TestReconfigurationConfig.xml
turbine/fulcrum/trunk/yaafi/src/test/TestRoleConfig.xml
turbine/fulcrum/trunk/yaafi/src/test/TestYaafiContainerConfig.xml
turbine/fulcrum/trunk/yaafi/tutorial/conf/componentRoles.xml
Modified: turbine/fulcrum/trunk/yaafi/pom.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/pom.xml?rev=1694578&r1=1694577&r2=1694578&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/pom.xml (original)
+++ turbine/fulcrum/trunk/yaafi/pom.xml Thu Aug 6 21:50:57 2015
@@ -80,12 +80,23 @@
<optional>true</optional>
</dependency>
-->
- <!-- Interceptor dependencies -->
<dependency>
<groupId>com.jamonapi</groupId>
<artifactId>jamon</artifactId>
<version>2.81</version>
<optional>true</optional>
+ <exclusions>
+ <exclusion>
+ <groupId>com.hazelcast</groupId>
+ <artifactId>hazelcast-all</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.javasimon</groupId>
+ <artifactId>javasimon-core</artifactId>
+ <version>4.0.1</version>
+ <optional>true</optional>
</dependency>
<!-- Testing dependencies -->
<dependency>
Modified: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/component/ServiceComponentImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/component/ServiceComponentImpl.java?rev=1694578&r1=1694577&r2=1694578&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/component/ServiceComponentImpl.java (original)
+++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/component/ServiceComponentImpl.java Thu Aug 6 21:50:57 2015
@@ -303,7 +303,7 @@ public abstract class ServiceComponentIm
}
/**
- * @return Returns the paramaters.
+ * @return Returns the parameters.
*/
public Parameters getParamaters()
{
Modified: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/interceptor/AvalonInterceptorFactory.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/interceptor/AvalonInterceptorFactory.java?rev=1694578&r1=1694577&r2=1694578&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/interceptor/AvalonInterceptorFactory.java (original)
+++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/interceptor/AvalonInterceptorFactory.java Thu Aug 6 21:50:57 2015
@@ -63,13 +63,13 @@ public class AvalonInterceptorFactory
Validate.notNull(serviceInterceptorList,"serviceInterceptorList");
Validate.notNull(serviceDelegate,"serviceDelegate");
- Object result = null;
+ Object result;
Class clazz = serviceDelegate.getClass();
ClassLoader classLoader = clazz.getClassLoader();
List interfaceList = Clazz.getAllInterfaces(clazz);
- // get the service interfaces to avoid lookups
+ // get the service interfaces to avoid look-ups
AvalonInterceptorService[] avalonInterceptorServices = resolve(
serviceManager,
@@ -103,7 +103,7 @@ public class AvalonInterceptorFactory
private static AvalonInterceptorService[] resolve( ServiceManager serviceManager, String[] interceptorList )
throws ServiceException
{
- String interceptorServiceName = null;
+ String interceptorServiceName;
AvalonInterceptorService[] result = new AvalonInterceptorService[interceptorList.length];
for( int i=0; i<interceptorList.length; i++ )
Modified: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/interceptor/AvalonInterceptorInvocationHandler.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/interceptor/AvalonInterceptorInvocationHandler.java?rev=1694578&r1=1694577&r2=1694578&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/interceptor/AvalonInterceptorInvocationHandler.java (original)
+++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/interceptor/AvalonInterceptorInvocationHandler.java Thu Aug 6 21:50:57 2015
@@ -22,9 +22,10 @@ package org.apache.fulcrum.yaafi.framewo
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.concurrent.atomic.AtomicLong;
-import org.apache.fulcrum.yaafi.framework.util.Validate;
import org.apache.fulcrum.yaafi.framework.util.ToStringBuilder;
+import org.apache.fulcrum.yaafi.framework.util.Validate;
/**
* The InvocationHandler invoked when a service call is routed through
@@ -48,7 +49,7 @@ public class AvalonInterceptorInvocation
private AvalonInterceptorService [] serviceInterceptorList;
/** counts the current transactions */
- private static volatile long transactionCounter = 0L;
+ private static AtomicLong transactionCounter = new AtomicLong(0);
/** the current transaction id */
private Long transactionId;
@@ -139,7 +140,7 @@ public class AvalonInterceptorInvocation
public Object invoke(Object proxy, Method method, Object [] args)
throws Throwable
{
- Object result = null;
+ Object result;
// create the interceptor context for current method call
@@ -168,6 +169,11 @@ public class AvalonInterceptorInvocation
this.onError(context,e.getTargetException());
throw e.getTargetException();
}
+ catch (Throwable t)
+ {
+ this.onError(context,t);
+ throw t;
+ }
finally
{
// decrement the service invocation depth
@@ -192,7 +198,8 @@ public class AvalonInterceptorInvocation
{
for( int i=0; i<this.getServiceInterceptorList().length; i++ )
{
- this.getServiceInterceptorList()[i].onEntry(context);
+ AvalonInterceptorService avalonInterceptorService = this.getServiceInterceptorList()[i];
+ avalonInterceptorService.onEntry(context);
}
}
@@ -206,7 +213,8 @@ public class AvalonInterceptorInvocation
{
for( int i=this.getServiceInterceptorList().length-1; i>=0; i-- )
{
- this.getServiceInterceptorList()[i].onExit(context,result);
+ AvalonInterceptorService avalonInterceptorService = this.getServiceInterceptorList()[i];
+ avalonInterceptorService.onExit(context, result);
}
}
@@ -220,7 +228,8 @@ public class AvalonInterceptorInvocation
{
for( int i=this.getServiceInterceptorList().length-1; i>=0; i-- )
{
- this.getServiceInterceptorList()[i].onError(context,t);
+ AvalonInterceptorService avalonInterceptorService = this.getServiceInterceptorList()[i];
+ avalonInterceptorService.onError(context, t);
}
}
@@ -231,15 +240,14 @@ public class AvalonInterceptorInvocation
*/
private boolean createTransactionId(AvalonInterceptorContext context)
{
- Long currentTransactionId = null;
+ Long currentTransactionId;
- if( context.hasTransactionId() == false )
+ if( !context.hasTransactionId() )
{
// create a new transaction id
- currentTransactionId = new Long(
- ++AvalonInterceptorInvocationHandler.transactionCounter
- );
+ currentTransactionId = transactionCounter.incrementAndGet();
+ this.transactionId = currentTransactionId;
// store it in the TLS
Modified: 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=1694578&r1=1694577&r2=1694578&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/Jamon1PerformanceMonitorImpl.java (original)
+++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/Jamon1PerformanceMonitorImpl.java Thu Aug 6 21:50:57 2015
@@ -19,15 +19,16 @@ package org.apache.fulcrum.yaafi.interce
* under the License.
*/
+import java.lang.reflect.Method;
+
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
*
+ * @deprecated JAMon 1.x is ancient so it is a good idea to upgrade to 2.x
* @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
*/
Modified: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/Jamon2PerformanceMonitorImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/Jamon2PerformanceMonitorImpl.java?rev=1694578&r1=1694577&r2=1694578&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/Jamon2PerformanceMonitorImpl.java (original)
+++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/Jamon2PerformanceMonitorImpl.java Thu Aug 6 21:50:57 2015
@@ -19,15 +19,15 @@ package org.apache.fulcrum.yaafi.interce
* under the License.
*/
+import java.lang.reflect.Method;
+
import com.jamonapi.Monitor;
import com.jamonapi.MonitorFactory;
import com.jamonapi.RangeHolder;
import org.apache.fulcrum.yaafi.interceptor.util.MethodToStringBuilderImpl;
-import java.lang.reflect.Method;
-
/**
- * Ecapsulating the JAMon 2.x related API calls. JAMon 2.x allows for a much
+ * Encapsulating the JAMon 2.x related API calls. JAMon 2.x allows for a much
* more powerful integration with Avalon services :
* <ul>
* <li>custom ranges/units</li>
@@ -49,7 +49,7 @@ public class Jamon2PerformanceMonitorImp
/** is monitoring enabled */
private boolean isActive;
- /** the method currenty monitored */
+ /** the method currently monitored */
private Method method;
/** the global JAMON monitor */
@@ -120,7 +120,6 @@ public class Jamon2PerformanceMonitorImp
}
}
-
/**
* Create a performance report.
*
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=1694578&r1=1694577&r2=1694578&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 Thu Aug 6 21:50:57 2015
@@ -19,6 +19,11 @@ package org.apache.fulcrum.yaafi.interce
* 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;
@@ -29,11 +34,6 @@ import org.apache.fulcrum.yaafi.framewor
import org.apache.fulcrum.yaafi.framework.reflection.Clazz;
import org.apache.fulcrum.yaafi.interceptor.baseservice.BaseInterceptorServiceImpl;
-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
* relies on reflection to invoke JAMON to avoid compile-time coupling.
@@ -70,7 +70,7 @@ public class JamonInterceptorServiceImpl
private static final String MONITORFACTORY_CLASSNAME = "com.jamonapi.MonitorFactory";
/** the class name of the JAMon MonitorFactory */
- private static final String DEFAULT_PERFORMANCEMONITOR_CLASSNAME = "org.apache.fulcrum.yaafi.interceptor.jamon.Jamon1PerformanceMonitorImpl";
+ private static final String DEFAULT_PERFORMANCEMONITOR_CLASSNAME = "org.apache.fulcrum.yaafi.interceptor.jamon.Jamon2PerformanceMonitorImpl";
/////////////////////////////////////////////////////////////////////////
// Avalon Service Lifecycle Implementation
@@ -231,7 +231,7 @@ public class JamonInterceptorServiceImpl
/////////////////////////////////////////////////////////////////////////
/**
- * @return Returns the isJamonAvailable.
+ * @return Returns true if JAMon is availble.
*/
protected final boolean isJamonAvailable()
{
Modified: 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=1694578&r1=1694577&r2=1694578&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/JamonPerformanceMonitor.java (original)
+++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/jamon/JamonPerformanceMonitor.java Thu Aug 6 21:50:57 2015
@@ -28,21 +28,21 @@ package org.apache.fulcrum.yaafi.interce
public interface JamonPerformanceMonitor
{
/** Start the monitor. */
- public void start();
+ void start();
/** Stop the monitor. */
- public void stop();
+ void stop();
/**
* Stop the monitor based on an Throwable.
* @param throwable the throwable
*/
- public void stop(Throwable throwable);
+ void stop(Throwable throwable);
/**
* Create a performance report
* @return the textual performance report
* @throws Exception generating the report failed
*/
- public String createReport() throws Exception;
+ String createReport() throws Exception;
}
Added: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimon4PerformanceMonitorImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimon4PerformanceMonitorImpl.java?rev=1694578&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimon4PerformanceMonitorImpl.java (added)
+++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimon4PerformanceMonitorImpl.java Thu Aug 6 21:50:57 2015
@@ -0,0 +1,109 @@
+package org.apache.fulcrum.yaafi.interceptor.javasimon;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.lang.reflect.Method;
+
+import org.apache.fulcrum.yaafi.interceptor.util.MethodToStringBuilderImpl;
+import org.javasimon.SimonManager;
+import org.javasimon.Split;
+import org.javasimon.Stopwatch;
+
+/**
+ * Encapsulating the JAMon 2.x related API calls. JAMon 2.x allows for a much
+ * more powerful integration with Avalon services :
+ * <ul>
+ * <li>custom ranges/units</li>
+ * <li>exception monitoring</li>
+ * <li>smooth web interface</li>
+ * </ul>
+ *
+ * @since 1.0.7
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+
+public class JavaSimon4PerformanceMonitorImpl implements JavaSimonPerformanceMonitor
+{
+ /** is monitoring enabled */
+ private boolean isActive;
+
+ /** the method currently monitored */
+ private Method method;
+
+ /** the split for this invocation */
+ private Split split;
+
+ /**
+ * 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 JavaSimon4PerformanceMonitorImpl(String serviceName, Method method, Boolean isActive)
+ {
+ this.method = method;
+ this.isActive = isActive.booleanValue();
+ }
+
+ /**
+ * Start the monitor.
+ */
+ public void start()
+ {
+ if(this.isActive)
+ {
+ String methodSignature = createMethodSignature(this.method, 0);
+ Stopwatch stopwatch = SimonManager.getStopwatch(methodSignature);
+ this.split = stopwatch.start();
+ }
+ }
+
+ /**
+ * Stop the monitor
+ */
+ public void stop()
+ {
+ if(this.isActive)
+ {
+ this.split.stop();
+ }
+ }
+
+ /**
+ * Stop the monitor
+ */
+ public void stop(Throwable throwable)
+ {
+ if(this.isActive)
+ {
+ this.split.stop();
+ }
+ }
+
+ /**
+ * Create a method signature - JavaSimon does not look names with '#' in it.
+ */
+ private String createMethodSignature(Method method, int mode)
+ {
+ MethodToStringBuilderImpl methodToStringBuilder = new MethodToStringBuilderImpl(method, mode);
+ return methodToStringBuilder.toString().replace("#", "[]");
+ }
+}
Added: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimonInterceptorService.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimonInterceptorService.java?rev=1694578&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimonInterceptorService.java (added)
+++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimonInterceptorService.java Thu Aug 6 21:50:57 2015
@@ -0,0 +1,34 @@
+package org.apache.fulcrum.yaafi.interceptor.javasimon;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorService;
+
+/**
+ * A service using JavaSimon for performance monitoring
+ *
+ * @since 1.0.7
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+
+public interface JavaSimonInterceptorService extends AvalonInterceptorService, Runnable
+{
+ // This interface doesn't exposes any other methods
+}
Added: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimonInterceptorServiceImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimonInterceptorServiceImpl.java?rev=1694578&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimonInterceptorServiceImpl.java (added)
+++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimonInterceptorServiceImpl.java Thu Aug 6 21:50:57 2015
@@ -0,0 +1,326 @@
+package org.apache.fulcrum.yaafi.interceptor.javasimon;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * 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;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.Reconfigurable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorContext;
+import org.apache.fulcrum.yaafi.framework.reflection.Clazz;
+import org.apache.fulcrum.yaafi.interceptor.baseservice.BaseInterceptorServiceImpl;
+
+/**
+ * A service using JavaSimon for performance monitoring. The implementation
+ * relies on reflection to invoke JavaSimon to avoid compile-time coupling.
+ *
+ * @since 1.0.7
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+
+public class JavaSimonInterceptorServiceImpl
+ extends BaseInterceptorServiceImpl
+ implements JavaSimonInterceptorService, Reconfigurable, ThreadSafe, Disposable, Initializable
+{
+ /** are the JavaSimon classes in the classpath */
+ private boolean isJavaSimonAvailable;
+
+ /** the file to hold the report */
+ private File reportFile;
+
+ /** the time in ms between two reports */
+ private long reportTimeout;
+
+ /** do we create a report during disposal of the service */
+ private boolean reportOnExit;
+
+ /** the time when the next report is due */
+ private long nextReportTimestamp;
+
+ /** 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 JavaSimon factory */
+ private static final String MONITORFACTORY_CLASSNAME = "org.javasimon.SimonManager";
+
+ /** the class name of the JavaSimon MonitorFactory */
+ private static final String DEFAULT_PERFORMANCEMONITOR_CLASSNAME = "org.apache.fulcrum.yaafi.interceptor.javasimon.JavaSimon4PerformanceMonitorImpl";
+
+ /////////////////////////////////////////////////////////////////////////
+ // Avalon Service Lifecycle Implementation
+ /////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Constructor
+ */
+ public JavaSimonInterceptorServiceImpl()
+ {
+ super();
+ }
+
+ /**
+ * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
+ */
+ public void configure(Configuration configuration) throws ConfigurationException
+ {
+ super.configure(configuration);
+ this.reportTimeout = configuration.getChild("reportTimeout").getValueAsLong(0);
+
+ // parse the performance monitor class name
+ this.performanceMonitorClassName = configuration.getChild("performanceMonitorClassName").getValue(DEFAULT_PERFORMANCEMONITOR_CLASSNAME);
+
+ // parse the report file name
+ String reportFileName = configuration.getChild("reportFile").getValue("./javasimon.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);
+ }
+
+ /**
+ * @see Initializable#initialize()
+ */
+ public void initialize() throws Exception
+ {
+ ClassLoader classLoader = this.getClassLoader();
+
+ if (!Clazz.hasClazz(classLoader, MONITORFACTORY_CLASSNAME))
+ {
+ String msg = "The JavaSimonInterceptorService is disabled since the JavaSimon classes are not found in the classpath";
+ this.getLogger().warn(msg);
+ this.isJavaSimonAvailable = false;
+ return;
+ }
+
+ if (!Clazz.hasClazz(classLoader, this.performanceMonitorClassName))
+ {
+ String msg = "The JavaSimonInterceptorService is disabled since the performance monitor class is not found in the classpath";
+ this.getLogger().warn(msg);
+ this.isJavaSimonAvailable = 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
+ JavaSimonPerformanceMonitor testMonitor = this.createJavaSimonPerformanceMonitor(null, null, true);
+ if(testMonitor == null)
+ {
+ String msg = "The JavaSimonInterceptorService is disabled since the performance monitor can't be instantiated";
+ this.getLogger().warn(msg);
+ this.isJavaSimonAvailable = false;
+ return;
+ }
+
+ this.getLogger().debug("The JavaSimonInterceptorService is enabled");
+ this.isJavaSimonAvailable = true;
+ }
+
+ /**
+ * @see Reconfigurable#reconfigure(Configuration)
+ */
+ public void reconfigure(Configuration configuration) throws ConfigurationException
+ {
+ super.reconfigure(configuration);
+ this.configure(configuration);
+ }
+
+ /**
+ * @see Disposable#dispose()
+ */
+ public void dispose()
+ {
+ if( this.reportOnExit )
+ {
+ this.run();
+ }
+
+ this.reportFile = null;
+ }
+
+ /////////////////////////////////////////////////////////////////////////
+ // Service interface implementation
+ /////////////////////////////////////////////////////////////////////////
+
+ /**
+ * @see org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorService#onEntry(AvalonInterceptorContext)
+ */
+ @SuppressWarnings("unchecked")
+ public void onEntry(AvalonInterceptorContext interceptorContext)
+ {
+ if( this.isJavaSimonAvailable() )
+ {
+ this.writeReport();
+
+ String serviceShortHand = interceptorContext.getServiceShorthand();
+ Method serviceMethod = interceptorContext.getMethod();
+ boolean isEnabled = this.isServiceMonitored(interceptorContext );
+ JavaSimonPerformanceMonitor monitor = this.createJavaSimonPerformanceMonitor(serviceShortHand, serviceMethod, isEnabled);
+ monitor.start();
+ interceptorContext.getRequestContext().put(this.getServiceName(), monitor);
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorService#onExit(AvalonInterceptorContext, Object)
+ */
+ public void onExit(AvalonInterceptorContext interceptorContext, Object result)
+ {
+ if( this.isJavaSimonAvailable() )
+ {
+ JavaSimonPerformanceMonitor monitor;
+ monitor = (JavaSimonPerformanceMonitor) interceptorContext.getRequestContext().remove(this.getServiceName());
+ monitor.stop();
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorService#onError(AvalonInterceptorContext, Throwable)
+ */
+ public void onError(AvalonInterceptorContext interceptorContext,Throwable t)
+ {
+ if( this.isJavaSimonAvailable() )
+ {
+ JavaSimonPerformanceMonitor monitor;
+ monitor = (JavaSimonPerformanceMonitor) interceptorContext.getRequestContext().remove(this.getServiceName());
+ monitor.stop(t);
+ }
+ }
+
+ /**
+ * Writes the JavaSimon report to the file system.
+ *
+ * @see Runnable#run()
+ */
+ public void run()
+ {
+ this.writeReport(this.reportFile);
+ }
+
+ /////////////////////////////////////////////////////////////////////////
+ // Service Implementation
+ /////////////////////////////////////////////////////////////////////////
+
+ /**
+ * @return Returns the isJavaSimonAvailable.
+ */
+ protected final boolean isJavaSimonAvailable()
+ {
+ return this.isJavaSimonAvailable;
+ }
+
+ /**
+ * Factory method for creating an implementation of a JavaSimonPerformanceMonitor.
+ *
+ * @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 JavaSimonPerformanceMonitor createJavaSimonPerformanceMonitor(String serviceName, Method method, boolean isEnabled)
+ {
+ JavaSimonPerformanceMonitor result = null;
+
+ try
+ {
+ Class[] signature = { String.class, Method.class, Boolean.class };
+ Object[] args = { serviceName, method, (isEnabled) ? Boolean.TRUE : Boolean.FALSE};
+ result = (JavaSimonPerformanceMonitor) Clazz.newInstance(this.performanceMonitorClass, signature, args);
+ }
+ catch(Exception e)
+ {
+ String msg = "Failed to create a performance monitor instance : " + this.performanceMonitorClassName;
+ this.getLogger().error(msg, e);
+ }
+
+ return result;
+ }
+
+ /**
+ * Write a report file
+ */
+ protected void writeReport()
+ {
+ if( this.reportTimeout > 0 )
+ {
+ long currTimestamp = System.currentTimeMillis();
+
+ if( currTimestamp > this.nextReportTimestamp )
+ {
+ this.nextReportTimestamp = currTimestamp + this.reportTimeout;
+ this.writeReport(this.reportFile);
+ }
+ }
+ }
+
+ /**
+ * Write the HTML report to the given destination.
+ *
+ * @param reportFile the report destination
+ */
+ protected void writeReport( File reportFile )
+ {
+ PrintWriter printWriter = null;
+
+ if( this.isJavaSimonAvailable() )
+ {
+ try
+ {
+ if( this.getLogger().isDebugEnabled() )
+ {
+ this.getLogger().debug( "Writing JavaSimon report to " + reportFile.getAbsolutePath() );
+ }
+
+ FileOutputStream fos = new FileOutputStream( reportFile );
+ printWriter = new PrintWriter( fos );
+ // JavaSimonPerformanceMonitor monitor = this.createJavaSimonPerformanceMonitor(null, null, true);
+ String report = "Not implemented yet ...";
+ printWriter.write( report );
+ printWriter.close();
+ }
+ catch( Throwable t )
+ {
+ String msg = "Generating the JavaSimon report failed for " + reportFile.getAbsolutePath();
+ this.getLogger().error(msg,t);
+ }
+ finally
+ {
+ if( printWriter != null )
+ {
+ printWriter.close();
+ }
+ }
+ }
+ }
+}
Added: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimonPerformanceMonitor.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimonPerformanceMonitor.java?rev=1694578&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimonPerformanceMonitor.java (added)
+++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/javasimon/JavaSimonPerformanceMonitor.java Thu Aug 6 21:50:57 2015
@@ -0,0 +1,42 @@
+package org.apache.fulcrum.yaafi.interceptor.javasimon;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Expose the start()/stop() methods for performance monitors independent from their concrete
+ * implementation.
+ *
+ * @since 1.0.7
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+
+public interface JavaSimonPerformanceMonitor
+{
+ /** Start the monitor. */
+ void start();
+
+ /** Stop the monitor. */
+ void stop();
+
+ /**
+ * Stop the monitor based on an Throwable.
+ * @param throwable the throwable
+ */
+ void stop(Throwable throwable);
+}
Modified: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/util/MethodToStringBuilderImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/util/MethodToStringBuilderImpl.java?rev=1694578&r1=1694577&r2=1694578&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/util/MethodToStringBuilderImpl.java (original)
+++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/util/MethodToStringBuilderImpl.java Thu Aug 6 21:50:57 2015
@@ -21,8 +21,6 @@ package org.apache.fulcrum.yaafi.interce
import java.lang.reflect.Method;
-import org.apache.fulcrum.yaafi.framework.util.StringUtils;
-
/**
* Creates a string representation of java.lang.reflect.Method
*
@@ -107,7 +105,7 @@ public class MethodToStringBuilderImpl i
{
try
{
- StringBuffer buffer = new StringBuffer(BUF_SIZE);
+ StringBuilder buffer = new StringBuilder(BUF_SIZE);
Class returnType = method.getReturnType();
Class declaringClass = method.getDeclaringClass();
@@ -117,13 +115,13 @@ public class MethodToStringBuilderImpl i
if ((this.mode & INCLUDE_RETURNTYPE) == 1)
{
- buffer.append( this.stripDefaultPackage(returnType.getName()));
+ buffer.append( returnType.getSimpleName() );
buffer.append( ' ');
}
// print class and method
- buffer.append( this.stripDefaultPackage(declaringClass.getName()));
+ buffer.append( declaringClass.getSimpleName() ) ;
buffer.append( '.');
buffer.append( method.getName() );
buffer.append( '(');
@@ -132,7 +130,7 @@ public class MethodToStringBuilderImpl i
for (int i = 0; i < params.length; i++)
{
- buffer.append( this.stripDefaultPackage(params[i].getName()) );
+ buffer.append( params[i].getSimpleName() );
if (i < (params.length - 1))
{
buffer.append(",");
@@ -145,23 +143,7 @@ public class MethodToStringBuilderImpl i
}
catch (Throwable t)
{
- return "<" + t + ">";
- }
- }
-
- /**
- * Strips "java.lang" from the argument other than arrays
- */
- private String stripDefaultPackage( String arg )
- {
- if( arg.charAt(0) == '[' )
- {
- // this is an array
- return StringUtils.replaceChars(arg,';','#');
- }
- else
- {
- return StringUtils.replace( arg, "java.lang.", "");
+ return "<" + t.getClass().getSimpleName() + ">";
}
}
}
Modified: turbine/fulcrum/trunk/yaafi/src/test/TestComponentConfig.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/TestComponentConfig.xml?rev=1694578&r1=1694577&r2=1694578&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/test/TestComponentConfig.xml (original)
+++ turbine/fulcrum/trunk/yaafi/src/test/TestComponentConfig.xml Thu Aug 6 21:50:57 2015
@@ -81,7 +81,7 @@
<JamonInterceptorService>
<isEnabled>true</isEnabled>
- <performanceMonitorClassName>org.apache.fulcrum.yaafi.interceptor.jamon.Jamon1PerformanceMonitorImpl</performanceMonitorClassName>
+ <performanceMonitorClassName>org.apache.fulcrum.yaafi.interceptor.jamon.Jamon2PerformanceMonitorImpl</performanceMonitorClassName>
<reportTimeout>60000</reportTimeout>
<reportFile>./target/jamon.html</reportFile>
<reportOnExit>true</reportOnExit>
@@ -91,6 +91,29 @@
</JamonInterceptorService>
<!--
+ JavaSimonInterceptorSerivce
+
+ isEnabled := is the interceptor enabled
+ performanceMonitorClassName := the performance monitor implementation to interact with JAMon
+ reportTimeout := the timeout between generating a JAMON report (No report = 0)
+ reportFile := the file for the JAMON report
+ reportOnExit := create a HTML report on disposal
+ services := the list of services being monitored
+ services/service@name := the name of the service being monitored
+ -->
+
+ <JavaSimonInterceptorSerivce>
+ <isEnabled>true</isEnabled>
+ <performanceMonitorClassName>org.apache.fulcrum.yaafi.interceptor.javasimon.JavaSimonInterceptorServiceImpl</performanceMonitorClassName>
+ <reportTimeout>60000</reportTimeout>
+ <reportFile>./target/javasimon.html</reportFile>
+ <reportOnExit>true</reportOnExit>
+ <services>
+ <service name="*"/>
+ </services>
+ </JavaSimonInterceptorSerivce>
+
+ <!--
AdviceService
interceptors := the list of interceptors for an advised object
Modified: turbine/fulcrum/trunk/yaafi/src/test/TestReconfigurationConfig.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/TestReconfigurationConfig.xml?rev=1694578&r1=1694577&r2=1694578&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/test/TestReconfigurationConfig.xml (original)
+++ turbine/fulcrum/trunk/yaafi/src/test/TestReconfigurationConfig.xml Thu Aug 6 21:50:57 2015
@@ -34,4 +34,4 @@
</entry>
</ReconfigurationService>
-</componentConfig>
+</componentConfig>
\ No newline at end of file
Modified: turbine/fulcrum/trunk/yaafi/src/test/TestRoleConfig.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/TestRoleConfig.xml?rev=1694578&r1=1694577&r2=1694578&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/test/TestRoleConfig.xml (original)
+++ turbine/fulcrum/trunk/yaafi/src/test/TestRoleConfig.xml Thu Aug 6 21:50:57 2015
@@ -37,6 +37,11 @@
shorthand="JamonInterceptorService"
default-class="org.apache.fulcrum.yaafi.interceptor.jamon.JamonInterceptorServiceImpl"
/>
+ <role
+ name="org.apache.fulcrum.yaafi.interceptor.javasimon.JavaSimonInterceptorService"
+ shorthand="JavaSimonInterceptorService"
+ default-class="org.apache.fulcrum.yaafi.interceptor.javasimon.JavaSimonInterceptorServiceImpl"
+ />
<!-- Use minimal role entry -->
<role
name="org.apache.fulcrum.yaafi.service.servicemanager.ServiceManagerService"
@@ -98,4 +103,4 @@
early-init="false"
description="A simple service deriving from BaseService"
/>
-</role-list>
+</role-list>
\ No newline at end of file
Modified: turbine/fulcrum/trunk/yaafi/src/test/TestYaafiContainerConfig.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/TestYaafiContainerConfig.xml?rev=1694578&r1=1694577&r2=1694578&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/src/test/TestYaafiContainerConfig.xml (original)
+++ turbine/fulcrum/trunk/yaafi/src/test/TestYaafiContainerConfig.xml Thu Aug 6 21:50:57 2015
@@ -36,6 +36,7 @@
</parameters>
<interceptors>
<interceptor>org.apache.fulcrum.yaafi.interceptor.jamon.JamonInterceptorService</interceptor>
+ <interceptor>org.apache.fulcrum.yaafi.interceptor.javasimon.JavaSimonInterceptorService</interceptor>
<interceptor>org.apache.fulcrum.yaafi.interceptor.performance.PerformanceInterceptorService</interceptor>
<interceptor>org.apache.fulcrum.yaafi.interceptor.logging.LoggingInterceptorService</interceptor>
</interceptors>
Modified: turbine/fulcrum/trunk/yaafi/tutorial/conf/componentRoles.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/tutorial/conf/componentRoles.xml?rev=1694578&r1=1694577&r2=1694578&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/tutorial/conf/componentRoles.xml (original)
+++ turbine/fulcrum/trunk/yaafi/tutorial/conf/componentRoles.xml Thu Aug 6 21:50:57 2015
@@ -24,4 +24,4 @@
shorthand="SystemPropertyService"
default-class="tutorial.service.SystemPropertyServiceImpl"
/>
-</role-list>
+</role-list>
\ No newline at end of file