[jboss-cvs] JBossAS SVN: r101117 - in projects/jboss-mdr/trunk/src: main/java/org/jboss/metadata/spi/retrieval and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Feb 18 11:00:29 EST 2010
Author: kabir.khan at jboss.com
Date: 2010-02-18 11:00:28 -0500 (Thu, 18 Feb 2010)
New Revision: 101117
Added:
projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/
projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/
projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation1.java
projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation2.java
projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation3.java
projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation4.java
projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation5.java
projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/NullAnnotatedElementMetaDataLoader.java
projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/OriginalAnnotatedElementMetaDataLoader.java
projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/SecurityActions.java
projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/SingletonAnnotatedElementMetaDataLoader.java
projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/test/
projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/test/CreateScopeKeyBenchmark.java
projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/test/CreateUnmodifiableScopeKeyBenchmark.java
projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/test/NoComponentMetaDataCachingMetaDataContextBenchmark.java
Modified:
projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java
projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/retrieval/MetaDataRetrievalToMetaDataBridge.java
Log:
[JBMDR-66] Make AnnotatedElementMetaDataLoader.getComponentMetaDataRetrieval() return null, and MetaDataRetrievalToMetaDataBridge.getComponentMetaData() return an empty singleton if there is no metadata
Modified: projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java 2010-02-18 15:17:05 UTC (rev 101116)
+++ projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java 2010-02-18 16:00:28 UTC (rev 101117)
@@ -42,6 +42,8 @@
import org.jboss.metadata.spi.retrieval.basic.BasicMetaDatasItem;
import org.jboss.metadata.spi.retrieval.simple.SimpleAnnotationItem;
import org.jboss.metadata.spi.retrieval.simple.SimpleAnnotationsItem;
+import org.jboss.metadata.spi.retrieval.simple.SimpleMetaDataItem;
+import org.jboss.metadata.spi.retrieval.simple.SimpleMetaDatasItem;
import org.jboss.metadata.spi.scope.CommonLevels;
import org.jboss.metadata.spi.scope.Scope;
import org.jboss.metadata.spi.scope.ScopeKey;
@@ -54,6 +56,7 @@
import org.jboss.metadata.spi.signature.MethodParametersSignature;
import org.jboss.metadata.spi.signature.MethodSignature;
import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.test.metadata.benchmark.support.NullAnnotatedElementMetaDataLoader;
import org.jboss.util.JBossStringBuilder;
import org.jboss.util.Strings;
@@ -146,8 +149,8 @@
return null;
}
if (constructor.getAnnotations().length == 0)
- return NullAnnotatedElementComponentMetaDataLoader.INSTANCE;
- return new AnnotatedElementMetaDataLoader(constructor);
+ return null;
+ return new NullAnnotatedElementMetaDataLoader(constructor);
}
else if (signature instanceof MethodSignature)
{
@@ -162,8 +165,8 @@
return null;
}
if (method.getAnnotations().length == 0)
- return NullAnnotatedElementComponentMetaDataLoader.INSTANCE;
- return new AnnotatedElementMetaDataLoader(method);
+ return null;
+ return new NullAnnotatedElementMetaDataLoader(method);
}
else if (signature instanceof DeclaredMethodSignature)
{
@@ -186,8 +189,8 @@
}
}
if (method.getAnnotations().length == 0)
- return NullAnnotatedElementComponentMetaDataLoader.INSTANCE;
- return new AnnotatedElementMetaDataLoader(method);
+ return null;
+ return new NullAnnotatedElementMetaDataLoader(method);
}
else if (signature instanceof MethodParametersSignature)
{
@@ -203,7 +206,7 @@
}
Annotation[][] paramAnnotations = method.getParameterAnnotations();
if (paramAnnotations[methodParametersSignature.getParam()].length == 0)
- return NullAnnotatedElementComponentMetaDataLoader.INSTANCE;
+ return null;
return new SimpleMetaDataLoader(paramAnnotations[methodParametersSignature.getParam()]);
}
else if (signature instanceof ConstructorParametersSignature)
@@ -220,7 +223,7 @@
}
Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
if (paramAnnotations[constructorParametersSignature.getParam()].length == 0)
- return NullAnnotatedElementComponentMetaDataLoader.INSTANCE;
+ return null;
return new SimpleMetaDataLoader(paramAnnotations[constructorParametersSignature.getParam()]);
}
else if (signature instanceof FieldSignature)
@@ -236,8 +239,8 @@
return null;
}
if (field.getAnnotations().length == 0)
- return NullAnnotatedElementComponentMetaDataLoader.INSTANCE;
- return new AnnotatedElementMetaDataLoader(field);
+ return null;
+ return new NullAnnotatedElementMetaDataLoader(field);
}
}
@@ -249,7 +252,7 @@
Annotation[][] paramAnnotations = method.getParameterAnnotations();
MethodParametersSignature sig = (MethodParametersSignature) signature;
if (paramAnnotations[sig.getParam()].length == 0)
- return NullAnnotatedElementComponentMetaDataLoader.INSTANCE;
+ return null;
return new SimpleMetaDataLoader(paramAnnotations[sig.getParam()]);
}
}
@@ -262,7 +265,7 @@
Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
ConstructorParametersSignature sig = (ConstructorParametersSignature) signature;
if (paramAnnotations[sig.getParam()].length == 0)
- return NullAnnotatedElementComponentMetaDataLoader.INSTANCE;
+ return null;
return new SimpleMetaDataLoader(paramAnnotations[sig.getParam()]);
}
}
@@ -304,86 +307,4 @@
}
return null;
}
-
- /**
- * http://community.jboss.org/thread/148203
- * Singleton be returned by AnnotatedElementMetaDataLoader.getComponentMetaDataRetrieval() when there are no annotations for the member. This is to avoid
- * the overhead of creating a new AnnotatedElementMetaDataLoader even in those cases, something which shows up to be a big bottleneck in AS startup time,
- * mainly due to the creation of AnnotatedElementMetaDataLoader's ScopeKey.
- */
- private static class NullAnnotatedElementComponentMetaDataLoader implements MetaDataRetrieval
- {
- final static NullAnnotatedElementComponentMetaDataLoader INSTANCE = new NullAnnotatedElementComponentMetaDataLoader();
- final static ScopeKey nullScopeKey = new ScopeKey(new Scope(CommonLevels.JOINPOINT, INSTANCE));
-
- final BasicAnnotationsItem noANnnotationsItem = new BasicAnnotationsItem(null, new AnnotationItem[0]);
- final BasicMetaDatasItem noMetaDatasItem = new BasicMetaDatasItem(null, new MetaDataItem[0]);
- final ValidTime validTime = new ValidTime();
-
- public MetaDataRetrieval getComponentMetaDataRetrieval(Signature signature)
- {
- return INSTANCE;
- }
-
- public ScopeKey getScope()
- {
- return nullScopeKey;
- }
-
- public MetaDataRetrieval getScopedRetrieval(ScopeLevel level)
- {
- return INSTANCE;
- }
-
- public ValidTime getValidTime()
- {
- return validTime;
- }
-
- public boolean isEmpty()
- {
- return true;
- }
-
- public <T extends Annotation> AnnotationItem<T> retrieveAnnotation(Class<T> annotationType)
- {
- return null;
- }
-
- public AnnotationsItem retrieveAnnotations()
- {
- return noANnnotationsItem;
- }
-
- public AnnotationsItem retrieveAnnotationsAnnotatedWith(Class<? extends Annotation> meta)
- {
- return noANnnotationsItem;
- }
-
- public AnnotationsItem retrieveLocalAnnotations()
- {
- return noANnnotationsItem;
- }
-
- public MetaDatasItem retrieveLocalMetaData()
- {
- return noMetaDatasItem;
- }
-
- public MetaDatasItem retrieveMetaData()
- {
- return noMetaDatasItem;
- }
-
- public <T> MetaDataItem<T> retrieveMetaData(Class<T> type)
- {
- return null;
- }
-
- public MetaDataItem<?> retrieveMetaData(String name)
- {
- return null;
- }
-
- }
}
Modified: projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/retrieval/MetaDataRetrievalToMetaDataBridge.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/retrieval/MetaDataRetrievalToMetaDataBridge.java 2010-02-18 15:17:05 UTC (rev 101116)
+++ projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/retrieval/MetaDataRetrievalToMetaDataBridge.java 2010-02-18 16:00:28 UTC (rev 101117)
@@ -167,7 +167,7 @@
{
MetaDataRetrieval component = retrieval.getComponentMetaDataRetrieval(signature);
if (component == null)
- return null;
+ return NullComponentMetaData.INSTANCE;
return new MetaDataRetrievalToMetaDataBridge(component);
}
@@ -218,4 +218,95 @@
{
return retrieval;
}
+
+ private static class NullComponentMetaData implements MetaData
+ {
+ final static NullComponentMetaData INSTANCE = new NullComponentMetaData();
+
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+ {
+ return null;
+ }
+
+ public Annotation[] getAnnotations()
+ {
+ return MetaData.NO_ANNOTATIONS;
+ }
+
+ public Annotation[] getAnnotationsAnnotatedWith(Class<? extends Annotation> meta)
+ {
+ return MetaData.NO_ANNOTATIONS;
+ }
+
+ public MetaData getComponentMetaData(Signature signature)
+ {
+ return null;
+ }
+
+ public Annotation[] getLocalAnnotations()
+ {
+ return MetaData.NO_ANNOTATIONS;
+ }
+
+ public Object[] getLocalMetaData()
+ {
+ return MetaData.NO_METADATA;
+ }
+
+ public <T> T getMetaData(Class<T> type)
+ {
+ return null;
+ }
+
+ public Object[] getMetaData()
+ {
+ return MetaData.NO_METADATA;
+ }
+
+ public Object getMetaData(String name)
+ {
+ return null;
+ }
+
+ public <T> T getMetaData(String name, Class<T> type)
+ {
+ return null;
+ }
+
+ public MetaData getScopeMetaData(ScopeLevel level)
+ {
+ return null;
+ }
+
+ public long getValidTime()
+ {
+ return 0;
+ }
+
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+ {
+ return false;
+ }
+
+ public boolean isEmpty()
+ {
+ return true;
+ }
+
+ public boolean isMetaDataPresent(Class<?> type)
+ {
+ return false;
+ }
+
+ public boolean isMetaDataPresent(String name)
+ {
+ return false;
+ }
+
+ public boolean isMetaDataPresent(String name, Class<?> type)
+ {
+ return false;
+ }
+
+ }
}
Added: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation1.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation1.java (rev 0)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation1.java 2010-02-18 16:00:28 UTC (rev 101117)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.test.metadata.benchmark.support;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassNoMethodAnnotation1
+{
+ public void method1(){}
+ public void method2(){}
+ public void method3(){}
+ public void method4(){}
+ public void method5(){}
+ public void method6(){}
+ public void method7(){}
+ public void method8(){}
+ public void method9(){}
+}
Added: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation2.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation2.java (rev 0)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation2.java 2010-02-18 16:00:28 UTC (rev 101117)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.test.metadata.benchmark.support;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassNoMethodAnnotation2
+{
+ public void method1(){}
+ public void method2(){}
+ public void method3(){}
+ public void method4(){}
+ public void method5(){}
+ public void method6(){}
+ public void method7(){}
+ public void method8(){}
+ public void method9(){}
+}
Added: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation3.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation3.java (rev 0)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation3.java 2010-02-18 16:00:28 UTC (rev 101117)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.test.metadata.benchmark.support;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassNoMethodAnnotation3
+{
+ public void method1(){}
+ public void method2(){}
+ public void method3(){}
+ public void method4(){}
+ public void method5(){}
+ public void method6(){}
+ public void method7(){}
+ public void method8(){}
+ public void method9(){}
+}
Added: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation4.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation4.java (rev 0)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation4.java 2010-02-18 16:00:28 UTC (rev 101117)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.test.metadata.benchmark.support;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassNoMethodAnnotation4
+{
+ public void method1(){}
+ public void method2(){}
+ public void method3(){}
+ public void method4(){}
+ public void method5(){}
+ public void method6(){}
+ public void method7(){}
+ public void method8(){}
+ public void method9(){}
+}
Added: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation5.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation5.java (rev 0)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/ClassNoMethodAnnotation5.java 2010-02-18 16:00:28 UTC (rev 101117)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.test.metadata.benchmark.support;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassNoMethodAnnotation5
+{
+ public void method1(){}
+ public void method2(){}
+ public void method3(){}
+ public void method4(){}
+ public void method5(){}
+ public void method6(){}
+ public void method7(){}
+ public void method8(){}
+ public void method9(){}
+}
Added: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/NullAnnotatedElementMetaDataLoader.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/NullAnnotatedElementMetaDataLoader.java (rev 0)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/NullAnnotatedElementMetaDataLoader.java 2010-02-18 16:00:28 UTC (rev 101117)
@@ -0,0 +1,388 @@
+/*
+* 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.test.metadata.benchmark.support;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+
+import org.jboss.logging.Logger;
+import org.jboss.metadata.plugins.loader.BasicMetaDataLoader;
+import org.jboss.metadata.plugins.loader.SimpleMetaDataLoader;
+import org.jboss.metadata.spi.retrieval.AnnotationItem;
+import org.jboss.metadata.spi.retrieval.AnnotationsItem;
+import org.jboss.metadata.spi.retrieval.MetaDataItem;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
+import org.jboss.metadata.spi.retrieval.MetaDatasItem;
+import org.jboss.metadata.spi.retrieval.ValidTime;
+import org.jboss.metadata.spi.retrieval.basic.BasicAnnotationsItem;
+import org.jboss.metadata.spi.retrieval.basic.BasicMetaDatasItem;
+import org.jboss.metadata.spi.retrieval.simple.SimpleAnnotationItem;
+import org.jboss.metadata.spi.retrieval.simple.SimpleAnnotationsItem;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.Scope;
+import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.scope.ScopeLevel;
+import org.jboss.metadata.spi.scope.UnmodifiableScopeKey;
+import org.jboss.metadata.spi.signature.ConstructorParametersSignature;
+import org.jboss.metadata.spi.signature.ConstructorSignature;
+import org.jboss.metadata.spi.signature.DeclaredMethodSignature;
+import org.jboss.metadata.spi.signature.FieldSignature;
+import org.jboss.metadata.spi.signature.MethodParametersSignature;
+import org.jboss.metadata.spi.signature.MethodSignature;
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.util.JBossStringBuilder;
+import org.jboss.util.Strings;
+
+/**
+ * AnnotatedElementMetaDataLoader.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 101076 $
+ */
+public class NullAnnotatedElementMetaDataLoader extends BasicMetaDataLoader
+{
+ /** The log */
+ private static final Logger log = Logger.getLogger(NullAnnotatedElementMetaDataLoader.class);
+
+ /** The annotated element */
+ private AnnotatedElement annotated;
+
+ private static final ScopeKey getScopeKey(AnnotatedElement annotated)
+ {
+ Scope scope;
+ if (annotated instanceof Class)
+ {
+ Class<?> clazz = Class.class.cast(annotated);
+ scope = new Scope(CommonLevels.CLASS, clazz);
+ }
+ else if (annotated instanceof Member)
+ {
+ Member member = (Member) annotated;
+ scope = new Scope(CommonLevels.JOINPOINT, member);
+ }
+ else
+ {
+ return ScopeKey.DEFAULT_SCOPE;
+ }
+ return new UnmodifiableScopeKey(scope);
+ }
+
+ /**
+ * Create a new AnnotatedElementMetaDataContext.
+ *
+ * @param annotated the annotated element
+ */
+ public NullAnnotatedElementMetaDataLoader(AnnotatedElement annotated)
+ {
+ super(getScopeKey(annotated));
+ if (annotated == null)
+ throw new IllegalArgumentException("Null annotated element");
+ this.annotated = annotated;
+ }
+
+ @SuppressWarnings("unchecked")
+ public AnnotationsItem retrieveAnnotations()
+ {
+ Annotation[] annotations = annotated.getAnnotations();
+ if (annotations.length == 0)
+ return SimpleAnnotationsItem.NO_ANNOTATIONS;
+
+ AnnotationItem[] items = new AnnotationItem[annotations.length];
+ for (int i = 0; i < items.length; ++i)
+ items[i] = new SimpleAnnotationItem(annotations[i]);
+ return new SimpleAnnotationsItem(items);
+ }
+
+ public <T extends Annotation> AnnotationItem<T> retrieveAnnotation(Class<T> annotationType)
+ {
+ T annotation = annotated.getAnnotation(annotationType);
+ if (annotation == null)
+ return null;
+ return new SimpleAnnotationItem<T>(annotation);
+ }
+
+ public MetaDataRetrieval getComponentMetaDataRetrieval(Signature signature)
+ {
+ if (signature == null)
+ return null;
+
+ if (annotated instanceof Class)
+ {
+ Class<?> clazz = Class.class.cast(annotated);
+ if (signature instanceof ConstructorSignature)
+ {
+ ConstructorSignature constructorSignature = (ConstructorSignature) signature;
+ Constructor<?> constructor = constructorSignature.getConstructor();
+ if (constructor == null)
+ constructor = SecurityActions.findConstructor(clazz, signature.getParametersTypes(clazz));
+ if (constructor == null)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Constructor with signature " + signature + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ if (constructor.getAnnotations().length == 0)
+ return null;
+ return new NullAnnotatedElementMetaDataLoader(constructor);
+ }
+ else if (signature instanceof MethodSignature)
+ {
+ MethodSignature methodSignature = (MethodSignature) signature;
+ Method method = methodSignature.getMethod();
+ if (method == null)
+ method = SecurityActions.findMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
+ if (method == null)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Method with signature " + signature + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ if (method.getAnnotations().length == 0)
+ return null;
+ return new NullAnnotatedElementMetaDataLoader(method);
+ }
+ else if (signature instanceof DeclaredMethodSignature)
+ {
+ DeclaredMethodSignature methodSignature = (DeclaredMethodSignature) signature;
+ Method method = methodSignature.getMethod();
+ if (method == null)
+ {
+ clazz = getDeclaringClass(clazz, methodSignature.getDeclaringClass());
+ if (clazz == null)
+ return null;
+ try
+ {
+ method = SecurityActions.findDeclaredMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
+ }
+ catch (NoSuchMethodException nsme)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Method with signature " + signature + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ }
+ if (method.getAnnotations().length == 0)
+ return null;
+ return new NullAnnotatedElementMetaDataLoader(method);
+ }
+ else if (signature instanceof MethodParametersSignature)
+ {
+ MethodParametersSignature methodParametersSignature = (MethodParametersSignature) signature;
+ Method method = methodParametersSignature.getMethod();
+ if (method == null)
+ method = SecurityActions.findMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
+ if (method == null)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Method with signature " + signature + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ Annotation[][] paramAnnotations = method.getParameterAnnotations();
+ if (paramAnnotations[methodParametersSignature.getParam()].length == 0)
+ return null;
+ return new SimpleMetaDataLoader(paramAnnotations[methodParametersSignature.getParam()]);
+ }
+ else if (signature instanceof ConstructorParametersSignature)
+ {
+ ConstructorParametersSignature constructorParametersSignature = (ConstructorParametersSignature) signature;
+ Constructor<?> constructor = constructorParametersSignature.getConstructor();
+ if (constructor == null)
+ constructor = SecurityActions.findConstructor(clazz, signature.getParametersTypes(clazz));
+ if (constructor == null)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Constructor with signature " + signature + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
+ if (paramAnnotations[constructorParametersSignature.getParam()].length == 0)
+ return null;
+ return new SimpleMetaDataLoader(paramAnnotations[constructorParametersSignature.getParam()]);
+ }
+ else if (signature instanceof FieldSignature)
+ {
+ FieldSignature fieldSignature = (FieldSignature) signature;
+ Field field = fieldSignature.getField();
+ if (field == null)
+ field = SecurityActions.findField(clazz, signature.getName());
+ if (field == null)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Field " + signature.getName() + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ if (field.getAnnotations().length == 0)
+ return null;
+ return new NullAnnotatedElementMetaDataLoader(field);
+ }
+ }
+
+ if (annotated instanceof Method)
+ {
+ if (signature instanceof MethodParametersSignature)
+ {
+ Method method = (Method)annotated;
+ Annotation[][] paramAnnotations = method.getParameterAnnotations();
+ MethodParametersSignature sig = (MethodParametersSignature) signature;
+ if (paramAnnotations[sig.getParam()].length == 0)
+ return null;
+ return new SimpleMetaDataLoader(paramAnnotations[sig.getParam()]);
+ }
+ }
+
+ if (annotated instanceof Constructor)
+ {
+ if (signature instanceof ConstructorParametersSignature)
+ {
+ Constructor<?> constructor = Constructor.class.cast(annotated);
+ Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
+ ConstructorParametersSignature sig = (ConstructorParametersSignature) signature;
+ if (paramAnnotations[sig.getParam()].length == 0)
+ return null;
+ return new SimpleMetaDataLoader(paramAnnotations[sig.getParam()]);
+ }
+ }
+
+ return null;
+ }
+
+ public boolean isEmpty()
+ {
+ Annotation[] annotations = annotated.getAnnotations();
+ return annotations == null || annotations.length == 0;
+ }
+
+ public String toString()
+ {
+ JBossStringBuilder buffer = new JBossStringBuilder();
+ Strings.defaultToString(buffer, this);
+ buffer.append("[");
+ buffer.append(annotated);
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+ /**
+ * Get the declaring class from the reference class
+ *
+ * @param reference the reference class
+ * @param declaringClass the declaring class
+ * @return the class or null if the declaring class is not a super class of the reference
+ */
+ private static Class<?> getDeclaringClass(Class<?> reference, String declaringClass)
+ {
+ while (reference != null)
+ {
+ if (declaringClass.equals(reference.getName()))
+ return reference;
+
+ reference = reference.getSuperclass();
+ }
+ return null;
+ }
+
+ /**
+ * http://community.jboss.org/thread/148203
+ * Singleton be returned by AnnotatedElementMetaDataLoader.getComponentMetaDataRetrieval() when there are no annotations for the member. This is to avoid
+ * the overhead of creating a new AnnotatedElementMetaDataLoader even in those cases, something which shows up to be a big bottleneck in AS startup time,
+ * mainly due to the creation of AnnotatedElementMetaDataLoader's ScopeKey.
+ */
+ private static class NullAnnotatedElementComponentMetaDataLoader implements MetaDataRetrieval
+ {
+ final static NullAnnotatedElementComponentMetaDataLoader INSTANCE = new NullAnnotatedElementComponentMetaDataLoader();
+ final static ScopeKey nullScopeKey = new ScopeKey(new Scope(CommonLevels.JOINPOINT, INSTANCE));
+
+ final BasicAnnotationsItem noANnnotationsItem = new BasicAnnotationsItem(null, new AnnotationItem[0]);
+ final BasicMetaDatasItem noMetaDatasItem = new BasicMetaDatasItem(null, new MetaDataItem[0]);
+ final ValidTime validTime = new ValidTime();
+
+ public MetaDataRetrieval getComponentMetaDataRetrieval(Signature signature)
+ {
+ return INSTANCE;
+ }
+
+ public ScopeKey getScope()
+ {
+ return nullScopeKey;
+ }
+
+ public MetaDataRetrieval getScopedRetrieval(ScopeLevel level)
+ {
+ return INSTANCE;
+ }
+
+ public ValidTime getValidTime()
+ {
+ return validTime;
+ }
+
+ public boolean isEmpty()
+ {
+ return true;
+ }
+
+ public <T extends Annotation> AnnotationItem<T> retrieveAnnotation(Class<T> annotationType)
+ {
+ return null;
+ }
+
+ public AnnotationsItem retrieveAnnotations()
+ {
+ return noANnnotationsItem;
+ }
+
+ public AnnotationsItem retrieveAnnotationsAnnotatedWith(Class<? extends Annotation> meta)
+ {
+ return noANnnotationsItem;
+ }
+
+ public AnnotationsItem retrieveLocalAnnotations()
+ {
+ return noANnnotationsItem;
+ }
+
+ public MetaDatasItem retrieveLocalMetaData()
+ {
+ return noMetaDatasItem;
+ }
+
+ public MetaDatasItem retrieveMetaData()
+ {
+ return noMetaDatasItem;
+ }
+
+ public <T> MetaDataItem<T> retrieveMetaData(Class<T> type)
+ {
+ return null;
+ }
+
+ public MetaDataItem<?> retrieveMetaData(String name)
+ {
+ return null;
+ }
+
+ }
+}
Added: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/OriginalAnnotatedElementMetaDataLoader.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/OriginalAnnotatedElementMetaDataLoader.java (rev 0)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/OriginalAnnotatedElementMetaDataLoader.java 2010-02-18 16:00:28 UTC (rev 101117)
@@ -0,0 +1,372 @@
+/*
+* 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.test.metadata.benchmark.support;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+
+import org.jboss.logging.Logger;
+import org.jboss.metadata.plugins.loader.BasicMetaDataLoader;
+import org.jboss.metadata.plugins.loader.SimpleMetaDataLoader;
+import org.jboss.metadata.spi.retrieval.AnnotationItem;
+import org.jboss.metadata.spi.retrieval.AnnotationsItem;
+import org.jboss.metadata.spi.retrieval.MetaDataItem;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
+import org.jboss.metadata.spi.retrieval.MetaDatasItem;
+import org.jboss.metadata.spi.retrieval.ValidTime;
+import org.jboss.metadata.spi.retrieval.basic.BasicAnnotationsItem;
+import org.jboss.metadata.spi.retrieval.basic.BasicMetaDatasItem;
+import org.jboss.metadata.spi.retrieval.simple.SimpleAnnotationItem;
+import org.jboss.metadata.spi.retrieval.simple.SimpleAnnotationsItem;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.Scope;
+import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.scope.ScopeLevel;
+import org.jboss.metadata.spi.scope.UnmodifiableScopeKey;
+import org.jboss.metadata.spi.signature.ConstructorParametersSignature;
+import org.jboss.metadata.spi.signature.ConstructorSignature;
+import org.jboss.metadata.spi.signature.DeclaredMethodSignature;
+import org.jboss.metadata.spi.signature.FieldSignature;
+import org.jboss.metadata.spi.signature.MethodParametersSignature;
+import org.jboss.metadata.spi.signature.MethodSignature;
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.util.JBossStringBuilder;
+import org.jboss.util.Strings;
+
+/**
+ * AnnotatedElementMetaDataLoader.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 101076 $
+ */
+public class OriginalAnnotatedElementMetaDataLoader extends BasicMetaDataLoader
+{
+ /** The log */
+ private static final Logger log = Logger.getLogger(OriginalAnnotatedElementMetaDataLoader.class);
+
+ /** The annotated element */
+ private AnnotatedElement annotated;
+
+ private static final ScopeKey getScopeKey(AnnotatedElement annotated)
+ {
+ Scope scope;
+ if (annotated instanceof Class)
+ {
+ Class<?> clazz = Class.class.cast(annotated);
+ scope = new Scope(CommonLevels.CLASS, clazz);
+ }
+ else if (annotated instanceof Member)
+ {
+ Member member = (Member) annotated;
+ scope = new Scope(CommonLevels.JOINPOINT, member);
+ }
+ else
+ {
+ return ScopeKey.DEFAULT_SCOPE;
+ }
+ return new UnmodifiableScopeKey(scope);
+ }
+
+ /**
+ * Create a new AnnotatedElementMetaDataContext.
+ *
+ * @param annotated the annotated element
+ */
+ public OriginalAnnotatedElementMetaDataLoader(AnnotatedElement annotated)
+ {
+ super(getScopeKey(annotated));
+ if (annotated == null)
+ throw new IllegalArgumentException("Null annotated element");
+ this.annotated = annotated;
+ }
+
+ @SuppressWarnings("unchecked")
+ public AnnotationsItem retrieveAnnotations()
+ {
+ Annotation[] annotations = annotated.getAnnotations();
+ if (annotations.length == 0)
+ return SimpleAnnotationsItem.NO_ANNOTATIONS;
+
+ AnnotationItem[] items = new AnnotationItem[annotations.length];
+ for (int i = 0; i < items.length; ++i)
+ items[i] = new SimpleAnnotationItem(annotations[i]);
+ return new SimpleAnnotationsItem(items);
+ }
+
+ public <T extends Annotation> AnnotationItem<T> retrieveAnnotation(Class<T> annotationType)
+ {
+ T annotation = annotated.getAnnotation(annotationType);
+ if (annotation == null)
+ return null;
+ return new SimpleAnnotationItem<T>(annotation);
+ }
+
+ public MetaDataRetrieval getComponentMetaDataRetrieval(Signature signature)
+ {
+ if (signature == null)
+ return null;
+
+ if (annotated instanceof Class)
+ {
+ Class<?> clazz = Class.class.cast(annotated);
+ if (signature instanceof ConstructorSignature)
+ {
+ ConstructorSignature constructorSignature = (ConstructorSignature) signature;
+ Constructor<?> constructor = constructorSignature.getConstructor();
+ if (constructor == null)
+ constructor = SecurityActions.findConstructor(clazz, signature.getParametersTypes(clazz));
+ if (constructor == null)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Constructor with signature " + signature + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ return new OriginalAnnotatedElementMetaDataLoader(constructor);
+ }
+ else if (signature instanceof MethodSignature)
+ {
+ MethodSignature methodSignature = (MethodSignature) signature;
+ Method method = methodSignature.getMethod();
+ if (method == null)
+ method = SecurityActions.findMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
+ if (method == null)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Method with signature " + signature + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ return new OriginalAnnotatedElementMetaDataLoader(method);
+ }
+ else if (signature instanceof DeclaredMethodSignature)
+ {
+ DeclaredMethodSignature methodSignature = (DeclaredMethodSignature) signature;
+ Method method = methodSignature.getMethod();
+ if (method == null)
+ {
+ clazz = getDeclaringClass(clazz, methodSignature.getDeclaringClass());
+ if (clazz == null)
+ return null;
+ try
+ {
+ method = SecurityActions.findDeclaredMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
+ }
+ catch (NoSuchMethodException nsme)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Method with signature " + signature + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ }
+ return new OriginalAnnotatedElementMetaDataLoader(method);
+ }
+ else if (signature instanceof MethodParametersSignature)
+ {
+ MethodParametersSignature methodParametersSignature = (MethodParametersSignature) signature;
+ Method method = methodParametersSignature.getMethod();
+ if (method == null)
+ method = SecurityActions.findMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
+ if (method == null)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Method with signature " + signature + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ Annotation[][] paramAnnotations = method.getParameterAnnotations();
+ return new SimpleMetaDataLoader(paramAnnotations[methodParametersSignature.getParam()]);
+ }
+ else if (signature instanceof ConstructorParametersSignature)
+ {
+ ConstructorParametersSignature constructorParametersSignature = (ConstructorParametersSignature) signature;
+ Constructor<?> constructor = constructorParametersSignature.getConstructor();
+ if (constructor == null)
+ constructor = SecurityActions.findConstructor(clazz, signature.getParametersTypes(clazz));
+ if (constructor == null)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Constructor with signature " + signature + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
+ return new SimpleMetaDataLoader(paramAnnotations[constructorParametersSignature.getParam()]);
+ }
+ else if (signature instanceof FieldSignature)
+ {
+ FieldSignature fieldSignature = (FieldSignature) signature;
+ Field field = fieldSignature.getField();
+ if (field == null)
+ field = SecurityActions.findField(clazz, signature.getName());
+ if (field == null)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Field " + signature.getName() + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ return new OriginalAnnotatedElementMetaDataLoader(field);
+ }
+ }
+
+ if (annotated instanceof Method)
+ {
+ if (signature instanceof MethodParametersSignature)
+ {
+ Method method = (Method)annotated;
+ Annotation[][] paramAnnotations = method.getParameterAnnotations();
+ MethodParametersSignature sig = (MethodParametersSignature) signature;
+ return new SimpleMetaDataLoader(paramAnnotations[sig.getParam()]);
+ }
+ }
+
+ if (annotated instanceof Constructor)
+ {
+ if (signature instanceof ConstructorParametersSignature)
+ {
+ Constructor<?> constructor = Constructor.class.cast(annotated);
+ Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
+ ConstructorParametersSignature sig = (ConstructorParametersSignature) signature;
+ return new SimpleMetaDataLoader(paramAnnotations[sig.getParam()]);
+ }
+ }
+
+ return null;
+ }
+
+ public boolean isEmpty()
+ {
+ Annotation[] annotations = annotated.getAnnotations();
+ return annotations == null || annotations.length == 0;
+ }
+
+ public String toString()
+ {
+ JBossStringBuilder buffer = new JBossStringBuilder();
+ Strings.defaultToString(buffer, this);
+ buffer.append("[");
+ buffer.append(annotated);
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+ /**
+ * Get the declaring class from the reference class
+ *
+ * @param reference the reference class
+ * @param declaringClass the declaring class
+ * @return the class or null if the declaring class is not a super class of the reference
+ */
+ private static Class<?> getDeclaringClass(Class<?> reference, String declaringClass)
+ {
+ while (reference != null)
+ {
+ if (declaringClass.equals(reference.getName()))
+ return reference;
+
+ reference = reference.getSuperclass();
+ }
+ return null;
+ }
+
+ /**
+ * http://community.jboss.org/thread/148203
+ * Singleton be returned by AnnotatedElementMetaDataLoader.getComponentMetaDataRetrieval() when there are no annotations for the member. This is to avoid
+ * the overhead of creating a new AnnotatedElementMetaDataLoader even in those cases, something which shows up to be a big bottleneck in AS startup time,
+ * mainly due to the creation of AnnotatedElementMetaDataLoader's ScopeKey.
+ */
+ private static class NullAnnotatedElementComponentMetaDataLoader implements MetaDataRetrieval
+ {
+ final static NullAnnotatedElementComponentMetaDataLoader INSTANCE = new NullAnnotatedElementComponentMetaDataLoader();
+ final static ScopeKey nullScopeKey = new ScopeKey(new Scope(CommonLevels.JOINPOINT, INSTANCE));
+
+ final BasicAnnotationsItem noANnnotationsItem = new BasicAnnotationsItem(null, new AnnotationItem[0]);
+ final BasicMetaDatasItem noMetaDatasItem = new BasicMetaDatasItem(null, new MetaDataItem[0]);
+ final ValidTime validTime = new ValidTime();
+
+ public MetaDataRetrieval getComponentMetaDataRetrieval(Signature signature)
+ {
+ return INSTANCE;
+ }
+
+ public ScopeKey getScope()
+ {
+ return nullScopeKey;
+ }
+
+ public MetaDataRetrieval getScopedRetrieval(ScopeLevel level)
+ {
+ return INSTANCE;
+ }
+
+ public ValidTime getValidTime()
+ {
+ return validTime;
+ }
+
+ public boolean isEmpty()
+ {
+ return true;
+ }
+
+ public <T extends Annotation> AnnotationItem<T> retrieveAnnotation(Class<T> annotationType)
+ {
+ return null;
+ }
+
+ public AnnotationsItem retrieveAnnotations()
+ {
+ return noANnnotationsItem;
+ }
+
+ public AnnotationsItem retrieveAnnotationsAnnotatedWith(Class<? extends Annotation> meta)
+ {
+ return noANnnotationsItem;
+ }
+
+ public AnnotationsItem retrieveLocalAnnotations()
+ {
+ return noANnnotationsItem;
+ }
+
+ public MetaDatasItem retrieveLocalMetaData()
+ {
+ return noMetaDatasItem;
+ }
+
+ public MetaDatasItem retrieveMetaData()
+ {
+ return noMetaDatasItem;
+ }
+
+ public <T> MetaDataItem<T> retrieveMetaData(Class<T> type)
+ {
+ return null;
+ }
+
+ public MetaDataItem<?> retrieveMetaData(String name)
+ {
+ return null;
+ }
+
+ }
+}
Added: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/SecurityActions.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/SecurityActions.java (rev 0)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/SecurityActions.java 2010-02-18 16:00:28 UTC (rev 101117)
@@ -0,0 +1,141 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, 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.test.metadata.benchmark.support;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+import org.jboss.reflect.plugins.introspection.ReflectionUtils;
+
+/**
+ * SecurityActions.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class SecurityActions
+{
+ /**
+ * Find the method by name and parameters.
+ *
+ * @param clazz the class to look for method
+ * @param name the name
+ * @param parameterTypes the types
+ * @return method or null if not found
+ */
+ static Method findMethod(final Class<?> clazz, final String name, final Class<?>... parameterTypes)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ return ReflectionUtils.findMethod(clazz, name, parameterTypes);
+
+ return AccessController.doPrivileged(new PrivilegedAction<Method>()
+ {
+ public Method run()
+ {
+ return ReflectionUtils.findMethod(clazz, name, parameterTypes);
+ }
+ });
+ }
+
+ /**
+ * Find the field by name.
+ *
+ * @param clazz the class to look for field
+ * @param name the name
+ * @return field or null if not found
+ */
+ static Field findField(final Class<?> clazz, final String name)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ return ReflectionUtils.findField(clazz, name);
+
+ return AccessController.doPrivileged(new PrivilegedAction<Field>()
+ {
+ public Field run()
+ {
+ return ReflectionUtils.findField(clazz, name);
+ }
+ });
+ }
+
+ /**
+ * Find the constructor by parameters.
+ *
+ * @param clazz the class to look for constructor
+ * @param parameterTypes the types
+ * @return constructor or null if not found
+ */
+ static Constructor<?> findConstructor(final Class<?> clazz, final Class<?>... parameterTypes)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ return ReflectionUtils.findConstructor(clazz, parameterTypes);
+
+ return AccessController.doPrivileged(new PrivilegedAction<Constructor<?>>()
+ {
+ public Constructor<?> run()
+ {
+ return ReflectionUtils.findConstructor(clazz, parameterTypes);
+ }
+ });
+ }
+
+ /**
+ * Returns a method named <code>methodName</code> with params
+ * <code>parameterTypes</code> declared in the <code>declaringClass</code>.
+ * Methods with public, private, protected and package access are considered while
+ *
+ * @param declaringClass The Class declaring the method
+ * @param methodName The name of the method
+ * @param parameterTypes The parameters types accepted by the method
+ * @return found declared method
+ * @throws NoSuchMethodException If the method is not found in the <code>declaringClass</code>
+ */
+ static Method findDeclaredMethod(final Class<?> declaringClass, final String methodName, final Class<?>... parameterTypes) throws NoSuchMethodException
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ return declaringClass.getDeclaredMethod(methodName, parameterTypes);
+
+ try
+ {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Method>()
+ {
+ public Method run() throws NoSuchMethodException
+ {
+ return declaringClass.getDeclaredMethod(methodName, parameterTypes);
+ }
+ });
+ }
+ catch (PrivilegedActionException pae)
+ {
+ throw (NoSuchMethodException) pae.getException();
+ }
+ }
+}
Added: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/SingletonAnnotatedElementMetaDataLoader.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/SingletonAnnotatedElementMetaDataLoader.java (rev 0)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/support/SingletonAnnotatedElementMetaDataLoader.java 2010-02-18 16:00:28 UTC (rev 101117)
@@ -0,0 +1,388 @@
+/*
+* 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.test.metadata.benchmark.support;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+
+import org.jboss.logging.Logger;
+import org.jboss.metadata.plugins.loader.BasicMetaDataLoader;
+import org.jboss.metadata.plugins.loader.SimpleMetaDataLoader;
+import org.jboss.metadata.spi.retrieval.AnnotationItem;
+import org.jboss.metadata.spi.retrieval.AnnotationsItem;
+import org.jboss.metadata.spi.retrieval.MetaDataItem;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
+import org.jboss.metadata.spi.retrieval.MetaDatasItem;
+import org.jboss.metadata.spi.retrieval.ValidTime;
+import org.jboss.metadata.spi.retrieval.basic.BasicAnnotationsItem;
+import org.jboss.metadata.spi.retrieval.basic.BasicMetaDatasItem;
+import org.jboss.metadata.spi.retrieval.simple.SimpleAnnotationItem;
+import org.jboss.metadata.spi.retrieval.simple.SimpleAnnotationsItem;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.Scope;
+import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.scope.ScopeLevel;
+import org.jboss.metadata.spi.scope.UnmodifiableScopeKey;
+import org.jboss.metadata.spi.signature.ConstructorParametersSignature;
+import org.jboss.metadata.spi.signature.ConstructorSignature;
+import org.jboss.metadata.spi.signature.DeclaredMethodSignature;
+import org.jboss.metadata.spi.signature.FieldSignature;
+import org.jboss.metadata.spi.signature.MethodParametersSignature;
+import org.jboss.metadata.spi.signature.MethodSignature;
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.util.JBossStringBuilder;
+import org.jboss.util.Strings;
+
+/**
+ * AnnotatedElementMetaDataLoader.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 101076 $
+ */
+public class SingletonAnnotatedElementMetaDataLoader extends BasicMetaDataLoader
+{
+ /** The log */
+ private static final Logger log = Logger.getLogger(SingletonAnnotatedElementMetaDataLoader.class);
+
+ /** The annotated element */
+ private AnnotatedElement annotated;
+
+ private static final ScopeKey getScopeKey(AnnotatedElement annotated)
+ {
+ Scope scope;
+ if (annotated instanceof Class)
+ {
+ Class<?> clazz = Class.class.cast(annotated);
+ scope = new Scope(CommonLevels.CLASS, clazz);
+ }
+ else if (annotated instanceof Member)
+ {
+ Member member = (Member) annotated;
+ scope = new Scope(CommonLevels.JOINPOINT, member);
+ }
+ else
+ {
+ return ScopeKey.DEFAULT_SCOPE;
+ }
+ return new UnmodifiableScopeKey(scope);
+ }
+
+ /**
+ * Create a new AnnotatedElementMetaDataContext.
+ *
+ * @param annotated the annotated element
+ */
+ public SingletonAnnotatedElementMetaDataLoader(AnnotatedElement annotated)
+ {
+ super(getScopeKey(annotated));
+ if (annotated == null)
+ throw new IllegalArgumentException("Null annotated element");
+ this.annotated = annotated;
+ }
+
+ @SuppressWarnings("unchecked")
+ public AnnotationsItem retrieveAnnotations()
+ {
+ Annotation[] annotations = annotated.getAnnotations();
+ if (annotations.length == 0)
+ return SimpleAnnotationsItem.NO_ANNOTATIONS;
+
+ AnnotationItem[] items = new AnnotationItem[annotations.length];
+ for (int i = 0; i < items.length; ++i)
+ items[i] = new SimpleAnnotationItem(annotations[i]);
+ return new SimpleAnnotationsItem(items);
+ }
+
+ public <T extends Annotation> AnnotationItem<T> retrieveAnnotation(Class<T> annotationType)
+ {
+ T annotation = annotated.getAnnotation(annotationType);
+ if (annotation == null)
+ return null;
+ return new SimpleAnnotationItem<T>(annotation);
+ }
+
+ public MetaDataRetrieval getComponentMetaDataRetrieval(Signature signature)
+ {
+ if (signature == null)
+ return null;
+
+ if (annotated instanceof Class)
+ {
+ Class<?> clazz = Class.class.cast(annotated);
+ if (signature instanceof ConstructorSignature)
+ {
+ ConstructorSignature constructorSignature = (ConstructorSignature) signature;
+ Constructor<?> constructor = constructorSignature.getConstructor();
+ if (constructor == null)
+ constructor = SecurityActions.findConstructor(clazz, signature.getParametersTypes(clazz));
+ if (constructor == null)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Constructor with signature " + signature + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ if (constructor.getAnnotations().length == 0)
+ return NullAnnotatedElementComponentMetaDataLoader.INSTANCE;
+ return new SingletonAnnotatedElementMetaDataLoader(constructor);
+ }
+ else if (signature instanceof MethodSignature)
+ {
+ MethodSignature methodSignature = (MethodSignature) signature;
+ Method method = methodSignature.getMethod();
+ if (method == null)
+ method = SecurityActions.findMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
+ if (method == null)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Method with signature " + signature + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ if (method.getAnnotations().length == 0)
+ return NullAnnotatedElementComponentMetaDataLoader.INSTANCE;
+ return new SingletonAnnotatedElementMetaDataLoader(method);
+ }
+ else if (signature instanceof DeclaredMethodSignature)
+ {
+ DeclaredMethodSignature methodSignature = (DeclaredMethodSignature) signature;
+ Method method = methodSignature.getMethod();
+ if (method == null)
+ {
+ clazz = getDeclaringClass(clazz, methodSignature.getDeclaringClass());
+ if (clazz == null)
+ return null;
+ try
+ {
+ method = SecurityActions.findDeclaredMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
+ }
+ catch (NoSuchMethodException nsme)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Method with signature " + signature + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ }
+ if (method.getAnnotations().length == 0)
+ return NullAnnotatedElementComponentMetaDataLoader.INSTANCE;
+ return new SingletonAnnotatedElementMetaDataLoader(method);
+ }
+ else if (signature instanceof MethodParametersSignature)
+ {
+ MethodParametersSignature methodParametersSignature = (MethodParametersSignature) signature;
+ Method method = methodParametersSignature.getMethod();
+ if (method == null)
+ method = SecurityActions.findMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
+ if (method == null)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Method with signature " + signature + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ Annotation[][] paramAnnotations = method.getParameterAnnotations();
+ if (paramAnnotations[methodParametersSignature.getParam()].length == 0)
+ return NullAnnotatedElementComponentMetaDataLoader.INSTANCE;
+ return new SimpleMetaDataLoader(paramAnnotations[methodParametersSignature.getParam()]);
+ }
+ else if (signature instanceof ConstructorParametersSignature)
+ {
+ ConstructorParametersSignature constructorParametersSignature = (ConstructorParametersSignature) signature;
+ Constructor<?> constructor = constructorParametersSignature.getConstructor();
+ if (constructor == null)
+ constructor = SecurityActions.findConstructor(clazz, signature.getParametersTypes(clazz));
+ if (constructor == null)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Constructor with signature " + signature + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
+ if (paramAnnotations[constructorParametersSignature.getParam()].length == 0)
+ return NullAnnotatedElementComponentMetaDataLoader.INSTANCE;
+ return new SimpleMetaDataLoader(paramAnnotations[constructorParametersSignature.getParam()]);
+ }
+ else if (signature instanceof FieldSignature)
+ {
+ FieldSignature fieldSignature = (FieldSignature) signature;
+ Field field = fieldSignature.getField();
+ if (field == null)
+ field = SecurityActions.findField(clazz, signature.getName());
+ if (field == null)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Field " + signature.getName() + " does not exist on class " + clazz.getName());
+ return null;
+ }
+ if (field.getAnnotations().length == 0)
+ return NullAnnotatedElementComponentMetaDataLoader.INSTANCE;
+ return new SingletonAnnotatedElementMetaDataLoader(field);
+ }
+ }
+
+ if (annotated instanceof Method)
+ {
+ if (signature instanceof MethodParametersSignature)
+ {
+ Method method = (Method)annotated;
+ Annotation[][] paramAnnotations = method.getParameterAnnotations();
+ MethodParametersSignature sig = (MethodParametersSignature) signature;
+ if (paramAnnotations[sig.getParam()].length == 0)
+ return NullAnnotatedElementComponentMetaDataLoader.INSTANCE;
+ return new SimpleMetaDataLoader(paramAnnotations[sig.getParam()]);
+ }
+ }
+
+ if (annotated instanceof Constructor)
+ {
+ if (signature instanceof ConstructorParametersSignature)
+ {
+ Constructor<?> constructor = Constructor.class.cast(annotated);
+ Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
+ ConstructorParametersSignature sig = (ConstructorParametersSignature) signature;
+ if (paramAnnotations[sig.getParam()].length == 0)
+ return NullAnnotatedElementComponentMetaDataLoader.INSTANCE;
+ return new SimpleMetaDataLoader(paramAnnotations[sig.getParam()]);
+ }
+ }
+
+ return null;
+ }
+
+ public boolean isEmpty()
+ {
+ Annotation[] annotations = annotated.getAnnotations();
+ return annotations == null || annotations.length == 0;
+ }
+
+ public String toString()
+ {
+ JBossStringBuilder buffer = new JBossStringBuilder();
+ Strings.defaultToString(buffer, this);
+ buffer.append("[");
+ buffer.append(annotated);
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+ /**
+ * Get the declaring class from the reference class
+ *
+ * @param reference the reference class
+ * @param declaringClass the declaring class
+ * @return the class or null if the declaring class is not a super class of the reference
+ */
+ private static Class<?> getDeclaringClass(Class<?> reference, String declaringClass)
+ {
+ while (reference != null)
+ {
+ if (declaringClass.equals(reference.getName()))
+ return reference;
+
+ reference = reference.getSuperclass();
+ }
+ return null;
+ }
+
+ /**
+ * http://community.jboss.org/thread/148203
+ * Singleton be returned by AnnotatedElementMetaDataLoader.getComponentMetaDataRetrieval() when there are no annotations for the member. This is to avoid
+ * the overhead of creating a new AnnotatedElementMetaDataLoader even in those cases, something which shows up to be a big bottleneck in AS startup time,
+ * mainly due to the creation of AnnotatedElementMetaDataLoader's ScopeKey.
+ */
+ private static class NullAnnotatedElementComponentMetaDataLoader implements MetaDataRetrieval
+ {
+ final static NullAnnotatedElementComponentMetaDataLoader INSTANCE = new NullAnnotatedElementComponentMetaDataLoader();
+ final static ScopeKey nullScopeKey = new ScopeKey(new Scope(CommonLevels.JOINPOINT, INSTANCE));
+
+ final BasicAnnotationsItem noANnnotationsItem = new BasicAnnotationsItem(null, new AnnotationItem[0]);
+ final BasicMetaDatasItem noMetaDatasItem = new BasicMetaDatasItem(null, new MetaDataItem[0]);
+ final ValidTime validTime = new ValidTime();
+
+ public MetaDataRetrieval getComponentMetaDataRetrieval(Signature signature)
+ {
+ return INSTANCE;
+ }
+
+ public ScopeKey getScope()
+ {
+ return nullScopeKey;
+ }
+
+ public MetaDataRetrieval getScopedRetrieval(ScopeLevel level)
+ {
+ return INSTANCE;
+ }
+
+ public ValidTime getValidTime()
+ {
+ return validTime;
+ }
+
+ public boolean isEmpty()
+ {
+ return true;
+ }
+
+ public <T extends Annotation> AnnotationItem<T> retrieveAnnotation(Class<T> annotationType)
+ {
+ return null;
+ }
+
+ public AnnotationsItem retrieveAnnotations()
+ {
+ return noANnnotationsItem;
+ }
+
+ public AnnotationsItem retrieveAnnotationsAnnotatedWith(Class<? extends Annotation> meta)
+ {
+ return noANnnotationsItem;
+ }
+
+ public AnnotationsItem retrieveLocalAnnotations()
+ {
+ return noANnnotationsItem;
+ }
+
+ public MetaDatasItem retrieveLocalMetaData()
+ {
+ return noMetaDatasItem;
+ }
+
+ public MetaDatasItem retrieveMetaData()
+ {
+ return noMetaDatasItem;
+ }
+
+ public <T> MetaDataItem<T> retrieveMetaData(Class<T> type)
+ {
+ return null;
+ }
+
+ public MetaDataItem<?> retrieveMetaData(String name)
+ {
+ return null;
+ }
+
+ }
+}
Added: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/test/CreateScopeKeyBenchmark.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/test/CreateScopeKeyBenchmark.java (rev 0)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/test/CreateScopeKeyBenchmark.java 2010-02-18 16:00:28 UTC (rev 101117)
@@ -0,0 +1,60 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.test.metadata.benchmark.test;
+
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.Scope;
+import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.scope.UnmodifiableScopeKey;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class CreateScopeKeyBenchmark
+{
+ static int count = 100000;
+ public static void main(String[] args)
+ {
+ Scope[] scopes = new Scope[count];
+ for (int i = 0 ; i < count ; i++)
+ {
+ scopes[i] = new Scope(CommonLevels.JOINPOINT, i);
+ }
+
+ ScopeKey[] keys = new ScopeKey[count];
+ long start = System.currentTimeMillis();
+ for (int i = 0 ; i < count ; i++)
+ {
+ keys[i] = new ScopeKey(scopes[i]);
+ }
+ System.out.println("---> " + (System.currentTimeMillis() - start));
+ for (int i = 0 ; i < count ; i++)
+ {
+ if (keys[i] == null)
+ throw new IllegalStateException();
+ if (keys[i].getScopes().iterator().next().equals(scopes[i]) == false)
+ throw new IllegalStateException();
+ }
+ }
+}
Added: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/test/CreateUnmodifiableScopeKeyBenchmark.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/test/CreateUnmodifiableScopeKeyBenchmark.java (rev 0)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/test/CreateUnmodifiableScopeKeyBenchmark.java 2010-02-18 16:00:28 UTC (rev 101117)
@@ -0,0 +1,61 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.test.metadata.benchmark.test;
+
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.Scope;
+import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.scope.UnmodifiableScopeKey;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class CreateUnmodifiableScopeKeyBenchmark
+{
+ static int count = 100000;
+ public static void main(String[] args)
+ {
+ Scope[] scopes = new Scope[count];
+ for (int i = 0 ; i < count ; i++)
+ {
+ scopes[i] = new Scope(CommonLevels.JOINPOINT, i);
+ }
+
+ ScopeKey[] keys = new ScopeKey[count];
+ long start = System.currentTimeMillis();
+ for (int i = 0 ; i < count ; i++)
+ {
+ keys[i] = new UnmodifiableScopeKey(scopes[i]);
+ }
+ System.out.println("---> " + (System.currentTimeMillis() - start));
+ for (int i = 0 ; i < count ; i++)
+ {
+ if (keys[i] == null)
+ throw new IllegalStateException();
+ if (keys[i].getScopes().iterator().next().equals(scopes[i]) == false)
+ throw new IllegalStateException();
+ }
+ }
+
+}
Added: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/test/NoComponentMetaDataCachingMetaDataContextBenchmark.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/test/NoComponentMetaDataCachingMetaDataContextBenchmark.java (rev 0)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/benchmark/test/NoComponentMetaDataCachingMetaDataContextBenchmark.java 2010-02-18 16:00:28 UTC (rev 101117)
@@ -0,0 +1,184 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.test.metadata.benchmark.test;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.metadata.plugins.context.AbstractMetaDataContext;
+import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
+import org.jboss.metadata.plugins.loader.reflection.AnnotatedElementMetaDataLoader;
+import org.jboss.metadata.plugins.repository.AbstractMetaDataRepository;
+import org.jboss.metadata.plugins.repository.basic.BasicMetaDataRepository;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrievalToMetaDataBridge;
+import org.jboss.metadata.spi.retrieval.RetrievalUtils;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.Scope;
+import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.signature.DeclaredMethodSignature;
+import org.jboss.test.metadata.benchmark.support.NullAnnotatedElementMetaDataLoader;
+import org.jboss.test.metadata.benchmark.support.OriginalAnnotatedElementMetaDataLoader;
+import org.jboss.test.metadata.benchmark.support.SingletonAnnotatedElementMetaDataLoader;
+import org.jboss.test.metadata.benchmark.support.ClassNoMethodAnnotation1;
+import org.jboss.test.metadata.benchmark.support.ClassNoMethodAnnotation2;
+import org.jboss.test.metadata.benchmark.support.ClassNoMethodAnnotation3;
+import org.jboss.test.metadata.benchmark.support.ClassNoMethodAnnotation4;
+import org.jboss.test.metadata.benchmark.support.ClassNoMethodAnnotation5;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class NoComponentMetaDataCachingMetaDataContextBenchmark extends TestCase
+{
+// ClassRetrieval classRetrieval = ClassRetrieval.SINGLETON;
+// ClassRetrieval classRetrieval = ClassRetrieval.ORIGINAL;
+// ClassRetrieval classRetrieval = ClassRetrieval.NULL;
+ ClassRetrieval classRetrieval = ClassRetrieval.LATEST;
+
+ BasicMetaDataRepository repository = new BasicMetaDataRepository();
+
+// boolean caching = true;
+ boolean caching = false;
+
+ int iterations = 1000;
+ int count = 1000;
+
+ private MetaDataRetrieval createClassRetrieval(Class<?> clazz)
+ {
+ if (classRetrieval == ClassRetrieval.NULL)
+ return new NullAnnotatedElementMetaDataLoader(clazz);
+ if (classRetrieval == ClassRetrieval.SINGLETON)
+ return new SingletonAnnotatedElementMetaDataLoader(clazz);
+ if (classRetrieval == ClassRetrieval.ORIGINAL)
+ return new OriginalAnnotatedElementMetaDataLoader(clazz);
+ if (classRetrieval == ClassRetrieval.LATEST)
+ return new AnnotatedElementMetaDataLoader(clazz);
+
+ throw new RuntimeException();
+ }
+
+
+
+ public void testContexts()
+ {
+ List<MetaDataWrapper> data = createMetaDatas();
+
+ assertEquals(count, data.size());
+
+ long start = System.currentTimeMillis();
+
+ for (int i = 0 ; i < iterations ; i++)
+ {
+ for (MetaDataWrapper wrapper : data)
+ {
+ for (Method m : wrapper.getClazz().getDeclaredMethods())
+ {
+ DeclaredMethodSignature sig = new DeclaredMethodSignature(m);
+ MetaData component = wrapper.getMetaData().getComponentMetaData(sig);
+ if (component != null && component.isEmpty() == false)
+ throw new IllegalStateException("Expected null MD");
+ }
+ }
+ }
+
+ System.out.println("------>" + (System.currentTimeMillis() - start));
+ }
+
+ private List<MetaDataWrapper> createMetaDatas()
+ {
+ List<MetaDataWrapper> metaDatas = new ArrayList<MetaDataWrapper>();
+
+ MemoryMetaDataLoader jvm = new MemoryMetaDataLoader(new ScopeKey(new Scope(CommonLevels.JVM, "THIS")));
+ for (int i = 0 ; i < count ; i++)
+ {
+ List<MetaDataRetrieval> retrievals = new ArrayList<MetaDataRetrieval>();
+
+ retrievals.add(jvm);
+ retrievals.add(createClassRetrieval(getAnnotatedElementClass(i)));
+ retrievals.add(new MemoryMetaDataLoader(new ScopeKey(new Scope(CommonLevels.INSTANCE, "Bean" + i))));
+
+ AbstractMetaDataContext context = new AbstractMetaDataContext(null, retrievals);
+ MetaData metaData = new MetaDataRetrievalToMetaDataBridge(context);
+
+ if (caching)
+ metaData = RetrievalUtils.createCachedMetaData(metaData);
+
+ MetaDataWrapper wrapped = new MetaDataWrapper(metaData, getAnnotatedElementClass(i));
+ metaDatas.add(wrapped);
+ }
+
+ return metaDatas;
+ }
+ private Class<?> getAnnotatedElementClass(int i)
+ {
+ int mod = i % 5;
+ switch (mod)
+ {
+ case 0 :
+ return ClassNoMethodAnnotation1.class;
+ case 1 :
+ return ClassNoMethodAnnotation2.class;
+ case 2 :
+ return ClassNoMethodAnnotation3.class;
+ case 3 :
+ return ClassNoMethodAnnotation4.class;
+ case 4 :
+ return ClassNoMethodAnnotation5.class;
+ default:
+ throw new IllegalStateException();
+ }
+ }
+
+ private static class MetaDataWrapper
+ {
+ MetaData metaData;
+ Class<?> clazz;
+
+ public MetaDataWrapper(MetaData metaData, Class<?> clazz)
+ {
+ this.metaData = metaData;
+ this.clazz = clazz;
+ }
+
+ public MetaData getMetaData()
+ {
+ return metaData;
+ }
+
+ public Class<?> getClazz()
+ {
+ return clazz;
+ }
+ }
+
+ private enum ClassRetrieval
+ {
+ ORIGINAL, NULL, SINGLETON, LATEST
+ }
+}
More information about the jboss-cvs-commits
mailing list