ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

JBoss Cache as a POJO Cache
Pages: 1, 2, 3, 4, 5, 6

Configuration

Before we can use the POJO cache functionality, we will need to use JBoss AOP tools to instrument the POJOs (namely, the PropagationManager, Node, and StateItem classes). We can do this via either XML declaration or annotation. Here we illustrate the POJO instrumentation via the JBoss AOP JDK 1.4 annotation (JDK 5.0 annotation will be supported in the next JBoss Cache release). Below are the code snippets that declare the annotation on the three main interfaces.



/**
* @@org.jboss.cache.aop.InstanceOfAopMarker
*/
public interface PropagationManager {
  public void setRootNode(String rdn);

  public void addNode(String parentFdn, String rdn);

  public void addStateItem(String parentFdn,
    long itemId, String name, long defaultState);

  public Node findNode(String fdn);

  public void stateChange(String fdn, long itemId,
    long newState);

...
}
   


/**
*
* @@org.jboss.cache.aop.InstanceOfAopMarker
*/
public interface Node {
  public void addChildNode(Node child);

  public List getChildren();

  public void setParentNode(Node parent);

  public Node getParentNode();

  public void addStateItem(StateItem stateItem);

  public void setSummaryStateItem(StateItem stateItem);

  public StateItem getSummaryStateItem();

  public List getStateItems();

  public StateItem findStateItem(long itemId);

  public void setPropagationRule(PropagationRule rule);

...
}



/**
* @@org.jboss.cache.aop.InstanceOfAopMarker
*/
public interface StateItem {
  public long getItemId();

  public boolean setState(long state);

  public long getState();

  public void setName(String name);

  public String getName();

...
}

Note the annotation inside the JavaDoc--@@org.jboss.cache.aop.InstanceOfAopMarker is a JBoss POJO Cache annotation that essentially declares that all instances of this interface will be instrumented, so there is no need to annotate individual classes. If you want to annotate a specific class (without propagating to its subclass), you can also use the @@org.jboss.cache.aop.AopMarker annotation.

After the interfaces are annotated, we then use a JDK-1.4-style JBoss AOP annotation precompiler, annoc, and an AOP precompiler, aopc, to perform compile-time instrumentation. Once these steps are done, the instrumentation process is complete and we are ready to run the example.

Pages: 1, 2, 3, 4, 5, 6

Next Pagearrow