[exo-jcr-commits] exo-jcr SVN: r2269 - in jcr/trunk: exo.jcr.component.statistics and 11 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Apr 13 03:42:50 EDT 2010


Author: nfilotto
Date: 2010-04-13 03:42:49 -0400 (Tue, 13 Apr 2010)
New Revision: 2269

Added:
   jcr/trunk/exo.jcr.component.statistics/
   jcr/trunk/exo.jcr.component.statistics/pom.xml
   jcr/trunk/exo.jcr.component.statistics/src/
   jcr/trunk/exo.jcr.component.statistics/src/main/
   jcr/trunk/exo.jcr.component.statistics/src/main/java/
   jcr/trunk/exo.jcr.component.statistics/src/main/java/org/
   jcr/trunk/exo.jcr.component.statistics/src/main/java/org/exoplatform/
   jcr/trunk/exo.jcr.component.statistics/src/main/java/org/exoplatform/services/
   jcr/trunk/exo.jcr.component.statistics/src/main/java/org/exoplatform/services/jcr/
   jcr/trunk/exo.jcr.component.statistics/src/main/java/org/exoplatform/services/jcr/statistics/
   jcr/trunk/exo.jcr.component.statistics/src/main/java/org/exoplatform/services/jcr/statistics/JCRAPIAspect.java
   jcr/trunk/exo.jcr.component.statistics/src/main/java/org/exoplatform/services/jcr/statistics/JCRAPIAspectConfig.java
   jcr/trunk/exo.jcr.component.statistics/src/main/resources/
   jcr/trunk/exo.jcr.component.statistics/src/main/resources/META-INF/
   jcr/trunk/exo.jcr.component.statistics/src/main/resources/META-INF/aop.xml
   jcr/trunk/exo.jcr.component.statistics/src/main/resources/conf/
   jcr/trunk/exo.jcr.component.statistics/src/main/resources/conf/configuration.xml
Modified:
   jcr/trunk/pom.xml
Log:
EXOJCR-611: Implementation based on the Load-time Weaving from AspectJ

Added: jcr/trunk/exo.jcr.component.statistics/pom.xml
===================================================================
--- jcr/trunk/exo.jcr.component.statistics/pom.xml	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.statistics/pom.xml	2010-04-13 07:42:49 UTC (rev 2269)
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright (C) 2009 eXo Platform SAS.
+
+    This is free software; you can redistribute it and/or modify it
+    under the terms of the GNU Lesser General Public License as
+    published by the Free Software Foundation; either version 2.1 of
+    the License, or (at your option) any later version.
+
+    This software is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this software; if not, write to the Free
+    Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+    02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.exoplatform.jcr</groupId>
+    <artifactId>jcr-parent</artifactId>
+    <version>1.12.1-GA-SNAPSHOT</version>
+  </parent>
+  <artifactId>exo.jcr.component.statistics</artifactId>
+  <name>eXo JCR :: Component :: Statistics Provider</name>
+  <description>eXo JCR Statistics</description>
+  <dependencies>
+    <dependency>
+      <groupId>org.exoplatform.jcr</groupId>
+      <artifactId>exo.jcr.component.core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.aspectj</groupId>
+      <artifactId>aspectjrt</artifactId>
+     </dependency>
+  </dependencies>
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.codehaus.mojo</groupId>
+          <artifactId>aspectj-maven-plugin</artifactId>
+          <version>1.3</version>
+          <executions>
+            <execution>
+              <goals>
+                <goal>compile</goal>
+              </goals>
+            </execution>
+          </executions>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+</project>

Added: jcr/trunk/exo.jcr.component.statistics/src/main/java/org/exoplatform/services/jcr/statistics/JCRAPIAspect.java
===================================================================
--- jcr/trunk/exo.jcr.component.statistics/src/main/java/org/exoplatform/services/jcr/statistics/JCRAPIAspect.java	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.statistics/src/main/java/org/exoplatform/services/jcr/statistics/JCRAPIAspect.java	2010-04-13 07:42:49 UTC (rev 2269)
@@ -0,0 +1,261 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see&lt;http://www.gnu.org/licenses/&gt;.
+ */
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see&lt;http://www.gnu.org/licenses/&gt;.
+ */
+package org.exoplatform.services.jcr.statistics;
+
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.After;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * This aspect is used to collect all the statistics of all the methods of the JCR API.
+ * 
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto 
+ *          nicolas.filotto at exoplatform.com
+ * 26 mars 2010  
+ */
+ at Aspect
+public abstract class JCRAPIAspect
+{
+
+   /**
+    * The logger
+    */
+   private static final Log LOG = ExoLogger.getLogger("exo.jcr.component.statistics.JCRAPIAspectC");
+   
+   /**
+    * The result of the mapping if the corresponding value cannot be found.
+    */
+   private static final Statistics UNKNOWN = new Statistics(null, "?");
+
+   /**
+    * The flag that indicates if the aspect is initialized or not.
+    */
+   private static volatile boolean INITIALIZED;
+
+   /**
+    * The list of all the interfaces for which we want statistics
+    */
+   private static Class<?>[] TARGET_INTERFACES;
+
+   /**
+    * The mapping between the AspectJ signature and the target statistics
+    */
+   private static volatile Map<String, Statistics> MAPPING = Collections.unmodifiableMap(new HashMap<String, Statistics>());
+
+   /**
+    * The list of all the statistics, one per method
+    */
+   private final static Map<String, Map<String, Statistics>> ALL_STATISTICS = new HashMap<String, Map<String, Statistics>>();
+
+   /**
+    * Gives the name of the statistics from the given {@link Method} 
+    */
+   private static String getStatisticsName(Method m)
+   {
+      StringBuilder sb = new StringBuilder();
+      sb.append(m.getName());
+      sb.append('(');
+      Class<?>[] types = m.getParameterTypes();
+      if (types != null)
+      {
+         boolean first = true;
+         for (Class<?> type : types)
+         {
+            if (first)
+            {
+               first = false;
+            }
+            else
+            {
+               sb.append(", ");
+            }
+            sb.append(type.getSimpleName());
+         }
+      }
+      sb.append(')');
+      return sb.toString();
+   }
+
+   /**
+    * Gives the corresponding statistics for the given target class and AspectJ signature
+    * @param target the target {@link Class}
+    * @param signature the AspectJ signature
+    * @return the related {@link Statistics} or <code>null</code> if it cannot be found
+    */
+   private static Statistics getStatistics(Class<?> target, String signature)
+   {
+      initIfNeeded();
+      Statistics statistics = MAPPING.get(signature);
+      if (statistics == null)
+      {
+         synchronized (JCRAPIAspect.class)
+         {
+            Class<?> interfaceClass = findInterface(target);
+            if (interfaceClass != null)
+            {
+               Map<String, Statistics> allStatistics = ALL_STATISTICS.get(interfaceClass.getSimpleName());
+               if (allStatistics != null)
+               {
+                  int index1 = signature.indexOf('(');
+                  int index = signature.substring(0, index1).lastIndexOf('.');
+                  String name = signature.substring(index + 1);
+                  statistics = allStatistics.get(name);
+               }
+            }
+            if (statistics == null)
+            {
+               statistics = UNKNOWN;
+            }
+            Map<String, Statistics> tempMapping = new HashMap<String, Statistics>(MAPPING);
+            tempMapping.put(signature, statistics);
+            MAPPING = Collections.unmodifiableMap(tempMapping);            
+         }
+      }
+      if (statistics == UNKNOWN)
+      {
+         return null;
+      }
+      return statistics;
+   }
+
+   /**
+    * Find the monitored interface from the target {@link Class}
+    * @param target the target {@link Class}
+    * @return the monitored interface, <code>null</code> otherwise
+    */
+   private static Class<?> findInterface(Class<?> target)
+   {
+      if (target == null)
+      {
+         return null;
+      }
+      Class<?>[] interfaces = target.getInterfaces();
+      if (interfaces != null)
+      {
+         for (Class<?> c : TARGET_INTERFACES)
+         {
+            for (Class<?> i : interfaces)
+            {
+               if (c.getName().equals(i.getName()))
+               {
+                  return c;
+               }
+            }
+         }
+      }
+      return findInterface(target.getSuperclass());
+   }
+
+   /**
+    * Initializes the aspect if needed
+    */
+   private static void initIfNeeded()
+   {
+      if (!INITIALIZED)
+      {
+         synchronized (JCRAPIAspect.class)
+         {
+            if (!INITIALIZED)
+            {
+               ExoContainer container = ExoContainerContext.getTopContainer();
+               JCRAPIAspectConfig config = null;
+               if (container != null)
+               {
+                  config = (JCRAPIAspectConfig)container.getComponentInstanceOfType(JCRAPIAspectConfig.class);
+               }
+               if (config == null)
+               {
+                  TARGET_INTERFACES = new Class<?>[]{};
+                  LOG.warn("No interface to monitor could be found");
+               }
+               else
+               {
+                  TARGET_INTERFACES = config.getTargetInterfaces();
+                  for (Class<?> c : TARGET_INTERFACES)
+                  {
+                     Statistics global = new Statistics(null, "global");
+                     Map<String, Statistics> statistics = new TreeMap<String, Statistics>();
+                     Method[] methods = c.getMethods();
+                     for (Method m : methods)
+                     {
+                        String name = getStatisticsName(m);
+                        statistics.put(name, new Statistics(global, name));
+                     }
+                     JCRStatisticsManager.registerStatistics(c.getSimpleName(), global, statistics);
+                     ALL_STATISTICS.put(c.getSimpleName(), statistics);
+                  }
+               }
+               INITIALIZED = true;
+            }
+         }
+      }
+   }
+
+   @Pointcut
+   abstract void JCRAPIPointcut();
+
+   @Before("JCRAPIPointcut()")
+   public void begin(JoinPoint thisJoinPoint)
+   {
+      Statistics statistics =
+         getStatistics(thisJoinPoint.getTarget().getClass(), thisJoinPoint.getSignature().toString());
+      if (statistics != null)
+      {
+         statistics.begin();
+      }
+   }
+
+   @After("JCRAPIPointcut()")
+   public void end(JoinPoint thisJoinPoint)
+   {
+      Statistics statistics =
+         getStatistics(thisJoinPoint.getTarget().getClass(), thisJoinPoint.getSignature().toString());
+      if (statistics != null)
+      {
+         statistics.end();
+      }
+   }
+}

Added: jcr/trunk/exo.jcr.component.statistics/src/main/java/org/exoplatform/services/jcr/statistics/JCRAPIAspectConfig.java
===================================================================
--- jcr/trunk/exo.jcr.component.statistics/src/main/java/org/exoplatform/services/jcr/statistics/JCRAPIAspectConfig.java	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.statistics/src/main/java/org/exoplatform/services/jcr/statistics/JCRAPIAspectConfig.java	2010-04-13 07:42:49 UTC (rev 2269)
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see&lt;http://www.gnu.org/licenses/&gt;.
+ */
+package org.exoplatform.services.jcr.statistics;
+
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.ValuesParam;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The configuration of the {@link JCRAPIAspect}
+ * 
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto 
+ *          nicolas.filotto at exoplatform.com
+ * 9 avr. 2010  
+ */
+public class JCRAPIAspectConfig
+{
+
+   /**
+    * The logger
+    */
+   private static final Log LOG = ExoLogger.getLogger("exo.jcr.component.statistics.JCRAPIAspectConfig");
+
+   /**
+    * The list of interfaces that we want to monitor
+    */
+   private Class<?>[] targetInterfaces;
+
+   /**
+    * Default constructor
+    */
+   public JCRAPIAspectConfig(InitParams params)
+   {
+      this.targetInterfaces = loadTargetInterfaces(params.getValuesParam("targetInterfaces"));
+   }
+
+   /**
+    * @return the list of interfaces to monitor
+    */
+   private Class<?>[] loadTargetInterfaces(ValuesParam params)
+   {
+      ArrayList<?> values = params.getValues();
+      List<Class<?>> lTargetInterfaces = new ArrayList<Class<?>>();
+      if (values != null)
+      {
+         for (Object o : params.getValues())
+         {
+            String className = null;
+            try
+            {
+               className = (String)o;
+               lTargetInterfaces.add(Class.forName(className));
+            }
+            catch (Exception e)
+            {
+               LOG.warn("Cannot find the target interface " + className, e);
+            }
+         }
+      }
+      Class<?>[] targetInterfaces = new Class<?>[lTargetInterfaces.size()];
+      return (Class<?>[])lTargetInterfaces.toArray(targetInterfaces);
+   }
+   
+   /**
+    * @return the list of target interfaces
+    */
+   public Class<?>[] getTargetInterfaces()
+   {
+      return targetInterfaces;
+   }
+}

Added: jcr/trunk/exo.jcr.component.statistics/src/main/resources/META-INF/aop.xml
===================================================================
--- jcr/trunk/exo.jcr.component.statistics/src/main/resources/META-INF/aop.xml	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.statistics/src/main/resources/META-INF/aop.xml	2010-04-13 07:42:49 UTC (rev 2269)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<aspectj>
+	<aspects>
+		<concrete-aspect name="org.exoplatform.services.jcr.statistics.JCRAPIAspectImpl" extends="org.exoplatform.services.jcr.statistics.JCRAPIAspect">
+			<pointcut name="JCRAPIPointcut"
+				expression="(target(org.exoplatform.services.jcr.core.ExtendedSession) || target(org.exoplatform.services.jcr.core.ExtendedNode) || target(org.exoplatform.services.jcr.core.ExtendedProperty)) &amp;&amp; call(public * *(..))" />
+		</concrete-aspect>
+	</aspects>
+	<weaver>
+		<include within="org.exoplatform..*" />
+	</weaver>
+</aspectj>
\ No newline at end of file

Added: jcr/trunk/exo.jcr.component.statistics/src/main/resources/conf/configuration.xml
===================================================================
--- jcr/trunk/exo.jcr.component.statistics/src/main/resources/conf/configuration.xml	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.statistics/src/main/resources/conf/configuration.xml	2010-04-13 07:42:49 UTC (rev 2269)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+	<!--
+
+		Copyright (C) 2009 eXo Platform SAS. This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
+		as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This software is distributed in the
+		hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+		Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this software; if not,
+		write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+	-->
+<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+	xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+
+	<component>
+		<type>org.exoplatform.services.jcr.statistics.JCRAPIAspectConfig</type>
+		<init-params>
+			<values-param>
+				<name>targetInterfaces</name>
+				<value>org.exoplatform.services.jcr.core.ExtendedSession</value>
+				<value>org.exoplatform.services.jcr.core.ExtendedNode</value>
+				<value>org.exoplatform.services.jcr.core.ExtendedProperty</value>
+			</values-param>
+		</init-params>
+	</component>
+</configuration>

Modified: jcr/trunk/pom.xml
===================================================================
--- jcr/trunk/pom.xml	2010-04-13 07:03:28 UTC (rev 2268)
+++ jcr/trunk/pom.xml	2010-04-13 07:42:49 UTC (rev 2269)
@@ -360,7 +360,12 @@
         <groupId>jboss.jbossts</groupId>
         <artifactId>jbossts-common</artifactId>
         <version>4.6.1.GA</version>
-      </dependency>
+      </dependency>
+      <dependency>
+        <groupId>org.aspectj</groupId>
+        <artifactId>aspectjrt</artifactId>
+        <version>1.6.8</version>
+      </dependency>      
     </dependencies>
   </dependencyManagement>
   <dependencies>
@@ -425,7 +430,8 @@
     </testResources>
   </build>
   <modules>
-    <module>exo.jcr.component.core</module>
+    <module>exo.jcr.component.core</module>
+    <module>exo.jcr.component.statistics</module>
     <module>exo.jcr.component.ext</module>
     <module>exo.jcr.component.ftp</module>
     <module>exo.jcr.component.webdav</module>



More information about the exo-jcr-commits mailing list