[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] changing pointcut at runtime
|
Thanks at all.
I will try Adrian Colyer's solution...I think that in this manner I can
solve my problems.
best regards
Adrian Colyer ha scritto:
Also of interest would be to look at the AspectJ weaver tools API. In
particular the class org.aspectj.weaver.tools.PointcutParser
(http://www.eclipse.org/aspectj/doc/released/weaver-api/index.html)
allows you to create a PointcutParser that can parse a String and
return a PointcutExpression that can be used for matching. A solution
based around this would have to:
1) Create a class something like JoinPointMatcher that can be
constructed with a PointcutExpression and uses the information in
JoinPoint to drive the PointcutExpression matching API.
2) advise the maximum allowable set of join points for which you wish
to support runtime matching, using a pointcut with an if() component
as suggested by Matthew.
3) Inside the if() pointcut, write a boolean expression that matches
if your JoinPointMatcher matches thisJoinPoint
The PointcutParser class is the same one that Spring uses for its
AspectJ integration...
Regards, Adrian.
On 2 Oct 2006, at 10:34, Matthew Webster wrote:
Wes,
>But you're foraging around a proposal that sounds interesting: to
declare
>programmatically at runtime a concrete aspect using LTW that (only)
>affects the loading of subsequent classes. In principle this is doable
>(at some coherency risk vis-a-vis any classes loaded first), so the
>question becomes whether you can make a compelling use case,
particularly
>if it involves a well-defined start/end point for defining subaspects
>programmatically.
This may sound a bit Isaac Asimov but such a feature would break the
first rule of LTW:
http://www.eclipse.org/aspectj/doc/released/devguide/ltw-rules.html.
It is very important that a program behave the same regardless of the
stage at which weaving takes place. Allowing an aspect to be defined
at an arbitrary time would most likely result in the scope of weaving
being different for each execution of a program given that, as you
point out, this is determined by the order in which classes are loaded.
>As Eric mentioned, you can advise some join points and then include
a check
>at each one whether to run the advice; you might implement the check
using
>Pointcut or reflection or what have you. You cannot change an existing
>pointcut, but you can decide what code to run. (With some cheating
you can
>change the result of an if(..) PCD, but it's clearer to change the
advice.)
The best approach is to weave every eligible join point shadow with
advice associated with an "if()" pointcut filter. The filter would
test at runtime whether a join point was to be advised. The test can
be optimized after the first execution by adding the JoinPoint to a
set. If AspectJ allowed such "runtime" weaving this is probably the
way it would be implemented.
Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester, SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
<mailto:matthew_webster@xxxxxxxxxx>
http://w3.hursley.ibm.com/~websterm/
<http://w3.hursley.ibm.com/%7Ewebsterm/%02>
*"Wes" <wes@xxxxxxxxxxxxxx <mailto:wes@xxxxxxxxxxxxxx>>*
Sent by: aspectj-users-bounces@xxxxxxxxxxx
<mailto:aspectj-users-bounces@xxxxxxxxxxx>
02/10/2006 07:11
Please respond to
wes@xxxxxxxxxxxxxx <mailto:wes@xxxxxxxxxxxxxx>; Please respond to
aspectj-users@xxxxxxxxxxx <mailto:aspectj-users@xxxxxxxxxxx>
To
aspectj-users@xxxxxxxxxxx <mailto:aspectj-users@xxxxxxxxxxx>
cc
Subject
Re: [aspectj-users] changing pointcut at runtime
A longstanding and interesting question...
As Eric mentioned, you can advise some join points and then include a
check
at each one whether to run the advice; you might implement the check
using
Pointcut or reflection or what have you. You cannot change an existing
pointcut, but you can decide what code to run. (With some cheating
you can
change the result of an if(..) PCD, but it's clearer to change the
advice.)
But you're foraging around a proposal that sounds interesting: to declare
programmatically at runtime a concrete aspect using LTW that (only)
affects the loading of subsequent classes. In principle this is doable
(at some coherency risk vis-a-vis any classes loaded first), so the
question becomes whether you can make a compelling use case, particularly
if it involves a well-defined start/end point for defining subaspects
programmatically.
Wes
> ------------Original Message------------
> From: stalsy <stalsy@xxxxxxxxx <mailto:stalsy@xxxxxxxxx>>
> To: aspectj-users@xxxxxxxxxxx <mailto:aspectj-users@xxxxxxxxxxx>
> Date: Sun, Oct-1-2006 11:40 AM
> Subject: [aspectj-users] changing pointcut at runtime
>
>
> Hi all,
>
> I'm a newbie in aspectj and I need to change a pointcut at runtime
> based on
> the user choice.
>
> I receive an input String from the user keyboard and I want create a
> pointcut based on that input. Initially I've thinking at aspect
> reflection,
> but there isn't any "set" method for this pourpose.
>
> String comp = InitVars.getFilter(); // get an input from user keyboard
> ....
> AjType dt = AjTypeSystem.getAjType(DynTrace.class); // the aspect
> (DynTrace.aj) in which I would insert new pointcut
> Pointcut pc = dt.getPointcut("filter"); // take the old pointcut
> PointcutExpression pce = pc.getPointcutExpression(); // take the
> pointcut
> old expression
>
> now how can I insert new pointcut expression( value of variable "comp"
> ) in
> this pointcut? There is another way to make this?
>
> ES:
>
> I get the input "component" from user. Than I would change the old
> pointcut
> public pointcut filter(): Scope() && execution(* *(..));
> to
> public pointcut filter(): Scope() && execution(* component(..));
>
> where component in pointcut expression is the value of component
> variable.
>
> someone can help me, please?
>
> thank you in advance for replies, best regards
> --
> View this message in context:
>
http://www.nabble.com/changing-pointcut-at-runtime-tf2365784.html#a6590719
> Sent from the AspectJ - users mailing list archive at Nabble.com.
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx <mailto:aspectj-users@xxxxxxxxxxx>
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx <mailto:aspectj-users@xxxxxxxxxxx>
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx <mailto: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
--
Stalsy
HomePage --:. http://www.stalsy.it
Blog --:. http://blog.stalsy.com
Public Key --:. http://www.stalsy.it/key.php
E-Mail --:. stalsy@xxxxxxxxx
ICQ --:. 302346155
MSN --:. faricci@xxxxxxxx