|
VOctopusAspects
This document describes all the Aspects implemented to overcome certain cross-cutting concerns of the webserver.
Featured, Phase-Implementation, Phase-Design IntroductionAspect-Oriented Programming is the paradigm of programming languages that complements Object-Oriented Programming in a way to avoid intrusive code that does not make part of the business logic of a given section. Examples of those are Loggin, Persistence, Security, Cache, Code Policy, and so on. VOctopus will make use of Aspects when necessary in order to increase productivity and decrease coupling among the classes with frameworks that are intrusive. The ideas were described at my blog entry AOP rescued me today. DetailsVOctopusWebServerLoggin AspectAspects is created using the aspect-oriented language AspectJ. In this case, it's related to Java, but you can find others online that adapts to other programming language. In a nutshell, AspectJ comes handy in the case of the Loggin concern, something that's not an intrinsic part of the business logic of the Web Server. As a result, the aspect of Loggin is added to the following artifact: package edu.sfsu.cs.csc867.msales.voctopus.aspect.loggin;
import java.util.logging.Logger;
import java.util.logging.Level;
import org.aspectj.lang.Signature;
/**
* Aspect responsible for the loggin of the entire application.
* @author marcello
* Feb 16, 2008 8:26:02 AM
*/
public aspect VOctopusExecutionLoggin {
private Logger vologger = Logger.getLogger("tracer");
private VOctopusExecutionLoggin() {
this.vologger.setLevel(Level.ALL);
}
pointcut aspects() : within(VOctopusExecutionLoggin);
pointcut vOcotpusPackage() : execution(* edu.sfsu.cs.csc867.msales.voctopus..public(..)) || execution(edu.sfsu.cs.csc867.msales.voctopus..new(..));
pointcut excludedObjectCalls() : execution(* Logger.*(..));
pointcut loggableCalls() : vOcotpusPackage() && !aspects() && !excludedObjectCalls();
before() : loggableCalls() {
if (this.vologger.isLoggable(Level.INFO)) {
Signature sig = thisJoinPointStaticPart.getSignature();
this.vologger.logp(Level.INFO, sig.getDeclaringType().getName(), sig.getName(), "Entering");
}
}
}Everything starts with the definition of pointcuts. Pointcuts are points in the system where you want AspectJ to verify, in order to be able to intercept that point and then waive the code with the changes you are going to make. Then next step is the creation of Advices. By advising on what you want to do on the given pointcuts you will be exploring the power of accessing the execution of a given piece of code around the pointcuts. This is called Join Point since it will give a specific scenario of interception, say, "before return", "after exception thrown" are examples of that. The first aspect implemented on this server is the VOctopusWebServerLogging. It is intended to be a tracer for all the method calls inside of the package of the application. It contains a few advices on the pointcuts created. The screenshot below shows the Eclipse plugin "Aspect Visualization", where it details the cross-cutting on each section of the classes of the server's package.
|