9 Replies Latest reply on Nov 21, 2012 12:23 PM by creatureoflegend

    infinispan: clustred instances not sharing cache

    creatureoflegend Newbie

      I'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.

        • 1. Re: infinispan: clustred instances not sharing cache
          Tristan Tarrant Master

          Hi Anastasia,

          we really need some logs in order to help you here. Just drop in a log4j jar and a log4j.xml/log4j.properties and set the Infinispan and JGroups logging to debug (something like https://github.com/infinispan/infinispan/blob/master/core/src/test/resources/log4j.xml will do).

          By default Infinispan uses JGroups' UDP multicast, so make sure that is enabled.

          • 2. Re: infinispan: clustred instances not sharing cache
            creatureoflegend Newbie

            Hi Tristan!

             

            Thanks so much for responding!

             

            I've dropped that log4j.xml into my root path but I don't think it took. I'm not sure what you bean by jGroups logging. I coudln't find any directions on how to set up jGroups to work with infinispan. Is jGroups supposed to be like a separate server that runs outise of Glassfish and my web app?  I'm kind of looking for a clustered caching solution that wouldn't need a separate server. If my app can cluster why can't there be a builtin cache that can use the same clustering mechanis m and not need a separate server?

             

            Sorry, I'm a total n00b. I've read a bunch of inifnispan tutorials, but noe of them include anything about jGroups, and jGroups tutorials aren't really about caching, so I'm really not sure where to go from here.

             

            Here are the glassfish logs from both cluster instances:

             

            Instance 1 (one on the DAS server):

             

             

            [#|2012-11-19T10:14:56.047-0600|INFO|glassfish3.1.2|javax.enterprise.resource.webcontainer.jsf.config|_ThreadID=21;_ThreadName=Thread-2;|Initializing Mojarra 2.1.6 (SNAPSHOT 20111206) for context '/InfinispanWeb1'|#]

             

            [#|2012-11-19T10:14:56.694-0600|INFO|glassfish3.1.2|org.primefaces.webapp.PostConstructApplicationEventListener|_ThreadID=21;_ThreadName=Thread-2;|Running on PrimeFaces 3.3.1|#]

             

            [#|2012-11-19T10:14:58.849-0600|INFO|glassfish3.1.2|org.infinispan.configuration.parsing.Parser|_ThreadID=21;_ThreadName=Thread-2;|ISPN000186: hash's 'rehashRpcTimeout' attribute has been deprecated. Please use stateTransfer.timeout instead|#]

             

            [#|2012-11-19T10:14:59.808-0600|INFO|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=21;_ThreadName=Thread-2;|WEB0671: Loading application [InfinispanWeb1] at [/InfinispanWeb1]|#]

             

            [#|2012-11-19T10:14:59.948-0600|INFO|glassfish3.1.2|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=21;_ThreadName=Thread-2;|InfinispanWeb1 was successfully deployed in 9,527 milliseconds.|#]

             

            [#|2012-11-19T10:15:06.712-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|Before setStuffz()|#]

             

            [#|2012-11-19T10:15:07.650-0600|INFO|glassfish3.1.2|org.infinispan.remoting.transport.jgroups.JGroupsTransport|_ThreadID=30;_ThreadName=Thread-2;|ISPN000078: Starting JGroups Channel|#]

             

            [#|2012-11-19T10:15:07.650-0600|INFO|glassfish3.1.2|org.infinispan.remoting.transport.jgroups.JGroupsTransport|_ThreadID=30;_ThreadName=Thread-2;|ISPN000088: Unable to use any JGroups configuration mechanisms provided in properties {}. Using default JGroups configuration!|#]

             

            [#|2012-11-19T10:15:08.032-0600|SEVERE|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|log4j:WARN No appenders could be found for logger (org.jgroups.conf.ClassConfigurator).|#]

             

            [#|2012-11-19T10:15:08.032-0600|SEVERE|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|log4j:WARN Please initialize the log4j system properly.|#]

             

            [#|2012-11-19T10:15:08.032-0600|SEVERE|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.|#]

             

            [#|2012-11-19T10:15:12.358-0600|INFO|glassfish3.1.2|org.infinispan.remoting.transport.jgroups.JGroupsTransport|_ThreadID=30;_ThreadName=Thread-2;|ISPN000094: Received new cluster view: [RC-11537-28504|0] [RC-11537-28504]|#]

             

            [#|2012-11-19T10:15:12.420-0600|INFO|glassfish3.1.2|org.infinispan.remoting.transport.jgroups.JGroupsTransport|_ThreadID=30;_ThreadName=Thread-2;|ISPN000079: Cache local address is RC-11537-28504, physical addresses are [fe80:0:0:0:d58:a0f5:ce96:b7b3:63427]|#]

             

            [#|2012-11-19T10:15:12.436-0600|INFO|glassfish3.1.2|org.infinispan.factories.GlobalComponentRegistry|_ThreadID=30;_ThreadName=Thread-2;|ISPN000128: Infinispan version: Infinispan 'Brahma' 5.1.6.FINAL|#]

             

            [#|2012-11-19T10:15:13.777-0600|INFO|glassfish3.1.2|org.infinispan.jmx.CacheJmxRegistration|_ThreadID=30;_ThreadName=Thread-2;|ISPN000031: MBeans were successfully registered to the platform mbean server.|#]

             

            [#|2012-11-19T10:15:13.949-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|After setStuffz()|#]

             

            [#|2012-11-19T10:15:14.011-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:17.937-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|Before setStuffz()|#]

             

            [#|2012-11-19T10:15:17.937-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|After setStuffz()|#]

             

            [#|2012-11-19T10:15:17.937-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:17.937-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:17.937-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:17.937-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:17.937-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:17.937-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:17.937-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:17.937-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:17.937-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:17.977-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=30;_ThreadName=Thread-2;|Stuffz: 1|#]

             

            [#|2012-11-19T10:15:21.460-0600|WARNING|glassfish3.1.2|org.apache.catalina.connector.Request|_ThreadID=33;_ThreadName=Thread-2;|PWC4011: Unable to set request character encoding to UTF-8 from context /InfinispanWeb1, because request parameters have already been read, or ServletRequest.getReader() has already been called|#]

             

            [#|2012-11-19T10:15:21.476-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=33;_ThreadName=Thread-2;|Before setStuffz()|#]

             

            [#|2012-11-19T10:15:21.476-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=33;_ThreadName=Thread-2;|After setStuffz()|#]

             

            [#|2012-11-19T10:15:21.476-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=33;_ThreadName=Thread-2;|Stuffz: 1|#]

             

            [#|2012-11-19T10:15:21.476-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=33;_ThreadName=Thread-2;|Stuffz: 1|#]

             

            [#|2012-11-19T10:15:21.476-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=33;_ThreadName=Thread-2;|Stuffz: 1|#]

             

            [#|2012-11-19T10:15:21.476-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=33;_ThreadName=Thread-2;|Stuffz: 1|#]

             

            [#|2012-11-19T10:15:21.476-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=33;_ThreadName=Thread-2;|Stuffz: 1|#]

             

            [#|2012-11-19T10:15:21.476-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=33;_ThreadName=Thread-2;|Stuffz: 1|#]

             

            [#|2012-11-19T10:15:21.476-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=33;_ThreadName=Thread-2;|Stuffz: 1|#]

             

            [#|2012-11-19T10:15:21.476-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=33;_ThreadName=Thread-2;|Stuffz: 1|#]

             

            [#|2012-11-19T10:15:21.476-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=33;_ThreadName=Thread-2;|Stuffz: 1|#]

             

            [#|2012-11-19T10:15:21.491-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=33;_ThreadName=Thread-2;|Stuffz: 2|#]

             


             

             

             

            Instance 2 (on another computer)

             

             

            [#|2012-11-19T10:14:55.366-0600|INFO|glassfish3.1.2|javax.enterprise.resource.webcontainer.jsf.config|_ThreadID=91;_ThreadName=Thread-2;|Initializing Mojarra 2.1.6 (SNAPSHOT 20111206) for context '/InfinispanWeb1'|#]

             

            [#|2012-11-19T10:14:55.834-0600|INFO|glassfish3.1.2|org.primefaces.webapp.PostConstructApplicationEventListener|_ThreadID=91;_ThreadName=Thread-2;|Running on PrimeFaces 3.3.1|#]

             

            [#|2012-11-19T10:14:56.006-0600|SEVERE|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=91;_ThreadName=Thread-2;|log4j:WARN No appenders could be found for logger (org.jboss.logging).|#]

             

            [#|2012-11-19T10:14:56.006-0600|SEVERE|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=91;_ThreadName=Thread-2;|log4j:WARN Please initialize the log4j system properly.|#]

             

            [#|2012-11-19T10:14:56.006-0600|SEVERE|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=91;_ThreadName=Thread-2;|log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.|#]

             

            [#|2012-11-19T10:14:57.069-0600|INFO|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=91;_ThreadName=Thread-2;|WEB0671: Loading application [InfinispanWeb1] at [/InfinispanWeb1]|#]

             

            [#|2012-11-19T10:14:57.100-0600|INFO|glassfish3.1.2|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=91;_ThreadName=Thread-2;|InfinispanWeb1 was successfully deployed in 6,109 milliseconds.|#]

             

            [#|2012-11-19T10:15:40.241-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=786;_ThreadName=Thread-2;|Before setStuffz()|#]

             

            [#|2012-11-19T10:15:45.178-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=786;_ThreadName=Thread-2;|After setStuffz()|#]

             

            [#|2012-11-19T10:15:45.210-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=786;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:54.022-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=787;_ThreadName=Thread-2;|Before setStuffz()|#]

             

            [#|2012-11-19T10:15:54.022-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=787;_ThreadName=Thread-2;|After setStuffz()|#]

             

            [#|2012-11-19T10:15:54.022-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=787;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:54.022-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=787;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:54.022-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=787;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:54.038-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=787;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:54.038-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=787;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:54.038-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=787;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:54.038-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=787;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:54.038-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=787;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:54.038-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=787;_ThreadName=Thread-2;|Stuffz: 0|#]

             

            [#|2012-11-19T10:15:54.069-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=787;_ThreadName=Thread-2;|Stuffz: 1|#]

             


             

             

            Thanks!

            • 3. Re: infinispan: clustred instances not sharing cache
              creatureoflegend Newbie

              Basically what I'm looking to do is  this:

               

              Using Infinispan in servlet containers (such as Tomcat or Jetty) and other application servers (such as GlassFish):

              https://docs.jboss.org/author/display/ISPN/Getting+Started+Guide#GettingStartedGuide-UsingInfinispaninservletcontainers(suchasTomcatorJetty)andotherapplicationservers(suchasGlassFish)

               

              Exactly the part that's missing out of the official Getting Started guide. >.<

              • 4. Re: infinispan: clustred instances not sharing cache
                Tristan Tarrant Master

                JGroups runs as part of your application, so no need for an "external server". From the logs above I see that the first server is starting fine:

                 

                [#|2012-11-19T10:15:12.420-0600|INFO|glassfish3.1.2|org.infinispan.remoting.transport.jgroups.JGroupsTransport|_ThreadID=30;_ThreadName=Thread-2;|ISPN000079: Cache local address is RC-11537-28504, physical addresses are [fe80:0:0:0:d58:a0f5:ce96:b7b3:63427]|#]

                 

                The second server does not seem to do anything (it does not log like the other). Are you sure the context listener is getting invoked ?

                1 of 1 people found this helpful
                • 5. Re: infinispan: clustred instances not sharing cache
                  creatureoflegend Newbie


                  It is. I just put in some more logging in the listener and here's more info:

                   

                  Modification:

                   

                   

                  @Override

                      public void contextInitialized(ServletContextEvent sce)

                      {

                          System.out.println("--------- BEGIN CONTEXT LISTENER contextInitialized(.) -----------");

                          try

                          {

                              manager = new DefaultCacheManager("config.xml");

                   

                              System.out.println("Manager: " + manager);

                   

                              if(manager != null)

                              {

                                  System.out.println("Listener manager.getClusterName(): " + manager.getClusterName());

                                  System.out.println("Listener manager.getMembers(): " + manager.getMembers());

                                  System.out.println("Listener manager.getAddress(): " + manager.getAddress());

                                  System.out.println("Listener manager.getCoordinator(): " + manager.getCoordinator());

                                  System.out.println("Listener manager.getStatus(): " + manager.getStatus());

                                  System.out.println("Listener manager.getTransport(): " + manager.getTransport());

                              }

                   

                  //            manager.start();

                              sce.getServletContext().setAttribute("cacheManager", manager);

                          }

                          catch (IOException ex)

                          {

                              Logger.getLogger(Listener.class.getName()).log(Level.SEVERE, null, ex);

                          }

                          System.out.println("--------- / END ONTEXT LISTENER contextInitialized(.) -----------");

                      }

                   

                   

                   

                  After I re-deployed the app:

                   

                   

                  Clustered instance 1 log:

                  [#|2012-11-19T16:22:33.179-0600|INFO|glassfish3.1.2|javax.enterprise.resource.webcontainer.jsf.config|_ThreadID=28;_ThreadName=Thread-2;|Initializing Mojarra 2.1.6 (SNAPSHOT 20111206) for context '/InfinispanWeb1'|#]

                   

                  [#|2012-11-19T16:22:33.905-0600|INFO|glassfish3.1.2|org.primefaces.webapp.PostConstructApplicationEventListener|_ThreadID=28;_ThreadName=Thread-2;|Running on PrimeFaces 3.3.1|#]

                   

                  [#|2012-11-19T16:22:33.905-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=28;_ThreadName=Thread-2;|--------- BEGIN CONTEXT LISTENER contextInitialized(.) -----------|#]

                   

                  [#|2012-11-19T16:22:35.937-0600|INFO|glassfish3.1.2|org.infinispan.configuration.parsing.Parser|_ThreadID=28;_ThreadName=Thread-2;|ISPN000186: hash's 'rehashRpcTimeout' attribute has been deprecated. Please use stateTransfer.timeout instead|#]

                   

                  [#|2012-11-19T16:22:37.464-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=28;_ThreadName=Thread-2;|Manager: org.infinispan.manager.DefaultCacheManager@528779@Address:null|#]

                   

                  [#|2012-11-19T16:22:37.464-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=28;_ThreadName=Thread-2;|Listener manager.getClusterName(): PeachCluster|#]

                   

                  [#|2012-11-19T16:22:37.464-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=28;_ThreadName=Thread-2;|Listener manager.getMembers(): []|#]

                   

                  [#|2012-11-19T16:22:37.464-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=28;_ThreadName=Thread-2;|Listener manager.getAddress(): null|#]

                   

                  [#|2012-11-19T16:22:37.464-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=28;_ThreadName=Thread-2;|Listener manager.getCoordinator(): null|#]

                   

                  [#|2012-11-19T16:22:37.464-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=28;_ThreadName=Thread-2;|Listener manager.getStatus(): INSTANTIATED|#]

                   

                  [#|2012-11-19T16:22:37.464-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=28;_ThreadName=Thread-2;|Listener manager.getTransport(): org.infinispan.remoting.transport.jgroups.JGroupsTransport@3c266f|#]

                   

                  [#|2012-11-19T16:22:37.464-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=28;_ThreadName=Thread-2;|--------- / END ONTEXT LISTENER contextInitialized(.) -----------|#]

                   

                  [#|2012-11-19T16:22:37.494-0600|INFO|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=28;_ThreadName=Thread-2;|WEB0671: Loading application [InfinispanWeb1] at [/InfinispanWeb1]|#]

                   

                  [#|2012-11-19T16:22:37.504-0600|INFO|glassfish3.1.2|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=28;_ThreadName=Thread-2;|InfinispanWeb1 was successfully deployed in 10,166 milliseconds.|#]

                   


                   

                   

                   

                  Clustered Instance 2 log:

                   

                   

                  [#|2012-11-19T16:22:32.413-0600|INFO|glassfish3.1.2|javax.enterprise.resource.webcontainer.jsf.config|_ThreadID=127;_ThreadName=Thread-2;|Initializing Mojarra 2.1.6 (SNAPSHOT 20111206) for context '/InfinispanWeb1'|#]

                   

                  [#|2012-11-19T16:22:32.897-0600|INFO|glassfish3.1.2|org.primefaces.webapp.PostConstructApplicationEventListener|_ThreadID=127;_ThreadName=Thread-2;|Running on PrimeFaces 3.3.1|#]

                   

                  [#|2012-11-19T16:22:32.897-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=127;_ThreadName=Thread-2;|--------- BEGIN CONTEXT LISTENER contextInitialized(.) -----------|#]

                   

                  [#|2012-11-19T16:22:34.226-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=127;_ThreadName=Thread-2;|Manager: org.infinispan.manager.DefaultCacheManager@1d41657@Address:null|#]

                   

                  [#|2012-11-19T16:22:34.226-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=127;_ThreadName=Thread-2;|Listener manager.getClusterName(): PeachCluster|#]

                   

                  [#|2012-11-19T16:22:34.226-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=127;_ThreadName=Thread-2;|Listener manager.getMembers(): []|#]

                   

                  [#|2012-11-19T16:22:34.226-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=127;_ThreadName=Thread-2;|Listener manager.getAddress(): null|#]

                   

                  [#|2012-11-19T16:22:34.226-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=127;_ThreadName=Thread-2;|Listener manager.getCoordinator(): null|#]

                   

                  [#|2012-11-19T16:22:34.226-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=127;_ThreadName=Thread-2;|Listener manager.getStatus(): INSTANTIATED|#]

                   

                  [#|2012-11-19T16:22:34.226-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=127;_ThreadName=Thread-2;|Listener manager.getTransport(): org.infinispan.remoting.transport.jgroups.JGroupsTransport@106bc21|#]

                   

                  [#|2012-11-19T16:22:34.226-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=127;_ThreadName=Thread-2;|--------- / END ONTEXT LISTENER contextInitialized(.) -----------|#]

                   

                  [#|2012-11-19T16:22:34.241-0600|INFO|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=127;_ThreadName=Thread-2;|WEB0671: Loading application [InfinispanWeb1] at [/InfinispanWeb1]|#]

                   

                  [#|2012-11-19T16:22:34.272-0600|INFO|glassfish3.1.2|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=127;_ThreadName=Thread-2;|InfinispanWeb1 was successfully deployed in 5,390 milliseconds.|#]

                   

                  [#|2012-11-19T16:22:51.710-0600|INFO|glassfish3.1.2|com.hazelcast.impl.PartitionManager|_ThreadID=108;_ThreadName=Thread-2;|[10.4.28.94]:5701 [dev] Remaining migration tasks in queue => Immediate-Tasks: 1, Scheduled-Tasks: 0|#]

                  • 6. Re: infinispan: clustred instances not sharing cache
                    Tristan Tarrant Master

                    Hi Anastasia,

                    I built your package and it deployed fine. I made a couple of changes, however. Firstly I cleaned up the config.xml file by adding namespace info:

                     

                    {code:xml}<?xml version="1.0" encoding="UTF-8"?>

                    <infinispan

                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                          xsi:schemaLocation="urn:infinispan:config:5.1 http://docs.jboss.org/infinispan/schemas/infinispan-config-5.1.xsd"

                          xmlns="urn:infinispan:config:5.1">

                     

                        <global>

                          <transport clusterName="demoCluster"/>

                          <globalJmxStatistics enabled="true"/>

                       </global>

                     

                       <default>

                          <jmxStatistics enabled="true"/>

                          <clustering mode="distribution">

                             <hash numOwners="2" rehashRpcTimeout="100"/>

                             <sync/>

                          </clustering>

                       </default>

                     

                    </infinispan>{code}

                     

                    Then I added a getCache("stuffz") method in your listener, so that the cache is initialized at startup:

                     

                    {code:java}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;

                     

                    /**

                    * Web application lifecycle listener.

                    *

                    * @author aerohner

                    */

                    @WebListener()

                    public class Listener implements ServletContextListener {

                       EmbeddedCacheManager manager;

                     

                       @Override

                       public void contextInitialized(ServletContextEvent sce) {

                          try {

                             manager = new DefaultCacheManager("config.xml");

                             //            manager.start();

                             manager.getCache("stuffz");

                             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}

                     

                    As soon as you deploy the applications they should start the caches and form a cluster.

                    Let me know if this works

                    1 of 1 people found this helpful
                    • 7. Re: infinispan: clustred instances not sharing cache
                      creatureoflegend Newbie

                      Sorry, what namespace did you add to the config? It's not showing up in the post.

                       

                      I put the line that grabs the cache in the listener like you did, but it didn't do the trick:

                       

                      Both of the cluster instances are running on two different phsyical machenes. So I'm wondering if maybe that together w/ the following message may be the issue:

                       

                      java.net.BindException: Cannot assign requested address: Datagram send failed

                       

                       

                       

                      On the line where I print out manager.getMembers, each of the cluster instances only prints out it's own line:

                       

                       

                      Instance 1

                      [#|2012-11-21T08:22:17.688-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=21;_ThreadName=Thread-2;|--------- BEGIN CONTEXT LISTENER contextInitialized(.) -----------|#]

                       

                      [#|2012-11-21T08:22:19.996-0600|INFO|glassfish3.1.2|org.infinispan.configuration.parsing.Parser|_ThreadID=21;_ThreadName=Thread-2;|ISPN000186: hash's 'rehashRpcTimeout' attribute has been deprecated. Please use stateTransfer.timeout instead|#]

                       

                      [#|2012-11-21T08:22:20.995-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=21;_ThreadName=Thread-2;|Manager: org.infinispan.manager.DefaultCacheManager@1ad0ff8@Address:null|#]

                       

                      [#|2012-11-21T08:22:21.995-0600|INFO|glassfish3.1.2|org.infinispan.remoting.transport.jgroups.JGroupsTransport|_ThreadID=21;_ThreadName=Thread-2;|ISPN000078: Starting JGroups Channel|#]

                       

                      [#|2012-11-21T08:22:21.995-0600|INFO|glassfish3.1.2|org.infinispan.remoting.transport.jgroups.JGroupsTransport|_ThreadID=21;_ThreadName=Thread-2;|ISPN000088: Unable to use any JGroups configuration mechanisms provided in properties {}. Using default JGroups configuration!|#]

                       

                      [#|2012-11-21T08:22:24.104-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=21;_ThreadName=Thread-2;|2012-11-21 08:22:24,104 ERROR [UDP] (http-thread-pool-24848(5)) failed sending message to cluster (124 bytes): java.lang.Exception: dest=/ff0e:0:0:0:0:0:e406:708:46655 (127 bytes), cause: java.net.BindException: Cannot assign requested address: Datagram send failed

                      |#]

                       

                      [#|2012-11-21T08:22:27.182-0600|INFO|glassfish3.1.2|org.infinispan.remoting.transport.jgroups.JGroupsTransport|_ThreadID=21;_ThreadName=Thread-2;|ISPN000094: Received new cluster view: [RC-11537-2515|0] [RC-11537-2515]|#]

                       

                      [#|2012-11-21T08:22:27.260-0600|INFO|glassfish3.1.2|org.infinispan.remoting.transport.jgroups.JGroupsTransport|_ThreadID=21;_ThreadName=Thread-2;|ISPN000079: Cache local address is RC-11537-2515, physical addresses are [fe80:0:0:0:d58:a0f5:ce96:b7b3:58622]|#]

                       

                      [#|2012-11-21T08:22:27.291-0600|INFO|glassfish3.1.2|org.infinispan.factories.GlobalComponentRegistry|_ThreadID=21;_ThreadName=Thread-2;|ISPN000128: Infinispan version: Infinispan 'Brahma' 5.1.6.FINAL|#]

                       

                      [#|2012-11-21T08:22:28.697-0600|INFO|glassfish3.1.2|org.infinispan.jmx.CacheJmxRegistration|_ThreadID=21;_ThreadName=Thread-2;|ISPN000031: MBeans were successfully registered to the platform mbean server.|#]

                       

                      [#|2012-11-21T08:22:28.822-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=21;_ThreadName=Thread-2;|Listener manager.getClusterName(): PeachCluster|#]

                       

                      [#|2012-11-21T08:22:28.822-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=21;_ThreadName=Thread-2;|Listener manager.getMembers(): [RC-11537-2515]|#]

                       

                      [#|2012-11-21T08:22:28.822-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=21;_ThreadName=Thread-2;|Listener manager.getAddress(): RC-11537-2515|#]

                       

                      [#|2012-11-21T08:22:28.822-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=21;_ThreadName=Thread-2;|Listener manager.getCoordinator(): RC-11537-2515|#]

                       

                      [#|2012-11-21T08:22:28.822-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=21;_ThreadName=Thread-2;|Listener manager.getStatus(): RUNNING|#]

                       

                      [#|2012-11-21T08:22:28.822-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=21;_ThreadName=Thread-2;|Listener manager.getTransport(): org.infinispan.remoting.transport.jgroups.JGroupsTransport@1e890b4|#]

                       

                      [#|2012-11-21T08:22:28.822-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=21;_ThreadName=Thread-2;|--------- / END ONTEXT LISTENER contextInitialized(.) -----------|#]

                       

                       

                       

                      instance 2:

                       

                      [#|2012-11-21T08:22:10.833-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=129;_ThreadName=Thread-2;|--------- BEGIN CONTEXT LISTENER contextInitialized(.) -----------|#]

                       

                      [#|2012-11-21T08:22:12.146-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=129;_ThreadName=Thread-2;|Manager: org.infinispan.manager.DefaultCacheManager@3a5e19@Address:null|#]

                       

                      [#|2012-11-21T08:22:16.990-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=129;_ThreadName=Thread-2;|Listener manager.getClusterName(): PeachCluster|#]

                       

                      [#|2012-11-21T08:22:16.990-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=129;_ThreadName=Thread-2;|Listener manager.getMembers(): [RC-11164-2420]|#]

                       

                      [#|2012-11-21T08:22:16.990-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=129;_ThreadName=Thread-2;|Listener manager.getAddress(): RC-11164-2420|#]

                       

                      [#|2012-11-21T08:22:16.990-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=129;_ThreadName=Thread-2;|Listener manager.getCoordinator(): RC-11164-2420|#]

                       

                      [#|2012-11-21T08:22:16.990-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=129;_ThreadName=Thread-2;|Listener manager.getStatus(): RUNNING|#]

                       

                      [#|2012-11-21T08:22:16.990-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=129;_ThreadName=Thread-2;|Listener manager.getTransport(): org.infinispan.remoting.transport.jgroups.JGroupsTransport@d78416|#]

                       

                      [#|2012-11-21T08:22:16.990-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=129;_ThreadName=Thread-2;|--------- / END ONTEXT LISTENER contextInitialized(.) -----------|#]

                       

                      • 8. Re: infinispan: clustred instances not sharing cache
                        Tristan Tarrant Master

                        Ok, I fixed the XML above.

                        The problem is mostly with IPv6. Please run your application server with the -Djava.net.preferIPv4Stack=true switch

                        • 9. Re: infinispan: clustred instances not sharing cache
                          creatureoflegend Newbie

                          OMG!!!!!!!!!!!!!!!!!!!!!!!!!!

                           

                          That totally worked!!!! Thank you  SO much!