Beauty Is in the Eye of the Beholder
Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.
The content has been bookmarked!
There was an error bookmarking this content! Please retry.
Posted by Floyd Marinescu on Aug 09, 2006
Adrian Colyer, AspectJ lead and Chief Scientist at Interface21 has contributed an excellent article which shows how to use Spring 2's new AspectJ integration features followed by a roadmap for the adoption of Aspect Oriented Programming on an enterprise project, with lots of specific examples of how and where to apply Aspects.
Adoption of AOP can proceed in a number of phases: start out by taking advantage of aspects that Spring supplies out-of-the-box, and then you can add your own @AspectJ aspects using Spring AOP in the web, service, and data-access layers. AspectJ itself can be used to improve development productivity without introducing any runtime dependency on AspectJ. Going further, infrastructural requirements that cut across multiple layers of your application can be simply implemented using AspectJ aspects. Finally, you can use aspects to simplify the implementation of your domain model itself.Read Simplifying Enterprise Apps with Spring 2 and AspectJ. See also infoq.com/spring, infoq.com/aop
Monitor your Production Java App - includes JMX! Low Overhead - Free download
NOSQL, The Web And The Enterprise
Improve Java Garbage Collection, Runtime Execution, and JVM visibility with Zing
In today’s hyper-competitive world, later may be too late to adopt Agile development and this Roadmap for Success will help you get started. Download "Agile Development: A Manager's Roadmap for Success" now!
I enjoyed reading it.
Thanks Adrian.
What's "infoq.com/spring"? A topic? Why isn't it listed in the topics above?
What's "infoq.com/spring"? A topic? Why isn't it listed in the topics above?
If you look beneath the body of the article, you'll see "Tags Spring, AspectJ". You can click on those to see any all content on InfoQ about Spring or AspectJ. If you look at the top of the article you can see "topic - AOP", which functions the same. I added a link manually to the news item linking to this article so that people would notice the functionality.
Very nice article on AOP. Probably the most clean explanation of AOP terminology and principles that I've ever read. Keep on a great job, i21 & InfoQ!
When clicking on the print image right above, Firefox (1.5.0.6) is leaving some text out on the right, you cannot see the whole text. IE works fine. Could you pls check if there is something you could do about it? Thanks!
Thanks for the article, it is really nice!
Hi Peter, what page/paragraph do you notice the problem? I have the same version and it seems to print fine.
Like this page. I mean www.infoq.com/articles/Simplifying-Enterprise-Apps.
I was playing with the screen resolution and settings in Print Preview, but none of the attempts worked. Anyway, I managed to print it in IE and that is fine for now.
Thanks.
Hi Adrian,
Quick question: in the section about throwing, it's not clear that your afterThrowing() pointcut *replaces* the initial exception. I'm assuming that's what it does, right? It wouldn't make much sense to throw the original exception and then a DAOException, but you might want to clarify how this replacement actually works.
--
Cedric
Hi Cedric,
Your interpretion is correct. If after throwing advice itself throws an exception, then the exception thrown by the advice will be seen by the client. If the after throwing advice completes normally, then the original exception will propagate to the client.
The consequence of this is that you can use after throwing for exception *translation*, or for logging or taking other additional actions, but you can't use it to *handle* an exception condition. For that you have to use around advice, with a pattern that looks like this:
Object around() : some_pc() {
try {
return proceed();
}
catch(ExceptionToBeHandled ex) {
// handle condition here
return exceptionalConditionReturnValue;
}
}
(or the equivalent in @Aspect or Spring XML styles).
Regards, Adrian.
Hi Adrian,
Are you planning on releasing the sources. It would be great to show how one you easily implement the profiling strategy mapping to our Tracer API (www.jinspired.com/products/jxinsight/api/com/ji...) and have it easily integrated within our management console while adding additional JMV resource metrics (cpu, thread waiting, thread blocking, gc, object allocs).
We previously published a performance insight article based on our Spring 1.x trace extension.
www.jinspired.com/products/jxinsight/springtrac...
Regards,
William Louth
JXInsight Product Architect
JInspired
"Java EE tuning, testing, tracing, and monitoring with JXInsight"
www.jinspired.com
Hi,
Thanks for the good article. Though I have a quick question.
Just want to ask how would I be able to forward a user to an error page after using pointcut on that method. Say I have method in com.my.controllers.AnswerQuestion
processQuestion(blah, blah){
//do something
return “success”;
}
then I have this aop config
<aop:config>
<aop:aspect ref="exceptionHandler">
<aop:after-throwing
throwing="theException"
pointcut="com.my.controllers.AnswerQuestionprocessQuestion()"
method="theExceptionHandlerMethod"/>
</aop:aspect>
</aop:config>
The main question is how would you redirect the user not to “success” but to “errorpage”. Ofcourse I dont want to do big change on processQuestion() method, the aim is to let the AOP manage it.
Thanks!
Weng Guerra,
Try something like:
Thats my class:
public class Bar {
public String foo(int x) {
return "success";
}
}
And with this Aspect, i replace the outcome of foo(x):
public aspect ReplaceAspect {
pointcut yourMethodPointcut(Bar bar, int x):
target(bar) && args(x) &&
call(public String Bar.foo(int));
String around(Bar bar, int x) : yourMethodPointcut(bar, x) {
proceed(bar, x);
return "errorpage";
}
}
-Sebastian Jancke
(Sorry, I forgot the html-pre...)
Weng Guerra,
Try something like:
public class Bar {
public String foo(int x) {
return "success";
}
}
And with this Aspect, i replace the outcome of foo(x):
public aspect ReplaceAspect {
pointcut yourMethodPointcut(Bar bar, int x):
target(bar) && args(x) &&
call(public String Bar.foo(int));
String around(Bar bar, int x) : yourMethodPointcut(bar, x) {
proceed(bar, x);
return "errorpage";
}
}
-Sebastian Jancke
Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.
John Davies examines Visa’s architecture and shows how enterprises have architected complex integrations incorporating Hadoop, memcached, Ruby on Rails, and others to deliver innovative solutions.
Sean Comerford unveils ESPN.com’s architecture, what components are used and why, and the current changes the website goes through.
Are there repeated patterns of failure on Enterprise Agile Enablement efforts? Sanjiv and Arlen discuss Seven Deadly Sins to avoid when adopting Agile in an enterprise.
Erik Dörnenburg answers: What is Enterprise and Evolutionary Architecture?, discussing 4 issues: Turning strategy into execution, Ensuring conformance, Where do the architects sit? Buying or building?
Sean Cribbs explains what Map-Reduce and Riak are, why and how to use Map-Reduce with Riak, and how to convert SQL queries into their Map-Reduce equivalents.
Chris Richardson shows how he ported a relational database to three NoSQL data stores: Redis, Cassandra and MongoDB.
Jean Tabaka challenges the audience to reflect on what Agile practices they are employing, how they are using them, ending with the questions “Why have their organization chosen to go Agile?
13 comments
Watch Thread Reply