Skip navigation
2005

I am currently working on the JBossCache 1.2.4 release. The release will be mostly focused on JBossCacheAop and also the features needed to support fine-grained http session replication. One of the outstanding feature is for JBossCacheAop to handle scoped class loader (that can be a common requirement in a web app.) But I will defer it to another blog when it is completed.

Here, I would like to talk about annotation. One of the features in release 1.2.3 is the JDK1.4-style annotation support for JBossCacheAop. It is documented in the release doco. But since I have people asked me the usage, I thought I illustrate it here with an example of the fine-grained http session replication.

Since annotation (both JDK1.4 and 1.5) is supported by the JBossAop, there is really no ground-breaking development to apply it to JBossCacheAop per se. But without annotation, a user will always need to specify the Pojo (in this case, Address and Person ) instrumentation in a jboss-aop.xml file such as:

<aop>

  <prepare expr="field(* org.jboss.test.cache.test.standAloneAop.Address->*)" />

  <prepare expr="field(* $instanceof{org.jboss.test.cache.test.standAloneAop.Person}->*)" />

</aop>

Because we use dyanmic aop, we require every field in your Pojo to be "aspectized". It can become tedious for user to list every single one of them. Annotation in this case will work perfectly.

To facilitate the use of annotation, I have provided an AopMarker and InstanceOfAopMarker interfaces acting as 1.4 annotation holder. Then there is a system-wide jboss-aop.xml that is located under resources directory to associate the annotation as follows:

<aop> 

  <prepare expr="field(* org.jboss.cache.aop.AopMarker->*)" />

  <prepare expr="field(* $instanceof{org.jboss.cache.aop.InstanceOfAopMarker}->*)" />

</aop>

Note that InstanceOfAopMarker denotes that any sub-class or interface implementation of the Pojo will be automatically instrumented as well.

With these, all a user needs to declare in the pojo becomes very simple. It is just one line of annotation code. For example,

/** 

 * @@org.jboss.cache.aop.AopMarker

 */

public class Address {...}

or
/** 

 * @@org.jboss.cache.aop.InstanceOfAopMarker

 */

public class Person {...}

Will declare both Address and Person Pojos to be "aspectized" under JBossCacheAop automatically (without using a jboss-aop.xml).

So let&apos;s say when the next release of JBossAS supports fine-grained http session replication, to use it: 1) you will specify in your jboss-web.xml (inside your web app) that the replication granularity is "FIELD", 2) then declaring your Pojo(s) like above, the http session replication will be fine-grained automatically.

For example, when you do:

Person ben = new Person(); 

session.setAttribtue("ben", ben); // This setup Pojo ben to be managed.

ben.setName("Ben");

Only the name field in object ben will be replicated!

Of course because this is a 1.4 construct, you will still need an annotation compiler step to pre-compile your Pojos. But when we support 1.5 native annotation in the future release, there will be no need for pre-compiling and it will become mostly transparent for application developers!