infinispan: clustred instances not sharing cache
creatureoflegend Nov 12, 2012 1:34 PMI've spent over 3 days doing nothing but trying to get Infinispan to work in a clustered environment and it's not working. I don't want to run a separate infinispan server, I just want to embed it in my application that runs on a clustered Glassfish. Is that not possible? I got a sample JSF app where you can just load values into a map that's supposed to sit in cache. I pull up one clustered instance, add the values, they show up. But when I go to the other clustered instance, it shows the map as empty.
I know I'm doing something wrong, I just don't know what. Been searching the internet and there is no comprehensive tutorial on how to get it to work.
config (coppied from a tutorial that supposedly shows clustering http://www.mastertheboss.com/infinispan/infinispan-tutorial-part-2/page-2 ):
[code]
<infinispan>
<global>
<transport clusterName="demoCluster"/>
<globalJmxStatistics enabled="true"/>
</global>
<default>
<jmxStatistics enabled="true"/>
<clustering mode="distribution">
<hash numOwners="2" rehashRpcTimeout="120000"/>
<sync/>
</clustering>
</default>
</infinispan>
[/code]
Context listener:
[code]
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
@WebListener()
public class Listener implements ServletContextListener
{
EmbeddedCacheManager manager;
@Override
public void contextInitialized(ServletContextEvent sce)
{
try
{
manager = new DefaultCacheManager("config.xml");
//manager.start();
sce.getServletContext().setAttribute("cacheManager", manager);
}
catch (IOException ex)
{
Logger.getLogger(Listener.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void contextDestroyed(ServletContextEvent sce)
{
manager.stop();
}
}
[/code]
Bean:
[code]
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import org.infinispan.manager.EmbeddedCacheManager;
@ManagedBean(name="clusterTest")
public class ClusteredCacheBean extends CacheTestBean
{
EmbeddedCacheManager manager;
public ClusteredCacheBean() throws IOException
{
System.out.println("Before setStuffz()");
manager = (EmbeddedCacheManager) ((ServletContext)FacesContext.getCurrentInstance().
getExternalContext().getContext()).getAttribute("cacheManager");
setStuffz(manager.getCache("stuffz"));
System.out.println("After setStuffz()");
}// end ClusteredCacheBean()
@Override
public String addToCache()
{
String forwardTo = null;
manager.getCache("stuffz").put(getId(), getName());
return forwardTo;
}// end addToCache()
@Override
public List getStuffzList()
{
System.out.println("Stuffz: " + getStuffz().size());
return new LinkedList(manager.getCache("stuffz").entrySet());
}
}// end class ClusteredCacheBean
[/code]
I really don't know what to do at this point...
As a side-note, does anyone know of any good tutorials on running embedded infinispan in a clustered Glassfish. Looks like those sections are missing w/ a "todo" tag in the quckstart, and all of the tutorials for clustering I've found so far have to do with clustering infinispan in java SE, not on an app server.
I'm attaching the complete netbeans project below.
(I posted this question on stackoverflow, but so far no help. Hoping you guys will help me out here.)
Java: Oracle jdk1.6.0_35
Infinispan version: 5.1.6.FINAL
Network topology: dont know...
App server in use: Glassfish 3.1.2.2
Thread dump: n/a. No errors, just stuff added to the app on one cluster not is not available to the same app running on another cluster node.
-
InfinispanWeb1.zip 39.2 KB