We did have a discussion about this a year or two ago:
http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg05970.html
and I blogged about it later.
http://blog.aspectprogramming.com/articles/2006/04/21/aspect-oriented-design-humane-pointcut-languages
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.
http://www.parleys.com/display/PARLEYS/Domain%20Driven%20Design%20with%20AOP%20and%20DI
He's also blogged about it.
http://ramnivas.com/blog/index.php?p=20
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
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users
Dean Wampler, Ph.D.
dean at objectmentor.com
http://www.objectmentor.com
See also:
http://www.aspectprogramming.com AOP advocacy site
http://aquarium.rubyforge.org AOP for Ruby
http://www.contract4j.org Design by Contract for Java5
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users