Spring for .NET Community Forums    

Go Back   Spring for .NET Community Forums > General > AOP (Aspect Oriented Programming)

Reply
 
Thread Tools Display Modes
  #1  
Old 04-17-2009, 01:54 PM
graphicsxp graphicsxp is offline
Senior Member
Spring User
 
Join Date: Mar 2009
Posts: 115
Default Advice called multiple times when using AttributeMatchMethodPointCut

Hi,

I'm trying to use Attribute pointcut in order to apply my aroundAdvice to only the functions in my service which are decorated with a [SessionScope] attribute.

Since I've done that, the code goes in the aroundAdvice 3 times before it goes into the invoked method ! If I don't use the pointcut, the aroundAdvice is only hit once before the invoked method executes and returns fine.

Am I doing something wrong ?


here's my xml :

HTML Code:
 <object id="pointCut" type="Spring.Aop.Support.DefaultPointcutAdvisor, Spring.Aop" >
    <property name="Pointcut">
      <object type="Spring.Aop.Support.AttributeMatchMethodPointcut, Spring.Aop">
        <property name="Attribute" value="Metrica.SpringExtension.SessionScopeEx.SessionScopeAttribute, Metrica.SpringExtension"/>
      </object>
    </property>
    <property name="advice" ref="aroundAdvice" />           
  </object>

  <object id="aroundAdvice" 
          type="Metrica.Service.Aspects.MetricaServiceAroundAdvice, Metrica.Service" />    
  
  <object id="metricaService" type="Spring.Aop.Framework.ProxyFactoryObject">
    <property name="Target">
      <!-- The Metrica service object which is injected all the necessary DAO's. -->
      <object type="Metrica.Service.MetricaService, Metrica.Service" singleton="true">
        <property name="myDatabaseDao" ref="DatabaseDao" />
      </object>
    </property>
    <property name="InterceptorNames">
      <list>        
        <value>aroundAdvice</value>
      </list>
    </property>    
  </object>
Reply With Quote
  #2  
Old 06-23-2009, 02:45 PM
sybarite sybarite is offline
Junior Member
New User
 
Join Date: Jul 2006
Location: Vienna
Posts: 8
Default same problem a bit different config

I had the same problem and now have a similar problem also with a spring config using "DefaultAdvisorAutoProxyCreator"

Code:
<!-- protocol advisor -->
  <object id="protocolAdvisor" type="Spring.Aop.Support.AttributeMatchMethodPointcutAdvisor, Spring.Aop">
    <property name="Advice">
      <object type="CN.Core.Aspects.ProtocolAdvice, CN.Core" />
    </property>
    <property name="Attribute"
              value="CN.Core.Aspects.ProtocolAttribute, CN.Core" />
  </object>

  <!-- AutoProxy definition -->
  <object type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoProxyCreator, Spring.Aop" />
after changing the config to that, the advice is executed two instead of three times. What confuses me, is the fact, that the target of the first call is a CompositionAopProxy object and the second time the real target appears. There must be some kind of intransparent chaining but I've not found the source of that. The business object itself is injected into another service object. But beside that, the whole staff looks like the Spring.NET 1.2.0 sample.
Reply With Quote
  #3  
Old 06-24-2009, 09:04 AM
sybarite sybarite is offline
Junior Member
New User
 
Join Date: Jul 2006
Location: Vienna
Posts: 8
Default Transaction attribute and automatic proxy

Maybe the first appearing target (the proxy) is based on the following line in the config:

Code:
<tx:attribute-driven transaction-manager="transactionManager" />
But i still need the possibility of Spring transactions as well. Is there a solution to the problem, when one proxy is based on another proxy?
Reply With Quote
  #4  
Old 06-24-2009, 07:30 PM
Erich Eichinger Erich Eichinger is offline
Senior Member
Spring User
 
Join Date: Jan 2006
Location: Oslo, Norway
Posts: 1,337
Default

Hi,

I am currently looking into this. Actually the same advice instance shouldn't be called multiple - but one part of the issue is, that <tx:attribute-driven /> already registers a DefaultAutoProxyCreator instance internally. Registering a second instance manually is at least not necessary. Also the DefaultAutoProxyCreator automatically scans the context for IAdvisor and IAdvisors instances and applies them (according to their associated pointcut only of course). An alternative to using <tx:attribute-driven /> is to use e.g. an ObjectNameAutoProxyCreator:
Code:
<object id="txAutoProxyCreator" 
        type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator, Spring.Aop">
  <property name="ObjectNames">
    <list>
      <idref local="...."/>
    </list>
  </property>
  <property name="InterceptorNames">
    <list>
      <idref local="txInterceptor"/>
    </list>
  </property>
</object>

<object id="txInterceptor" 
        type="Spring.Transaction.Interceptor.TransactionInterceptor, Spring.Data">
  <property name="TransactionManager" ref="txManager"/>
  <property name="TransactionAttributeSource" ref="txAttributeSource"/>
</object>

<object id="txAttributeSource" type="Spring.Transaction.Interceptor.AttributeTransactionAttributeSource, Spring.Data" />

<object id="txManager" type="..."/>
I will ping back here as soon as I investigated the multiple advice execution a bit more.

hth,
Erich
Reply With Quote
  #5  
Old 06-24-2009, 09:48 PM
Erich Eichinger Erich Eichinger is offline
Senior Member
Spring User
 
Join Date: Jan 2006
Location: Oslo, Norway
Posts: 1,337
Default

Quote:
Originally Posted by graphicsxp View Post
I'm trying to use Attribute pointcut in order to apply my aroundAdvice to only the functions in my service which are decorated with a [SessionScope] attribute.

Since I've done that, the code goes in the aroundAdvice 3 times before it goes into the invoked method ! If I don't use the pointcut, the aroundAdvice is only hit once before the invoked method executes and returns fine.
plz post more of your config. Do you use <tx:attribute-driven> somewhere? Any other IAdvisor instances in your config?

-Erich
Reply With Quote
  #6  
Old 06-25-2009, 08:26 AM
sybarite sybarite is offline
Junior Member
New User
 
Join Date: Jul 2006
Location: Vienna
Posts: 8
Default problem solved!

thanks Erich! That was nearly the same what I thought without having a deep look into the spring sources

I have changed my configuration of the transaction stuff and now all works pretty fine. I wonder, that nobody else has ever encountered that problem. It would be nice, if the "DefaultAdvisorAutoProxyCreator" verifies that it is not called twice.
Reply With Quote
  #7  
Old 06-25-2009, 09:00 AM
Erich Eichinger Erich Eichinger is offline
Senior Member
Spring User
 
Join Date: Jan 2006
Location: Oslo, Norway
Posts: 1,337
Default

Quote:
I wonder, that nobody else has ever encountered that problem.
same here ;-). I am about to commit the code to avoid advice duplication when "double-proxying". So you still may end up with a proxy being proxied (which is perfectly legal) but duplicate advices will be removed from the "outer" proxy.

I recorded this as SPRNET-1221. An implementation for a DAAPC that does not interfere with user configs is TBD though.

-Erich
Reply With Quote
  #8  
Old 06-26-2009, 12:40 AM
nisbus nisbus is offline
Junior Member
New User
 
Join Date: Jun 2009
Posts: 9
Default Double triggering

I'm getting the same results (advice triggering twice for methods decorated with Debug or Publish) with my IMethodInterceptor and my IAfterReturningAdvice advices:

<!--AOP-->
<object id="PublishAdvice" type="Spring.Aop.Support.AttributeMatchMethodPoint cutAdvisor, Spring.Aop">
<property name="advice">
<object type="Domain.Aop.PublishAdvice,Domain"/>
</property>
<property name="attribute" value="Domain.Aop.PublishAttribute"/>
</object>

<object id="DebugAdvice" type="Spring.Aop.Support.AttributeMatchMethodPoint cutAdvisor, Spring.Aop">
<property name="advice">
<object type="Domain.Aop.DebugAdvice,Domain"/>
</property>
<property name="attribute" value="Domain.Aop.DebugAttribute"/>
</object>

<!--TRANSACTIONS-->
<object id="transactionManager"
type="Spring.Data.Core.TxScopeTransactionManager,S pring.Data">
</object>

<object id="autoProxyCreator"
type="Spring.Aop.Framework.AutoProxy.DefaultAdviso rAutoProxyCreator, Spring.Aop">
</object>

<object id="transactionAdvisor"
type="Spring.Transaction.Interceptor.TransactionAt tributeSourceAdvisor, Spring.Data">
<property name="TransactionInterceptor" ref="transactionInterceptor"/>
</object>


<!-- Transaction Interceptor -->
<object id="transactionInterceptor"
type="Spring.Transaction.Interceptor.TransactionIn terceptor, Spring.Data">
<property name="TransactionManager" ref="transactionManager"/>
<property name="TransactionAttributeSource" ref="attributeTransactionAttributeSource"/>
</object>

<object id="attributeTransactionAttributeSource"
type="Spring.Transaction.Interceptor.AttributesTra nsactionAttributeSource, Spring.Data">
</object>

I don't get what I'm doing wrong??

thanks,
nisbus
Reply With Quote
  #9  
Old 06-26-2009, 01:21 AM
nisbus nisbus is offline
Junior Member
New User
 
Join Date: Jun 2009
Posts: 9
Default

Sorry, my bad, I was actually raising the method twice (through context events) so there is no double triggering (except in my code)
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:10 AM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.