[Logo] Terracotta Discussion Forums
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
terracotta anotations  XML
Forum Index -> General
Author Message
palko

journeyman

Joined: 10/24/2008 06:28:26
Messages: 11
Offline

Hi
i configured our application to use terracotta annotations folowing http://www.terracotta.org/web/display/docs/Annotations

It's web application on tomcat, terracotta 2.7, java 6

I got a lots of errors when trying to load various classes and check them for annotation.
Is there a way in terracotta to narrow scope where to look for annotations (typical in spring, seam and other frameworks). If we can set to look only to our package startup will be faster and we get rid of errors as well i guess or is the problem somewhere else?

Thanks
Palko
We get errors like
Code:
 ava.lang.Exception: could not read class [javax.ejb.Stateful] as byte array
 	at com.tc.backport175.bytecode.DefaultBytecodeProvider.getBytecode(DefaultBytecodeProvider.java:42)
 	at com.tc.backport175.bytecode.AnnotationReader.getBytecodeFor(AnnotationReader.java:168)
 	at com.tc.backport175.bytecode.AnnotationDefaults.getDefaults(AnnotationDefaults.java:50)
 	at com.tc.backport175.bytecode.AnnotationReader$AnnotationBuilderVisitor.visitEnd(AnnotationReader.java:1140)
 	at com.tc.asm.ClassReader.readAnnotationValues(ClassReader.java:1535)
 	at com.tc.asm.ClassReader.accept(ClassReader.java:580)
 	at com.tc.asm.ClassReader.accept(ClassReader.java:420)
 	at com.tc.backport175.bytecode.AnnotationReader.parse(AnnotationReader.java:944)
 	at com.tc.backport175.bytecode.AnnotationReader.<init>(AnnotationReader.java:958)
 	at com.tc.backport175.bytecode.AnnotationReader.getReaderFor(AnnotationReader.java:209)
 	at com.tc.backport175.bytecode.AnnotationReader.getReaderFor(AnnotationReader.java:193)
 	at com.tc.aspectwerkz.reflect.impl.asm.AsmClassInfo.getAnnotationReader(AsmClassInfo.java:968)
 	at com.tc.aspectwerkz.reflect.impl.asm.AsmFieldInfo.getAnnotations(AsmFieldInfo.java:96)
 	at com.tc.aspectwerkz.expression.ExpressionVisitor.visitAttributes(ExpressionVisitor.java:815)
 	at com.tc.aspectwerkz.expression.ExpressionVisitor.visitAnnotatedNode(ExpressionVisitor.java:1021)
 	at com.tc.aspectwerkz.expression.ExpressionVisitor.visit(ExpressionVisitor.java:171)
 	at com.tc.aspectwerkz.expression.ast.ASTGet.jjtAccept(ASTGet.java:22)
 	at com.tc.aspectwerkz.expression.ExpressionVisitor.visit(ExpressionVisitor.java:100)
 	at com.tc.aspectwerkz.expression.ast.ASTExpression.jjtAccept(ASTExpression.java:22)
 	at com.tc.aspectwerkz.expression.ExpressionVisitor.visit(ExpressionVisitor.java:88)
 	at com.tc.aspectwerkz.expression.ExpressionVisitor.match(ExpressionVisitor.java:74)
 	at com.tc.object.config.Root.matches(Root.java:94)
 	at com.tc.object.config.StandardDSOClientConfigHelperImpl.findMatchingRootDefinition(StandardDSOClientConfigHelperImpl.java:997)
 	at com.tc.object.config.StandardDSOClientConfigHelperImpl.classContainsAnyRoots(StandardDSOClientConfigHelperImpl.java:1006)
 	at com.tc.object.config.StandardDSOClientConfigHelperImpl.shouldBeAdapted(StandardDSOClientConfigHelperImpl.java:1236)
 	at com.tc.object.bytecode.hook.impl.DefaultWeavingStrategy.transform(DefaultWeavingStrategy.java:139)
 	at com.tc.object.bytecode.hook.impl.DSOContextImpl.preProcess(DSOContextImpl.java:170)
 	at com.tc.object.bytecode.hook.impl.ClassProcessorHelper.defineClass0Pre(ClassProcessorHelper.java:678)
 	at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
 
 

tgautier

seraphim

Joined: 06/05/2006 12:19:26
Messages: 1781
Offline

If I am not mistaken this looks to be similar to:

http://forums.terracotta.org/forums/posts/list/1523.page


[WWW]
palko

journeyman

Joined: 10/24/2008 06:28:26
Messages: 11
Offline

Yes that is the same problem. Any solution for it?
tgautier

seraphim

Joined: 06/05/2006 12:19:26
Messages: 1781
Offline

Well, it's not clear yet what the problem is - as posted by Alex in the other thread, if there is any way to reproduce this easily we can look at it.

Best to file a JIRA for us to track it if you can provide a reproducible test case.
[WWW]
palko

journeyman

Joined: 10/24/2008 06:28:26
Messages: 11
Offline

Bug report created with application example to reproduce the problem

http://jira.terracotta.org/jira/browse/CDV-1032
gkeim

ophanim

Joined: 12/05/2006 10:22:37
Messages: 685
Location: Terracotta, Inc.
Offline

You are instrumenting everything:

<include>
<honor-transient>true</honor-transient>
<class-expression>*..*</class-expression>
</include>

If you just instrument those types that are going into the session, you will avoid this problem.

Gary Keim (terracotta developer) Want to post to this forum? Join the Terracotta Community
palko

journeyman

Joined: 10/24/2008 06:28:26
Messages: 11
Offline

No that's not true, instrumenting all classes doesn't cause the error. It happens when terracotta is seeking for annotations not during instrumenting. Sorry for the confusion with this, i copied the terracotta conf from my another project i should have clean it.

Anyway i have changed the configuration to instrument only one class which holds the terracotta root. Session is not shared in this example at all. Its just one POJO class. I made the tc-config as simple as possible and problem still persists

I have prepared new war in jira which is more simple and if annotation tim is inside tc-config then it produces errors if it is commented than application starts without problems and you can access index.html, index.jsp

new tc-config
Code:
 <tc:tc-config xmlns:tc="http://www.terracotta.org/config"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-4.xsd">
   <servers>
     <server host="localhost">
       <data>%(user.dir)/terracotta/server-data</data>
       <logs>%(user.dir)/terracotta/logs</logs>
     </server>
   </servers>
   <clients>
     <logs>%(user.dir)/logs/terracotta</logs>
     <statistics>%(user.dir)/logs/terracotta/client-statistics/%D</statistics>
     <modules>      
       <module name="tim-annotations" version="1.2.0" />
     </modules>
   </clients>
   <application>
     <dso>      
       <instrumented-classes>
         <include>
           <honor-transient>true</honor-transient>
           <class-expression>test.TestClass</class-expression>
         </include>    
       </instrumented-classes>      
       <roots>
         <root>
           <field-name>test.TestClass.map</field-name>
         </root>
       </roots>      
     </dso>
   </application>
 </tc:tc-config>
 
gkeim

ophanim

Joined: 12/05/2006 10:22:37
Messages: 685
Location: Terracotta, Inc.
Offline

I'm unable to deploy your test.war... it's missing some things in WEB-INF/lib such as javax.persistence, javax.transaction, hibernate-validate, and others. I finally gave up at that point. Can you provide a fully deployable version?

Gary Keim (terracotta developer) Want to post to this forum? Join the Terracotta Community
palko

journeyman

Joined: 10/24/2008 06:28:26
Messages: 11
Offline

Hi i have uploaded two wars first was wrong (not all libraries, sorry). If you use the correct one (bigger) you should not have any problems.

Direct link to correct file in jira
http://jira.terracotta.org/jira/secure/attachment/12568/terracotta-anotations.war
Palko
gkeim

ophanim

Joined: 12/05/2006 10:22:37
Messages: 685
Location: Terracotta, Inc.
Offline

Still not deploying.

Caused by: java.lang.ClassNotFoundException: javax.faces.component.UIComponent

Gary Keim (terracotta developer) Want to post to this forum? Join the Terracotta Community
palko

journeyman

Joined: 10/24/2008 06:28:26
Messages: 11
Offline

I have included the jsf libraries even though i don't need them to run the example. Are you using tomcat 6?

New war
http://jira.terracotta.org/jira/secure/attachment/12574/terracotta-anotations.war
gkeim

ophanim

Joined: 12/05/2006 10:22:37
Messages: 685
Location: Terracotta, Inc.
Offline

Yes, tomcat-6.0.16, but it doesn't matter.

You are correct that Aspectwerks is inspecting every class as it's loaded, which makes a ton of sense since the tim-annotations configuration contains patterns that contain wildcards. For instance:

<include>
<class-expression>@org.terracotta.modules.annotations.InstrumentedClass *</class-expression>
</include>
 

If you look at https://svn.terracotta.org/repo/forge/projects/tim-annotations/branches/tc-2.7/src/main/resources/terracotta.xml you can see the config that is applied. What you can do is create a custom version of tim-annotations that limits the wildcard portion of the expressions to your packages. If you work at Acme Solutions, you could create acme-annotations containing patterns like:

<include>
<class-expression>@org.terracotta.modules.annotations.InstrumentedClass com.acme..*</class-expression>
</include>
 

tim-annotations is a config-only TIM, which means it's bacically a ZIP file containing a manifest and a config file.

I also wonder if using tim-annotations adversely affects startup time.


Gary Keim (terracotta developer) Want to post to this forum? Join the Terracotta Community
tgautier

seraphim

Joined: 06/05/2006 12:19:26
Messages: 1781
Offline

I must admit I am slightly confused by all of this. I may be wrong, but Terracotta (AspectWerkz) does not to my knowledge look for annotations.

As I understand it, the rules specified in the tc-config have to be analyzed to see if the class matches, and then if so apply the appropriate instrumentation.

In other words, your Java VM loads class Foo. At this time Terracotta inspects class Foo against all the rules in the tc-config.xml -- this process does not happen in reverse - e.g. the classes are not searched for or "loaded" by Terracotta.

Which means it doesn't matter if your rule is:

A:
Code:
<include> 
 <class-expression>@org.terracotta.modules.annotations.InstrumentedClass com.acme..*</class-expression> 
 </include> 
 


or

B:
Code:
 <include> 
 <class-expression>@org.terracotta.modules.annotations.InstrumentedClass *</class-expression> 
 </include> 
 


Either one of these is just a rule that is a pattern match expression applied to the class. When the class is loaded, I can't see how it matters if your config contains version A or version B, the check still has to be applied to see if the rule matches.

What I am saying goes back to some earlier assertions made in this thread, namely:

If we can set to look only to our package startup will be faster and we get rid of errors as well i guess or is the problem somewhere else?
 


No I wouldn't think so - every class loaded must be matched against the ruleset.

Instrumentation happens after the rule matches, and takes time, so minimizing the number of classes that match your ruleset - e.g. the number of classes you specify to be instrumented - will improve startup time by reducing instrumentation time, but it's not possible or advantageous to "limit the search" as such a notion does not exist.





[WWW]
palko

journeyman

Joined: 10/24/2008 06:28:26
Messages: 11
Offline

Hi,
Thank you for pointing me to the right direction.

I have adjusted terracotta.xml in tim-annotations. I had to change Root part, instrumented classes part as follows and everything works fine.
Code:
 <instrumented-classes>
     <include>
       <class-expression>@org.terracotta.modules.annotations.InstrumentedClass com.gsx..*</class-expression>
     </include>
     <include>
       <class-expression>@org.terracotta.modules.annotations.InstrumentedClass @org.terracotta.modules.annotations.HonorTransient com.gsx..*</class-expression>
       <honor-transient>true</honor-transient>
     </include>
   </instrumented-classes>
 <roots>
     <root>
       <field-expression>@org.terracotta.modules.annotations.Root * com.gsx..*.* </field-expression>
     </root>
   </roots>
 

Using this configuration in module my example works and annotations are correctly recognized in classes withing com.gsx.package. I wonder should i limit
wildcards inside locks and distributed-methods part? It seems its not necessary but might be clearer after.

I still get this warning not sure why but it doesn't cause any problem.
Code:
 AW::WARNING - could not load class [javax/ejb/SessionSynchronization] as a resource in loader [WebappClassLoader
   delegate: false
   repositories:
     /WEB-INF/classes/
 ----------> Parent Classloader:
 org.apache.catalina.loader.StandardClassLoader@13a30bd
 



I also wonder if using tim-annotations adversely affects startup time.
 


In my experience it affects start up time. After wildcard limitations tomcat seems to be starting much faster and of course application is actually starting before it didn't.


Either one of these is just a rule that is a pattern match expression applied to the class. When the class is loaded, I can't see how it matters if your config contains version A or version B, the check still has to be applied to see if the rule matches.

No I wouldn't think so - every class loaded must be matched against the rule set.
 

I guess what was happening is that aspectwerkz was not limited to package but only to annotation so it must inspect all classes available to find out whether they match given annotation. In our case what happened is we use seam framework and it can be used inside ejb j2ee server working with EJB beans but also just in tomcat without EJB at all. I think inside seam are some compiled dependencies to EJB classes. We don't use ejb in our environment so this classes are not available at runtime but still aspectwerkz was trying to load and inspect them for annotations, loading obviously failed because they were not available.

Some suggestion:
Spring framework provides in xml configuration like:
Code:
 <context:component-scan base-package="org.example"/>
 

You can narrow scanning for annotations for your package only. If you could provide something similar so i could configure it on my tc-config.xml and tim-annotations module would load it and use it to reduce wildcards for scanning it would be great. People don't need after that creating new module even tough its pretty easy in this case.
 
Forum Index -> General
Go to:   
Powered by JForum 2.1.7 © JForum Team