We did have a discussion about this a year or two ago:
and I blogged about it later.
Google for "aspectj humane interface". I think your style is better than what I suggested, especially for people already familiar with JMock. I believe that a humane/fluent interface would help a lot of new and potential adopters. I'm trying for something like this in Aquarium (Ruby AOP library).
Also, this presentation by Ramnivas came up with a Google search.
He's also blogged about it.
dean On Feb 13, 2008, at 10:38 AM, Thomas Darimont wrote: Too fast.... it would look like this:
/** * */ package de.tutorials.aop.aspectj;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect;
import de.tutorials.aop.Any; import de.tutorials.aop.Arguments; import de.tutorials.aop.NotNull; import de.tutorials.aop.Pointcut; import de.tutorials.aop.Pointcuts; import de.tutorials.aop.Transactional;
/** * @author Thomas.Darimont * */ @Aspect public class Retry {
int maxRetries;
public int getMaxRetries() { return maxRetries; }
public void setMaxRetries(int retryLimit) { this.maxRetries = retryLimit; }
public Pointcut someMethods() { return Pointcuts .call() .methods("process*") .withinPackage("de.tutorials.services..") .withAttribute(Transactional.class) .withArguments(new Arguments() { Any args; //Any -> special Typ matching all types like "*" int param0; @NotNull String param1; }); }
@Around("someMethods") public Object retry(ProceedingJoinPoint thisJoinPoint) { int currentTry = 0; while (currentTry < maxRetries) { try { return thisJoinPoint.proceed(); }catch(Throwable throwable){ //log ... currentTry++; } } throw new RuntimeException("retry limit reached"); } }* *
Thomas Darimont schrieb:
Hello,
I don't know whether this was already discussed on the list (at least I couldn't find the thread) so I ask
what do you think of supporting a fluent API for Pointcuts in @AspectJ Java Style Aspects?
It would look like this:
/**
*
*/
package de.tutorials.aop.aspectj;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import de.tutorials.aop.Any;
import de.tutorials.aop.Arguments;
import de.tutorials.aop.NotNull;
import de.tutorials.aop.Pointcut;
import de.tutorials.aop.Pointcuts;
import de.tutorials.aop.Transactional;
/**
* @author Thomas.Darimont
*
*/
@Aspect
public class Retry {
int maxRetries;
public int getMaxRetries() {
return maxRetries;
}
public void setMaxRetries(int retryLimit) {
this.maxRetries = retryLimit;
}
public Pointcut someMethods() {
return Pointcuts
.call()
.methods("process*")
.withinPackage("de.tutorials.services..")
.withAttribute(Transactional.class)
.withArguments(new Arguments() {
Any args; //Any -> special Typ matching all types like "*"
int param0;
@NotNull String param1;
}).;
}
@Around("someMethods")
public Object retry(ProceedingJoinPoint thisJoinPoint) {
Object result = null;
int currentTry = 0;
while (currentTry < maxRetries) {
try {
result = thisJoinPoint.proceed();
}catch(Throwable throwable){
//log ...
currentTry++;
}
}
return result;
}
}
the obvious Advantages are:
- Pointcut definition would be refactoring friendly (e.g. renaming of a type
- Pointcut Expressions could be checked by the compiler (to a certain degree)
- AspectJ could be used to validate Pointcuts at compiletime (declare error!) :)
What do you think about this?
Best regards,
Thomas
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________ aspectj-users mailing list aspectj-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/aspectj-users
Dean Wampler, Ph.D. dean at objectmentor.com See also:
|