[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] trying to write a simple caching aspect
|
Ideally, I would think the following pointcut:
pointcut callingCachable() : call (ICachable+.new(..)); // calling any
constructor that implements ICachable interface
and advice:
advice Object around() : callingCachable() {
Object object = getCached(getTarget().getClassName());
if (object == null) {
object = proceed();
addToCache(object);
}
return object;
}
But according to syntax of pointcut, ICachable+ is not acceptable syntax. I
would like to see such syntax extension (not only for constructors, but for
methods). Not sure it is feasible. Any one have any thought?
Thanks,
Bo
----------------------------------------------------------
Dr. Bo Yi
WAS L3 Support
IBM Toronto Lab
A2-713/Q2Z/8200/MKM
8200 Warden Ave. Markham ONT. L6G 1C7
Phone: 905-413-4819
Tie Line: 969-4819
E-Mail: boyi@xxxxxxxxxx
"Jody Brownell"
<jody.brownell@Q1
Labs.com> To
Sent by: <aspectj-users@xxxxxxxxxxx>
aspectj-users-adm cc
in@xxxxxxxxxxx
Subject
[aspectj-users] trying to write a
10/21/2004 12:18 simple caching aspect
PM
Please respond to
aspectj-users
Hi ? I am new to aspectj, I am working through some example and trying to
develop a few aspects as a proof of concept.
The first aspect I am trying to develop is a real simple caching aspect
which caches objects based on the implementation of a tag interface.
What I would like to do is when a constructor is called, check if the class
implements an interface, if it does check the cache. If there is
no reference in the cache, proceed, cache the object and then return it.
Otherwise return the cached instance.
What I need to be able to do is get the name of the class the constructor
is being called on. My pointcut should really select all
constructors in the system (maybe confined to a package) with any number of
arguments. Once I have the class object or the name,
I can determine if the cache should be consulted.
Is this possible? If so could someone provide me with an example of the
pointcut and advice. I would provide what I have already but I
am stumped as to how I can capture class of the object I am trying to
instantiate. My problem is I would like to capture the class as context in
an around advice using a target() like construct.
Thanks in advance.
Jody b.