http://www.developer.com/
Create Aspect: Point cut: The build file has been given; by using it, you can run both flavors of benchmarking. Set the environment variables for Ant and then run "ant" to build and run both flavors. Build.xml Aspect-Oriented Programming has numerous advantages. Some of them are mentioned below: To give fair coverage of the topic I should list any negatives along with all the positives. On the downside, in my opinion, I found the learning curve steep. It takes a little longer to understand the concepts of joint point, advice and annotations style of programming. It also adds some latency to the target application, which might make you feel the performance hit.
Apart from AspectJ, there are other implementations also available. Some of them are Spring, Jboss, and AspectWerks. It's up to you to choose the implementation that is right for you. AOP is easier to understand and implement. It achieves code reuse and modularization at much greater levels. It removes the cross cutting concerns and makes application loosely coupled and maintenance easy. Ayyappan Gandhirajan holds a Master's degree in Software Systems from BITS, Pilani, India and a Bachelor's degree in Electronics & Communication Engineering from MK University, India. He has over eight years of profound software experience in domains of Travel, Telecom/Mobility, and e-commerce and technologies such as Spring, AOP, ESB, Web services, WS Security, and J2EE. He currently works for Perot Systems, India. Before joining Perot, he worked for five years with Hewlett-Packard ISO, India. He can be reached at ayyappan.gandhirajan@ps.net or G_Ayyapparaj@yahoo.com.
package aspect;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public abstract class AbstractBenchmarkAspect {
@Pointcut
public abstract void benchmark();
@Around("benchmark()")
public Object executeBenchmarkAdvise(ProceedingJoinPoint jp)
throws Throwable{
long startTime = System.currentTimeMillis();
Object response = jp.proceed();
long endTime = System.currentTimeMillis();
System.out.println("TIME TAKEN (in msecs): "+
(endTime - startTime));
return response;
}
}
<aspectj>
<aspects>
<concrete-aspect
name="aspect.BenchmarkAspect"
extends="aspect.AbstractBenchmarkAspect">
<pointcut name="benchmark"
expression=
"execution(* sample.LoanCalculator.*(..)))" />
</concrete-aspect>
</aspects>
</aspectj>
<project name="aspect" default="run">
<target name="init">
<mkdir dir="build"/>
</target>
<target name="compile" depends="init">
<javac
srcdir="src"
destdir="build"
source="1.5"
debug="true">
<classpath refid="build.classpath"/>
</javac>
</target>
<target name="run" depends="compile">
<echo>========================================</echo>
<echo>Running without aspect...</echo>
<echo>========================================</echo>
<java classname="sample.LoanClient2" fork="true">
<classpath refid="build.classpath"/>
</java>
<echo></echo>
<echo>========================================</echo>
<echo>Running with aspect...</echo>
<echo>========================================</echo>
<java classname="sample.LoanClient" fork="true">
<classpath refid="build.classpath"/>
<jvmarg value="-javaagent:libaspectjweaver.jar"/>
</java>
</target>
<path id="build.classpath">
<pathelement location="build"/>
<pathelement location="bin"/>
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</path>
</project>
Advantages
Disadvantages
Summary
References
About the Author