Spring, JBoss AOP, Seasar2, well I know.
So how about Lucy?Is that any AOP features?
I can say it will be.
Lucy AOP is based on Javassist byte code enhancing.
It will be like this:
@Component
@Singleton
@Aspect(interceptBy = StringReplaceInterceptor.class, pointcut = "replace")
public class Aaa {
public String replace() {
return "aaa";
}
}
It points out Aaa is gonna be enhanced by StringReplaceInterceptor,
and also mentions that if method name is like "replace", by what?
By @Aspect.
@Aspect puts on class and method.
If you do like below:
@Component
@Singleton
@Aspect(interceptBy = StringReplaceInterceptor.class, pointcut = "replace")
public class Aaa {
@Aspect(interceptBy=AppendInterceptor.class)
public String replace() {
return "aaa";
}
}
if "replace" method invoked, StringReplaceInterceptor and AppendInterceptor are
gonna work.
What @Aspect looks like?
@Aspect has two methods, interceptBy and pointcut.
interceptBy() must be declared without any exception,
however, pointcut() is just optional.
@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.TYPE, ElementType.METHOD })
public @interface Aspect {
Class[] interceptBy();
String[] pointcut() default ".*";
}
So with design decision, we are not gonna use aop alliance provided jar.
Why? It is very simple. It is just useless and no one wants to use it.
There are some reasonable reasons to have MethodInvocation,
MethodInterceptor , but others, uhmmm,,,
there is no need to use it. So we simply do not use and make our Interceptor and Invocation.
So, where is StringReplaceInterceptor?
Calm down, here is StringReplaceInterceptor:
@Component
@Singleton
public class StringReplaceInterceptor implements Interceptor {
@Override
public Object intercept(Invocationinvocation)
throws InvocationException {
return "bbb";
}
}
Interceptor is very much like AOP alliance Interceptor.
But we can add some good feature and also can consider much better architecure
and add feature when needed because we HAVE this code.
All component is managed by Lucy.
We hope we can provide good and simple AOP feature with Lucy.
No comments:
Post a Comment