1 Reply Latest reply on Jan 20, 2003 3:52 PM by marc fleury

    AOP to instrument classes on the fly ?

    Bela Ban Master

      Okay, back to my old problem: I want to know whether an object has been modified within a given period of time. Here's what I would like to do:

      Person p=new Person("Bela", 37);
      cache.put("bela", p);
      ...
      p.incrementAge();
      ...
      if(p.isModified()) {
      channel.replicate(p.toByteBuffer());
      p.setModified(false);
      }


      The getModified() and setModified() methods are added to the class when the class is loaded. Possibly we also instrument the class with a method toStream() /fromStream, which provides efficient serialization, so my objects do not have to implement Serializable.


      Can this be done ?

      This would entail tracking state changes within the object.

      Can you guys at class loading time find out whether a method is write or read-only ? If it is write add some code which sets an internal boolean "modified".

      Am I far off ?

      Bela

        • 1. Re: AOP to instrument classes on the fly ?
          marc fleury Master

          > Person p=new Person("Bela", 37);
          > cache.put("bela", p);
          > ...
          > p.incrementAge();
          > ...
          > if(p.isModified()) {
          > channel.replicate(p.toByteBuffer());
          > p.setModified(false);

          essentially incrementAge() is a field access modification and the modification is instrumented meaning it is indirected. The cache.put("bela", p) triggers
          ((AOP)p).getStack(addInterceptor(new CacheInterceptor(this));

          the Cache Interceptor is notified of setters changes.


          >
          >
          > The getModified() and setModified() methods are added
          > to the class when the class is loaded. Possibly we
          > also instrument the class with a method toStream()
          > /fromStream, which provides efficient serialization,
          > so my objects do not have to implement Serializable.

          essentially you get notified from the interceptor you dynamically add when someone inserts the entry in your cache.

          > Can this be done ?

          sure.

          > This would entail tracking state changes within the
          > object.

          exactly and you get notified.

          > Can you guys at class loading time find out whether a
          > method is write or read-only ? If it is write add
          > some code which sets an internal boolean "modified".

          Again better, you instrument it for modifications. We just create the indirection.

          marcf