Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] AspectJ issue or ...

There is an article here on caching:

http://www.aspectprogrammer.org/blogs/adrian/2004/06/implementing_ca_1.html

Something like this might work for you:

  public privileged aspect WriteBack extends WritePolicy
perthis(writeMethodCalled(Object)) {

     private ICache myCache;

     pointcut writingMethodCalled(Object o):
        (execution(@WritingMethod void *(*))) && // my methods in Aclass
  (or somewhere else)
         args(o);

     void around(Object o): writingMethodCalled(o) {
         // We need to find out the current cache
         // myCache is the current cache

         (...)
     }

you will get a different cache instance for every different execution
of an @WritingMethod annotated method (that takes a single argument).

Andy

On 01/04/2008, joss <jonathan.clairembault@xxxxxxxxx> wrote:
> Hi all,
>
>  I got an issue with AspectJ. Actually I have got 2 classes (Cache and
>  Aclass) and 1 aspect (WriteBack).
>  I'd like to advise methods in Aclass by declaring pointcuts in
>  WriteBack, but I need to write the result of those functions in Cache.
>  My issue is how can I recuperate my Cache in which I want to write to.
>
>  here is an example :
>
>  public privileged aspect WriteBack extends WritePolicy {
>
>     pointcut writingMethodCalled(Object o):
>         (execution(@WritingMethod void *(*))) && // my methods in Aclass
>  (or somewhere else)
>         args(o);
>
>     void around(Object o): writingMethodCalled(o) {
>         // We need to find out the current cache
>         ICache currentCache = ; // HERE IS THE ISSUE
>
>         (...)
>     }
>
>  public interface ICache<D> extends Iterable<IEntry<D>>{
>     int getSize();
>     int getMaxSize();
>     // entries with the same tag are merely modified (Data)
>     void putEntry(IEntry<D> e);
>     IEntry<D> getEntry(Taggable tag);
>     IEntry<D> getEntry(Object data);
>     void removeEntry(IEntry<D> e);
>  }
>
>  I wondering if I use my aspect with the clause perthis(cacheCreation()),
>  may I recuperate the Cache instance linked with this aspect ?
>
>  Thanks in advance,
>  Jonathan Clairembault
>  _______________________________________________
>  aspectj-users mailing list
>  aspectj-users@xxxxxxxxxxx
>  https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top