[jboss-svn-commits] JBL Code SVN: r15575 - in labs/jbossesb/trunk/product/services/jbrules: src and 12 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Oct 4 06:59:58 EDT 2007


Author: kevin.conner at jboss.com
Date: 2007-10-04 06:59:57 -0400 (Thu, 04 Oct 2007)
New Revision: 15575

Added:
   labs/jbossesb/trunk/product/services/jbrules/src/aop/
   labs/jbossesb/trunk/product/services/jbrules/src/aop/java/
   labs/jbossesb/trunk/product/services/jbrules/src/aop/java/org/
   labs/jbossesb/trunk/product/services/jbrules/src/aop/java/org/jboss/
   labs/jbossesb/trunk/product/services/jbrules/src/aop/java/org/jboss/internal/
   labs/jbossesb/trunk/product/services/jbrules/src/aop/java/org/jboss/internal/soa/
   labs/jbossesb/trunk/product/services/jbrules/src/aop/java/org/jboss/internal/soa/esb/
   labs/jbossesb/trunk/product/services/jbrules/src/aop/java/org/jboss/internal/soa/esb/services/
   labs/jbossesb/trunk/product/services/jbrules/src/aop/java/org/jboss/internal/soa/esb/services/routing/
   labs/jbossesb/trunk/product/services/jbrules/src/aop/java/org/jboss/internal/soa/esb/services/routing/aspect/
   labs/jbossesb/trunk/product/services/jbrules/src/aop/java/org/jboss/internal/soa/esb/services/routing/aspect/ClassFieldExtractorAspect.java
   labs/jbossesb/trunk/product/services/jbrules/src/aop/resources/
   labs/jbossesb/trunk/product/services/jbrules/src/aop/resources/META-INF/
   labs/jbossesb/trunk/product/services/jbrules/src/aop/resources/META-INF/jboss-aop.xml
Modified:
   labs/jbossesb/trunk/product/services/jbrules/build.xml
Log:
workaround for JBESB-704

Modified: labs/jbossesb/trunk/product/services/jbrules/build.xml
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/build.xml	2007-10-04 10:44:46 UTC (rev 15574)
+++ labs/jbossesb/trunk/product/services/jbrules/build.xml	2007-10-04 10:59:57 UTC (rev 15575)
@@ -4,6 +4,47 @@
 	<!-- Import the base Ant build script... -->
 	<import file="${services.base.build}"/>
 	
+	<taskdef name="aopc" classname="org.jboss.aop.ant.AopC"
+		classpathref="classpath"/>
+
 	<target name="test" depends="base.test"/>
 
-</project>
\ No newline at end of file
+	<target name="esb" depends="ESB-services-base-build.esb, aop">
+		<copy todir="build/${ant.project.name}.esb/" >
+			<fileset dir="build" includes="drools-core*.jar, *.aop"/>
+		 </copy>
+	</target>
+
+	<target name="aop" depends="aop-jar">
+		<property name="aopc.dir" location="build/aopc-classes"/>
+		<delete dir="${aopc.dir}" quiet="true"/>
+		<mkdir dir="${aopc.dir}"/>
+
+		<unzip src="lib/ext/drools-core-4.0.1.jar" dest="${aopc.dir}"/>
+		<aopc compilerclasspathref="classpath" verbose="true">
+			<classpath path="${aopc.dir}"/>
+			<src path="${aopc.dir}"/>
+			<include name="org/drools/base/ClassFieldExtractor*.class"/>
+
+			<aoppath path="src/aop/resources/META-INF/jboss-aop.xml"/>
+			<aopclasspath path="build/aop-classes"/>
+		</aopc>
+		<zip destfile="build/drools-core-4.0.1.jar" basedir="${aopc.dir}"/>
+	</target>
+
+	<target name="aop-jar" depends="aop-compile">
+		<jar destfile="build/${ant.project.name}.aop">
+			<fileset dir="build/aop-classes"/>
+			<fileset dir="src/aop/resources"/>
+		</jar>
+	</target>
+
+	<target name="aop-compile" depends="aop-prepare">
+		<javac srcdir="src/aop/java" destdir="build/aop-classes"
+			debug="on" classpathref="classpath"/>
+	</target>
+
+	<target name="aop-prepare">
+		<mkdir dir="build/aop-classes"/>
+	</target>
+</project>

Added: labs/jbossesb/trunk/product/services/jbrules/src/aop/java/org/jboss/internal/soa/esb/services/routing/aspect/ClassFieldExtractorAspect.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/aop/java/org/jboss/internal/soa/esb/services/routing/aspect/ClassFieldExtractorAspect.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbrules/src/aop/java/org/jboss/internal/soa/esb/services/routing/aspect/ClassFieldExtractorAspect.java	2007-10-04 10:59:57 UTC (rev 15575)
@@ -0,0 +1,168 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.
+ */
+package org.jboss.internal.soa.esb.services.routing.aspect;
+
+import java.security.ProtectionDomain;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.base.ClassFieldExtractor;
+import org.drools.util.asm.ClassFieldInspector;
+import org.jboss.aop.joinpoint.MethodCalledByMethodInvocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.soa.esb.lifecycle.LifecycleResource;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceException;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceFactory;
+
+public class ClassFieldExtractorAspect
+{
+    final LifecycleResource<Map<String, ClassFieldExtractor>> extractorCacheResource = new LifecycleResource<Map<String, ClassFieldExtractor>>(new ExtractorCacheFactory()) ;
+
+    final LifecycleResource<Map<Class, ClassFieldInspector>> inspectorCacheResource = new LifecycleResource<Map<Class, ClassFieldInspector>>(new InspectorCacheFactory()) ;
+    
+    final LifecycleResource<ByteArrayClassLoader> byteArrayClassLoaderResource = new LifecycleResource<ByteArrayClassLoader>(new ByteArrayClassLoaderCacheFactory()) ;
+
+    public synchronized Object getExtractor(final MethodInvocation invocation)
+        throws Throwable
+    {
+        final Object[] args = invocation.getArguments() ;
+        final Class clazz = (Class)args[0] ;
+        final String fieldName = (String)args[1] ;
+        final ClassLoader classLoader = (ClassLoader)args[2] ;
+        
+        final String key = clazz.getName() + "|" + fieldName ;
+
+        final Map<String, ClassFieldExtractor> extractorCache = extractorCacheResource.getLifecycleResource() ;
+        final ClassFieldExtractor currentExtractor = extractorCache.get(key) ;
+        if (currentExtractor != null)
+        {
+            return currentExtractor ;
+        }
+        final ClassFieldExtractor newExtractor = new ClassFieldExtractor(clazz, fieldName, classLoader) ;
+        extractorCache.put(key, newExtractor) ;
+        return newExtractor ;
+    }
+    
+    public Object putMap(final MethodCalledByMethodInvocation invocation)
+        throws Throwable
+    {
+        final Object[] args = invocation.getArguments() ;
+        final Object key = args[0] ;
+        final Object value = args[1] ;
+        
+        if ((key instanceof Class) && (value instanceof ClassFieldInspector))
+        {
+            inspectorCacheResource.getLifecycleResource().put((Class)key, (ClassFieldInspector)value) ;
+            return null ;
+        }
+        else
+        {
+            return invocation.invokeNext() ;
+        }
+    }
+    
+    public Object getMap(final MethodCalledByMethodInvocation invocation)
+        throws Throwable
+    {
+        final Object[] args = invocation.getArguments() ;
+        final Object key = args[0] ;
+
+        if (key instanceof Class)
+        {
+            return inspectorCacheResource.getLifecycleResource().get((Class)key) ;
+        }
+        else
+        {
+            return invocation.invokeNext() ;
+        }
+    }
+    
+    public synchronized Object defineClass(final MethodInvocation invocation)
+        throws Throwable
+    {
+        final Object[] args = invocation.getArguments() ;
+        final String name = (String)args[0] ;
+        final byte[] bytes = (byte[])args[1] ;
+        final ProtectionDomain domain = (ProtectionDomain)args[2] ;
+        
+        final ByteArrayClassLoader byteArrayClassLoader = byteArrayClassLoaderResource.getLifecycleResource() ;
+        return byteArrayClassLoader.defineClass(name, bytes, domain) ;
+    }
+
+    private static class ByteArrayClassLoader extends ClassLoader
+    {
+        public ByteArrayClassLoader(final ClassLoader parent)
+        {
+            super( parent ) ;
+        }
+
+        public Class defineClass(final String name, final byte[] bytes, final ProtectionDomain domain)
+        {
+            return defineClass(name, bytes, 0, bytes.length, domain) ;
+        }
+    }
+    
+    private static final class ExtractorCacheFactory implements LifecycleResourceFactory<Map<String, ClassFieldExtractor>>
+    {
+        public Map<String, ClassFieldExtractor> createLifecycleResource(final String lifecycleIdentity)
+            throws LifecycleResourceException
+        {
+            return new HashMap<String, ClassFieldExtractor>() ;
+        }
+        
+        public void destroyLifecycleResource(final Map<String, ClassFieldExtractor> resource,
+            final String lifecycleIdentity)
+            throws LifecycleResourceException
+        {
+        }
+    }
+    
+    private static final class InspectorCacheFactory implements LifecycleResourceFactory<Map<Class, ClassFieldInspector>>
+    {
+        public Map<Class, ClassFieldInspector> createLifecycleResource(final String lifecycleIdentity)
+            throws LifecycleResourceException
+        {
+            return new HashMap<Class, ClassFieldInspector>() ;
+        }
+        
+        public void destroyLifecycleResource(final Map<Class, ClassFieldInspector> resource,
+            final String lifecycleIdentity)
+            throws LifecycleResourceException
+        {
+        }
+    }
+    
+    private static class ByteArrayClassLoaderCacheFactory implements
+        LifecycleResourceFactory<ByteArrayClassLoader>
+    {
+        public ByteArrayClassLoader createLifecycleResource(final String lifecycleIdentity)
+            throws LifecycleResourceException
+        {
+            return new ByteArrayClassLoader(Thread.currentThread().getContextClassLoader()) ;
+        }
+        
+        public void destroyLifecycleResource(final ByteArrayClassLoader resource, final String lifecycleIdentity)
+            throws LifecycleResourceException
+        {
+        }
+    }
+}


Property changes on: labs/jbossesb/trunk/product/services/jbrules/src/aop/java/org/jboss/internal/soa/esb/services/routing/aspect/ClassFieldExtractorAspect.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/product/services/jbrules/src/aop/resources/META-INF/jboss-aop.xml
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/aop/resources/META-INF/jboss-aop.xml	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbrules/src/aop/resources/META-INF/jboss-aop.xml	2007-10-04 10:59:57 UTC (rev 15575)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE aop PUBLIC
+   "-//JBoss//DTD JBOSS AOP 1.0//EN"
+   "http://labs.jboss.com/portal/jbossaop/dtd/jboss-aop_1_0.dtd">
+
+<aop>
+   <aspect class="org.jboss.internal.soa.esb.services.routing.aspect.ClassFieldExtractorAspect" scope="PER_VM"/>
+   
+   <bind pointcut="execution(static * org.drools.base.ClassFieldExtractorCache->getExtractor(..))">
+      <advice name="getExtractor" aspect="org.jboss.internal.soa.esb.services.routing.aspect.ClassFieldExtractorAspect"/>
+   </bind>
+   <bind pointcut="withincode(* org.drools.base.ClassFieldExtractorFactory->getClassFieldExtractor(..)) AND call(* java.util.Map->get(..))">
+      <advice name="getMap" aspect="org.jboss.internal.soa.esb.services.routing.aspect.ClassFieldExtractorAspect"/>
+   </bind>
+   <bind pointcut="withincode(* org.drools.base.ClassFieldExtractorFactory->getClassFieldExtractor(..)) AND call(* java.util.Map->put(..))">
+      <advice name="putMap" aspect="org.jboss.internal.soa.esb.services.routing.aspect.ClassFieldExtractorAspect"/>
+   </bind>
+   <bind pointcut="execution(* org.drools.base.ClassFieldExtractorFactory$ByteArrayClassLoader->defineClass(java.lang.String, byte[], java.security.ProtectionDomain))">
+      <advice name="defineClass" aspect="org.jboss.internal.soa.esb.services.routing.aspect.ClassFieldExtractorAspect"/>
+   </bind>
+</aop>


Property changes on: labs/jbossesb/trunk/product/services/jbrules/src/aop/resources/META-INF/jboss-aop.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native




More information about the jboss-svn-commits mailing list