[jboss-user] [JBoss Cache] New message: "my jboss cache is not replicating"

robert walker do-not-reply at jboss.com
Fri Feb 26 16:07:09 EST 2010


User development,

A new message was posted in the thread "my jboss cache is not replicating":

http://community.jboss.org/message/528910#528910

Author  : robert walker
Profile : http://community.jboss.org/people/robertwalker

Message:
--------------------------------------------------------------
Hi all, I got example 12 from jboss in action working with the clustering, very fun indeed.
basically one client sends in numbers 0-99  to jboss cluster, (2 nodes) and each node
gets the request randomly.
 
i decided to take it a step further and add jboss cache to it. So when the clients sens a number to the random node (node1 or node2) I print it out AND then add it to my arraylist cache, which should get replicated to the other node.
 
when sending numbers to cluster is done, the client makes one last call that says print cache. I expect either node (1 or 2) , whomever get chosen to service the request, to print out the arraylist (my jboss cache) showing all the numbers, ones handled by node1 and the numbers handled by node2. BUT, the cache is not replicating, i.e, if node1 is printing 15, it does not replicate this to node2 cache.
 
here is my code, can someone help (this is jboss 5.01, jdk1.5)

=========================
{code}
package com.manning.jbia;
 
import javax.ejb.Stateless;
import org.jboss.ejb3.annotation.Clustered;
import javax.annotation.PostConstruct; 
import javax.annotation.PreDestroy;
import org.apache.log4j.Logger;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import java.util.ArrayList;
import java.util.Iterator;
 

@Stateless
@Clustered
public class CounterBean implements Counter 
{ 
public static boolean jbossCacheCreated = false;
private static Node numberCache = null;
 
public static Node getNumbersCache() 
{
if(numberCache==null)
{
System.out.println("Initializing the cache");
initializeCache();
}
return numberCache; 
}
 
public void printCount(int countNumber) 
{
System.out.print(countNumber +" ");
// add number to cache, but does not replicated to other node's cache
Node numberCache = CounterBean.getNumbersCache();
ArrayList al = (ArrayList)numberCache.get("numbersList"); 
al.add(countNumber);
 
}
 
public static void initializeCache()
{
CacheFactory factory = new DefaultCacheFactory();
 
Cache cache = factory.createCache();
// Have to create and start cache before using it
cache.create();
cache.start();
 
Node rootNode = cache.getRoot();
 
// JBoss Cache stores data in a tree structure.
// All nodes in the tree structure are identified by Fqn objects.
Fqn cersFqn = Fqn.fromString("/jboss/cache/numbers");
 
// Create a new Node
numberCache = rootNode.addChild(cersFqn);
 
// let's store some data in the node
numberCache.put("numbersList", new ArrayList());
}
 
public void printCache()
{
System.out.println("start CounterBean.printCache()\n"); 
ArrayList al = (ArrayList)numberCache.get("numbersList");
Iterator alIterator = al.iterator();
System.out.println("cache=[");
while(alIterator.hasNext())
{
System.out.print( alIterator.next() +" ");
}
System.out.println("]");
 
System.out.println("\n\nend CounterBean.printCache()");
}
 
@PostConstruct 
public void initialize () 
{ 
// Initialize here objects which will be used 
// by the session bean 
System.out.println("CounterBean initialize()"); 
}

@PreDestroy 
public void destroyBean() 
{ 
// Free here resources acquired by the session bean 
System.out.println("CounterBean destroyBean()"); 
}
}
{code}

--------------------------------------------------------------

To reply to this message visit the message page: http://community.jboss.org/message/528910#528910




More information about the jboss-user mailing list