I'm trying out JCacheAop, and liking it so far.  I've run into an issue, I don't know 
if it's me bein' dumb, a configuration problem, or a bug.

I have an interface 'Managable.'  Any class intended to be added to a cache implements 
it.  My jboss-aop file is

<?xml version="1.0" encoding="UTF-8"?>
  | <aop>
  |  
  |     <prepare expr="field(* $instanceof{Managable}->*)"/>
  |     
  | </aop>

OK.  So I implement a class, intended to act as a simple message queue.  It contains a 
java.util.ArrayList to hold strings.  If the list has more then maxSize strings, it 
pops them (removes the strings from the front).  

if you look at the method pushMessage, it has 3 debug messages: it prints the contents 
of the list before the new message is added, after it is added, and after each old 
message is popped.

The problems start after the first time an old msg is popped.  This is the output for 
a run in which 5 messages are entered:

stage 1: ; Adding first msg
stage 2: [0:first msg]
stage 1: [0:first msg]; Adding second msg
stage 2: [0:first msg][1:second msg]
stage 1: [0:first msg][1:second msg]; Adding third msg
stage 2: [0:first msg][1:second msg][2:third msg]
stage 1: [0:first msg][1:second msg][2:third msg]; Adding fourth msg
stage 2: [0:first msg][1:second msg][2:third msg][3:fourth msg]
stage 3: [0:second msg][1:third msg][2:null]; popped msg first msg
stage 1: [0:second msg][1:third msg][2:null]; Adding fifth msg
stage 2: [0:second msg][1:third msg][2:null]

Using the TreeCacheAopGui to look at the nodes in the cache, I have checked the 
nodes/values during this.  After the fifth message, I see the node 
/MessagesList/messages has three children, named 3, 0, and 1.
The node 3 has the value 'fourth value.'  

I've implemented the same app, but with the list replaced by a String[] that I replace 
each time a msg is pushed.  That one works as I expect it to, so I believe my 
application logic is OK.  

I expected that this was possible, from the feature section of the TreeCacheAop docs: 

anonymous wrote : Support List, Set, and Map based objects automatically without 
declaring them as aop-enabled. That is, you can use them either as a plain POJO or a 
sub-object to POJO without declaring them as advisable.

>From the last question of the FAQ, it seems I may need to replace the list instance 
>with a dynamic proxy.  Is this the solution, and if so, how would I change my impl?  
>Is it possible to do entirely outside of MessageList?  I'd prefer to not have any 
>impact on the MessageList class beyond implementing the Managable interface.

anonymous wrote : Q: How do I use List, Set, and Map dynamic proxy?
  |  
  | A: TreeCacheAop supports classes extends from List, Set, and Map without users to 
declare it "advised". It is done via a dynamic proxy. Here is a code snippet to use an 
ArrayList class...(snipped)
 


  | public class MessagesList implements Managable {
  |     
  |     /** Creates a new instance of Queue */
  |     public MessagesList() {
  |         background = java.awt.Color.WHITE;
  |         messages = new java.util.ArrayList();
  |     }
  |     
  |     public String[] getMessages() {
  |         String[] result = new String[messages.size()];
  |         messages.toArray(result);
  |         return result;
  |     }
  |     
  |     public void add(String msg) {
  |         messages.add(msg);
  |     }
  |     
  |     public void remove(int index) {
  |         messages.remove(index);
  |     }
  |     
  |     public void pushMessage(String message) {       
  |         System.out.println("stage 1: " + this);
  |         System.out.println("Adding " + message);
  |         messages.add(message);
  |         System.out.println("stage 2: " + this);
  |         int ms = getMaxSize();
  |         while(messages.size() > ms) {
  |             String rem = (String)messages.remove(0);
  |             System.out.println("popped msg " + rem);
  |             System.out.println("stage 3: " + this);
  |         }
  |     }
  |     
  |     public java.awt.Color getColor() {
  |         return background;
  |     }
  |     
  |     public void setColor(java.awt.Color color) {
  |         background = color;
  |     }
  |     
  |     public int size() {
  |         return messages.size();
  |     }
  |     
  |     public int getMaxSize() {
  |         return maxSize;
  |     }
  |     
  |     public void setMaxSize(int size) {
  |         maxSize = size;
  |     }
  |     
  |     public String toString() {
  |         String[] msgs = getMessages();
  |         StringBuffer sb = new StringBuffer();
  |         for (int i = 0; i < msgs.length; i++) {
  |             sb.append("[" + i + ":" + msgs + "]");
  |         }
  |         return sb.toString();
  |     }
  |     
  |     private java.util.List messages;
  |     private java.awt.Color background;
  |     private int maxSize = 3;
  |     
  | }
  | 




View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3829326#3829326

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3829326


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to