[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [aspectj-users] AspectJ and memory management
|
> Rickard says:
>
> Anyway, Wes and I resolved the terminology issues off-list and it
> appears what I want to do can't be done in AspectJ.
>
I thought the following code, that we exchanged mail about last night,
does do what you want. In what way doesn't it work?
/*
* Here's an aspect that associates a lot of extra state with
* some target type. But we want to be sure not to allocate
* all that storage unless we really need it. So we use a
* lazy allocation strategy for it.
*/
abstract aspect PersistenceOrSomething {
protected interface HPoS {}; //marker type
//stands for HasPersistenceOrSomething
private static StateBlock {
private Mumble mumble;
private Frotz frotz;
...<many more fields>...
StateBlock() { /*appropriate initialization*/ }
}
private StateBlock Target.state = null;
/* these are the accessor methods for the state */
public Mumble HPoS.getMumble() { return state.mumble; }
public Frotz HPoS.getFrotz () { return state.frotz; }
...<many more accessors>...
/* make sure the state is actually allocated before any accessor runs */
before(HPoS hpos): within(HasPersitenceOrSomething)
&& execution(* HPoS.get*())
&& this(hpos) {
if(hpos.state == null)
hpos.state = new StateBlock();
}
<and then the rest of your aspect is here>
}
aspect Foo extends HasPersistenceOrSomething {
declare parents: SomeSpecificClass implements HPoS;
}