Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Use Cases for Changing target and this in proceed

> However, I haven't been able to come up with a 
> realistic use case for changing the "this" object.

One use is to apply the strategy pattern to a template method.
Another would be to cache a local copy of a remote object; a 
variant of this would be to batch updates.  The basic idea is
that there are policies with different behavior or state that
one might want to apply using proxy-like behavior in situations
where you can't manage the references held by the client.  

You're right to suggest this is dicey business if some client 
expects a state change in the executing object that is not 
induced by the alternative object, but I'm not sure there's
a semantic difference between changing this or target
(modulo method dispatch - also, we should test/decide whether 
this change does/should affect more-precedent after advice).

Do you think this is a case where AspectJ is too powerful?
Would the language be simpler or more complex if you couldn't
replace this or target?  Would you want to be able to enable
a lint warning that indicated when this or target was replaced
(assuming one could implement it)?

(Just my $.02, not as a language designer, but as an apologist.) 

Wes

> ------------Original Message------------
> From: Curtis Clifton <curt.clifton@xxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Cc: "Gary Leavens" <leavens@xxxxxxxxxxxxxx>
> Date: Mon, Dec-13-2004 1:06 PM
> Subject: [aspectj-users] Use Cases for Changing target and this in proceed
>
> I am trying to understand the semantics of proceed.  One interesting 
> issue arises because AspectJ lets us change the "this" and "target" 
> objects when proceeding from around advice.  Here's a fragment that 
> just changes the "this" object (the full code for the example is given 
> below):
> 
> 	void around(ChangeThis th) : call(* *.m()) && this(th) {
> 		System.out.println("first around call m: this = " + th);
> 		proceed(new ChangeThis()); // change this, just seen in subsequent 
> advice
> 		System.out.println("first around call m: this = " + th);
> 	}
> 
> My example isn't practical; it is just meant to demonstrate the 
> semantic issue.
> 
> My question is about use cases for changing the target and this objects 
> 
> when proceeding.  I can imagine wanting to change the target object: 
> perhaps we want to wrap the original target in some wrapper object 
> before proceeding.  However, I haven't been able to come up with a 
> realistic use case for changing the "this" object.  I assume changing 
> the "this" object would only affect join point information bound in 
> subsequent advice.  I don't see how it could change the original "this" 
> 
> object that called the advised code, and the advised code wouldn't 
> typically be able to determine its original caller. (Experimentation 
> with ajc version 1.2 bears this assumption out.)  Also, it also isn't 
> clear what it should mean to change the target object at an execution 
> join point, because presumably the target object's stack frame has 
> already been pushed.
> 
> My basic question is:
> 
> Are there any use cases for changing the "this" object in a proceed?  
> Or is this capability just a result of the decision to make the 
> arguments to proceed match the parameters of the surrounding advice?
> 
> Thanks for any insight,
> 
> Curt
> 
> ----------------------------------
> Curtis Clifton, PhD Candidate
> Dept. of Computer Science, Iowa State University
> http://www.cs.iastate.edu/~cclifton
> 
> // Full sample code
> public class ChangeThis {
> 	private B b = new B();
> 
> 	public static void main(String[] args) {
> 		new ChangeThis().run();
> 	}
> 	
> 	void run() {
> 		System.out.println("in run, with b = " + b);
> 		b.m();
> 		System.out.println("in run, with b = " + b);
> 	}
> 	
> }
> 
> class B {
> 	void m() {
> 		System.out.println("in m, this = " + this);
> 	}
> }
> 
> aspect Asp1 {
> 	void around(ChangeThis th) : call(* *.m()) && this(th) {
> 		System.out.println("first around call m: this = " + th);
> 		proceed(new ChangeThis()); // change this, just seen in subsequent 
> advice
> 		System.out.println("first around call m: this = " + th);
> 	}
> 
> 	void around(ChangeThis th) : call(* *.m()) && this(th) {
> 		System.out.println("second around call m: this = " + th);
> 		proceed(th); // change this, seen in next advice?
> 		System.out.println("second around call m: this = " + th);
> 	}
> }
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 




Back to the top