Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Nonreflective field access in default implementations of interface methods

Hi!

I'm new to AspectJ and I'm pretty much stuck right now (please help me!
;-P). This is my example scenario:

My program is sluggishly slow. After some profiling, I see it spends
most of its time serializing and deserializing objects. I want do do
some benchmarks with different serialization approaches and want to do
so only once, so I change all my serializable classes and replace the
"implements Serializable" with a type annotation @Persistable.
Now I can try several policies using aspects. First approach: use
Externalizable instead of Serializable.
I want to do something like this (as I don't know how this should look,
I borrowed some syntax from JSP):


aspect PersistViaExternalizable {

  declare parents:
    (@Persistable *) implements Externalizable;

  public void Externalizable.readExternal(ObjectInput in) {
    <%
    for (Field f : IMPLEMENTING_CLASS.getFields()) {
      %><%= f.getName() %> = (<%= f.getType() %>) in.readObject();
      <%
    }
    %>
  }

  public void Externalizable.writeExternal(ObjectOutput out) {
    <%
    for (Field f : INSTRUMENTED_CLASS.fields) {
      %>out.writeObject(<%= f.getName() %>);
      <%
    }
    %>
  }
}


I read lot's of documentation and didn't find any example or mention of
anything remotely this, so I'd really like to hear how this could be done.

I know the example is oversimplified (e.g. no support for primitive
types), but as the fields and their types/supertypes are statically
known this _should_ be possible.

Can this be done in AspectJ? How?

Any help is greatly appreciated!

Regards,

Arne Hormann


Back to the top