[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Fluent interface for Pointcuts in @AspectJ style Aspects
|
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