2 Replies Latest reply on Jul 9, 2012 10:15 AM by a_w

    Application problems using Infinispan directly running under JBoss AS 6.1

    a_w

      Hello!

       

      I've been working on getting a shared cache running across multiple nodes in a JBoss AS 6.1.0 cluster, and have had some luck.  Originally I went the route of defining my own infinispan & jgroups xml files to create everything manually.  In our production environment, that is less than desired since we already create one TCPPING cluster for infinispan and I was going to have to pass in another initial cluster.

       

      In hunting down documentation I came across the Infinispan & AS6 integration guide here:

      https://community.jboss.org/wiki/InfinispanIntegrationInAS6

       

      I also took a look at this thread:

      https://community.jboss.org/thread/160116

       

      Those two were the most relevant my (admittedly impatient) searching turned up.

       

      My goal is to go with the option to have the application create a cache of it's own so the original JBoss configuration files don't have to be edited at all for this application.

       

      With that in mind I threw together a pretty rough test application to create just a simple cache that I could put data in and get data out of via a soap call.

       

      I am just not getting the reference to the cache container created in the beans xml file.  I've gone through several iterations trying to get the information in & out using JNDI, injection, etc.  I'm going to use the last code that's based on what I got out of the linked thread above (160116) as the starting point for this thread as it is halfway clean and simple.  As it stands, I have not been able to get access to the CacheContainer.

       

      All that being said, I am a bit rusty and mixing MC & EJBs is throwing me off a bit so forgive me if the solution is as simple as I suspect it is.

       

      Source is below, and attached is a zip file set of the files in a Maven project.  I have my local settings pointing at a Maven repo that acts as a proxy for several other Maven repositories including JBoss's which you may need to do as well to use it.  (The pom files are hackish as I yanked them out of the original project that this is for to use them for the example.)

       

      Versions are:

       

      Product
      Version
      JBoss6.1.0 (all server configuration)
      Infinispanprovided with AS
      Javajava version "1.6.0_27"

       

       

       

      The interface is this:

      package andrew.cache.example;
      
      public interface CacheTestService {
      
                public String getStatus();
      
                public String putIn(String key, String value);
      
                public String getOut(String key);
      
      }
      

       

       

       

       

       

      And it is implemented in this class:

      package andrew.cache.example;
      
      
      import java.text.DateFormat;
      import java.text.SimpleDateFormat;
      import java.util.Date;
      
      
      import javax.ejb.Remote;
      import javax.ejb.Stateless;
      import javax.jws.WebMethod;
      import javax.jws.WebParam;
      import javax.jws.WebResult;
      import javax.jws.WebService;
      import javax.jws.soap.SOAPBinding;
      
      
      import org.infinispan.Cache;
      import org.infinispan.manager.CacheContainer;
      import org.jboss.beans.metadata.api.annotations.Inject;
      import org.slf4j.Logger;
      import org.slf4j.LoggerFactory;
      
      
      @Stateless
      @WebService(name = "CacheTestService", serviceName = "CacheTestService")
      @Remote(CacheTestService.class)
      @SOAPBinding(style = SOAPBinding.Style.RPC)
      public class CacheTestServiceImpl implements CacheTestService {
                static final Logger log = LoggerFactory
                                    .getLogger(CacheTestServiceImpl.class);
      
      
                private static final String sep = "***************";
      
      
                private Cache<String, String> cache;
      
      
                // @Resource(name = "CustomCacheContainer")
                @Inject(bean = "CustomCacheContainer")
                private CacheContainer cc;
      
      
                public CacheTestServiceImpl() {
      
      
                          if (cc != null) {
                                    log.info("\n" + sep + "\nCache Container Exists\n" + sep + "\n");
                          } else {
                                    log.info("\n" + sep + "\nCache Container DOES NOT Exist\n" + sep
                                                        + "\n");
                          }
      
      
                          if (cc != null) {
                                    this.cache = cc.getCache();
                          } else {
                                    this.cache = null;
                          }
      
      
                }
      
      
                @WebMethod
                @WebResult(name = "status")
                public String getStatus() {
                          String methodName = Thread.currentThread().getStackTrace()[1]
                                              .getMethodName();
                          DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSSS");
                          Date d = new Date();
      
      
                          StringBuffer sb = new StringBuffer();
                          if (cc != null && this.cache != null) {
                                    sb.append(df.format(d));
                                    sb.append("\n");
                                    sb.append("Cache Name: ");
                                    sb.append(this.cache.getName());
                                    sb.append("\n");
                                    sb.append("Cache size:");
                                    sb.append(this.cache.size());
                                    sb.append("\n");
                                    sb.append("Status: ");
                                    sb.append(this.cache.getStatus().toString());
                                    sb.append("\n");
                                    sb.append("Version: ");
                                    sb.append(this.cache.getVersion());
                                    sb.append("\n");
                          } else {
                                    sb.append("\n" + sep + "\nCache Container DOES NOT Exist\n" + sep
                                                        + "\n");
                          }
      
      
                          log.info(sb.toString());
                          return sb.toString();
                }
      
      
                @Override
                @WebMethod
                @WebResult(name = "status")
                public String putIn(@WebParam(name = "key") String key,
                                    @WebParam(name = "value") String value) {
      
      
                          if (this.cache == null) {
                                    String msg = "Sorry, cache is null";
                                    log.info(msg);
                                    return msg;
                          }
      
      
                          try {
      
      
                                    this.cache.put(key, value);
                                    log.info("Inserted value <" + key + "," + value + ">");
                                    return "success";
                          } catch (Exception e) {
                                    return e.toString();
                          }
                }
      
      
                @Override
                @WebMethod
                @WebResult(name = "value")
                public String getOut(@WebParam(name = "key") String key) {
      
      
                          if (this.cache == null) {
                                    String msg = "Sorry, cache is null";
                                    log.info(msg);
                                    return msg;
                          }
      
      
                          String val = null;
      
      
                          if (this.cache.containsKey(key)) {
                                    log.info("Value found for <" + key + ">");
                                    val = this.cache.get(key).toString();
                          }
      
      
                          return val;
                }
      
      
      }
      
      

       

      The bean information is in cachetest-jboss-beans.xml:

      <?xml version="1.0" encoding="UTF-8" ?>
      
      
      <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
          xmlns="urn:jboss:bean-deployer:2.0">
      
      
          <!-- Factory created cache container -->
          <bean name="CustomCacheContainer" class="org.infinispan.manager.CacheContainer">
              <constructor factoryMethod="createCacheContainer">
                  <factory bean="CacheContainerFactory" />
                  <parameter>
                      <bean class="org.jboss.ha.ispn.CacheContainerConfiguration">
                          <constructor>
                              <parameter>
                                  <bean
                                      class="org.infinispan.config.GlobalConfiguration">
                                      <property name="clusterName">${jboss.partition.name:DefaultPartition}-PANZA
                                      </property>
                                      <property name="transportProperties">
                                          <map class="java.util.Properties"
                                              keyClass="java.lang.String"
                                              valueClass="java.lang.String">
                                              <entry>
                                                  <key>stack</key>
                                                  <value>udp</value>
                                              </entry>
                                          </map>
                                      </property>
                                      <property name="exposeGlobalJmxStatistics">true</property>
                                      <property name="cacheManagerName">PANZA</property>
                                      <!-- Define global configuration properties -->
                                  </bean>
                              </parameter>
                              <parameter>
                                  <bean class="org.infinispan.config.Configuration">
                                      <!-- Define default configuration properties -->
                                  </bean>
                              </parameter>
                          </constructor>
                      </bean>
                  </parameter>
              </constructor>
          </bean>
      </deployment>
      
      

       

      Edit to add server configuration.