-
1. Re: Interceptors vs. point cuts
nickarls Nov 14, 2009 8:23 PM (in response to asookazian)Stereotypes will get you started.
One option is to have an extension that listens to the beans at bootstrap and applies interceptor binding if the regexp matches, I suppose...
-
2. Re: Interceptors vs. point cuts
gavin.king Nov 14, 2009 9:38 PM (in response to asookazian)
For example, the pointcut expression:call(void Foo.make*(..)) || call(String Bar.get*(..))
Now this is just a perfect example of broken AOP. By giving my method a name that begins with the common English word
make
, I totally change its semantics! How the f*** is someone coming along later and trying to maintain this awful mess supposed to know that if they change the name of this method, they will completely break their code?This is what your supposedly
Very good book
recommends? Well, I suppose they let just about anybody write books these days :-/Embedding special semantics into naming conventions is always a bad idea. Don't do it.
No, that's not quite right. What I mean to say is: don't do it ever. And if anybody tells you to do it, ignore everything else they tell you.
how would you implement a similar solution using CDI? I'm guessing via XML?You annotate the methods that this special semantic applies to @MySpecialSemantic. And your code is thereby maintainable.
And you don't have to guess. You can read the docs or the spec to discover this.
-
3. Re: Interceptors vs. point cuts
asookazian Nov 14, 2009 11:04 PM (in response to asookazian)
Gavin King wrote on Nov 14, 2009 21:38:
Now this is just a perfect example of broken AOP. By giving my method a name that begins with the common English wordmake
, I totally change its semantics! How the f*** is someone coming along later and trying to maintain this awful mess supposed to know that if they change the name of this method, they will completely break their code?
This is what your supposedlyVery good book
recommends? Well, I suppose they let just about anybody write books these days :-/Ok, ok. I knew you'd have a strong comeback on that one. I don't know why, but I am partially fascinated by AOP. It's like I try to find a way to make it seem like it's the preferable way of dealing with orthogonal or cross-cutting concerns. This was the 2nd ed. of the book btw, it's a Manning book and I think most of the Manning books are very well written. I find it interesting that it didn't cover Guice or CDI as far as I could tell. But a book on CDI/Weld would not cover AOP either, no?
But you have a very good point about breaking the code. It's much easier to break the code in a project using XML (or separate types dedicated to advices, pointcuts, etc) rather than annotations. Annotations are right in front of your eyes for the type in question and are type-safe. What I'm concerned about with the
annotational
approach is having to apply the annotations to each type one by one. But I guess I'm likely missing something (like stereotypes or @MySpecialSemantic?)But I'm still wondering if the author had a point about the lack of pointcuts in EJB interceptor (or CDI?) being a significant disadvantage. I don't have the book in front of me but there is something about the join point context and having access to arguments.
I'll be honest, AOP is definitely very complicated and overly complex. AspectJ has its own ajc compiler as its an extension of Java but is not required with annotations. I'm wondering how popular it will become ultimately (there was even a graph in the beginning of the book showing how popular AOP had become, then declined, then up again). But even JBoss AOP is there.
How does JBoss AOP interact with CDI?? or totally separate project?
-
4. Re: Interceptors vs. point cuts
asookazian Nov 15, 2009 5:59 AM (in response to asookazian)Apparently Bill Burke and others are interested in JBoss AOP:
<aop> <aspect class="org.jboss.aspects.OnewayAspect"/> <bind pointcut="execution(void *->@org.jboss.Oneway(..))"> <advice name="oneway" aspect="org.jboss.aspects.OnewayAspect"/> </bind> </aop>
there's that fantastical pointcut in full effect in JBoss AOP.
who actually uses JBoss AOP, you don't really hear about it much...
-
5. Re: Interceptors vs. point cuts
gavin.king Nov 15, 2009 8:05 AM (in response to asookazian)pointcut="execution(void *->@org.jboss.Oneway(..))"
there's that fantastical pointcut in full effect in JBoss AOP.And here we have an example of
good
AOP. This pointcut is doing exactly what a CDI interceptor binding does. It is binding an interceptor, OnewayAspect, to methods with an annotation, @Oneway.Of course, in CDI, you can do this without some ugly piece XML containing an embedded expression in some foreign expression language, and without needing to know what words like
advice
,point cut
andaspect
mean. -
6. Re: Interceptors vs. point cuts
asookazian Nov 15, 2009 6:09 PM (in response to asookazian)It would be beneficial if you wrote a blog comparing/contrasting Spring AOP or JBoss AOP (or AOP in general) vs. CDI interceptors. With a concrete example, of course. thx.