13 Replies Latest reply on Aug 15, 2016 7:27 AM by sebastian.laskawiec

    Problem with Infinispan CDI

    seto

      Exception in thread "Thread-2" org.infinispan.jmx.JmxDomainConflictException: ISPN000034: There's already a JMX MBean instance type=CacheManager,name="CDIExtensionDefaultCacheManager" already registered under 'org.infinispan' JMX domain. If you want to allow multiple instances configured with same JMX domain enable 'allowDuplicateDomains' attribute in 'globalJmxStatistics' config element

        at org.infinispan.jmx.JmxUtil.buildJmxDomain(JmxUtil.java:52)

        at org.infinispan.jmx.CacheManagerJmxRegistration.updateDomain(CacheManagerJmxRegistration.java:79)

        at org.infinispan.jmx.CacheManagerJmxRegistration.buildRegistrar(CacheManagerJmxRegistration.java:73)

        at org.infinispan.jmx.AbstractJmxRegistration.registerMBeans(AbstractJmxRegistration.java:37)

        at org.infinispan.jmx.CacheManagerJmxRegistration.start(CacheManagerJmxRegistration.java:41)

        at org.infinispan.manager.DefaultCacheManager.start(DefaultCacheManager.java:657)

        at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:232)

        at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:209)

        at org.infinispan.cdi.DefaultEmbeddedCacheManagerProducer.getDefaultEmbeddedCacheManager(DefaultEmbeddedCacheManagerProducer.java:43)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:497)

        at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:88)

        at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:78)

        at org.jboss.weld.injection.producer.ProducerMethodProducer.produce(ProducerMethodProducer.java:99)

        at org.jboss.weld.injection.producer.AbstractMemberProducer.produce(AbstractMemberProducer.java:161)

        at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:181)

        at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96)

        at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:101)

        at org.jboss.weld.bean.ContextualInstanceStrategy$ApplicationScopedContextualInstanceStrategy.get(ContextualInstanceStrategy.java:141)

        at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)

        at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:99)

        at org.jboss.weld.bean.proxy.ProxyMethodHandler.getInstance(ProxyMethodHandler.java:125)

        at org.infinispan.manager.BasicCacheContainer$CacheContainer$EmbeddedCacheManager$Lifecycle$Listenable$274507849$Proxy$_$$_WeldClientProxy.toString(Unknown Source)

        at java.lang.String.valueOf(String.java:2994)

        at java.lang.StringBuilder.append(StringBuilder.java:131)

        at org.infinispan.cdi.util.Reflections.buildInvokeMethodErrorMessage(Reflections.java:87)

        at org.infinispan.cdi.util.Reflections.invokeMethod(Reflections.java:203)

        at org.infinispan.cdi.util.Reflections.invokeMethod(Reflections.java:126)

        at org.infinispan.cdi.util.InjectableMethod.invoke(InjectableMethod.java:153)

        at org.infinispan.cdi.util.InjectableMethod.invoke(InjectableMethod.java:110)

        at org.infinispan.cdi.util.defaultbean.DefaultProducerMethod.destroy(DefaultProducerMethod.java:42)

        at org.jboss.weld.util.bean.IsolatedForwardingBean.destroy(IsolatedForwardingBean.java:50)

        at org.jboss.weld.context.AbstractContext.destroyContextualInstance(AbstractContext.java:147)

        at org.jboss.weld.context.AbstractContext.destroy(AbstractContext.java:161)

        at org.jboss.weld.context.AbstractSharedContext.destroy(AbstractSharedContext.java:61)

        at org.jboss.weld.context.AbstractSharedContext.invalidate(AbstractSharedContext.java:56)

        at org.jboss.weld.bootstrap.WeldRuntime.shutdown(WeldRuntime.java:56)

        at org.jboss.weld.bootstrap.WeldBootstrap.shutdown(WeldBootstrap.java:113)

        at org.jboss.weld.environment.se.WeldContainer.shutdown(WeldContainer.java:237)

        at org.jboss.weld.environment.se.WeldContainer$ShutdownHook.run(WeldContainer.java:276)

       

      Kernal.java

      package co.kaiba.blueeyes.impl.kernel;

      import co.kaiba.blueeyes.impl.service.data.NameCache;
      import org.infinispan.Cache;
      import org.jboss.weld.environment.se.bindings.Parameters;
      import org.jboss.weld.environment.se.events.ContainerInitialized;

      import javax.enterprise.event.Observes;
      import javax.inject.Inject;
      import javax.inject.Singleton;
      import java.util.List;
      import java.util.Properties;

      /**
      * Created by Seto on 2016/4/21.
      */
      @Singleton
      public class Kernel {

         @Inject
        @NameCache
         Cache<String, String> nameCache;

        public void onContainerInitialized(@Observes ContainerInitialized event, @Parameters List<String> parameters) {

        System.out.println("aaa");
         Properties appProperties;
        if (parameters.size() == 1) {

        appProperties = findProperties(parameters.get(0));
         } else {

        appProperties = findProperties(null);
         }

        }

       

         private static Properties findProperties(String propLoc) {

        Properties baseProperties = new Properties();
        return baseProperties;
         }

      }

       

      DataServiceImpl.java

      package co.kaiba.blueeyes.impl.service.data;

      import org.infinispan.cdi.ConfigureCache;
      import org.infinispan.configuration.cache.Configuration;
      import javax.enterprise.inject.Produces;

      /**
      * Created by Seto on 2016/4/21.
      */
      public class DataServiceImpl {

       

         @ConfigureCache("name-cache")

         @NameCache
        @Produces
         public Configuration nameCacheConfig;
      }

       

      NameCache.java

      package co.kaiba.blueeyes.impl.service.data;

        import javax.inject.Qualifier;
        import java.lang.annotation.*;

      /**
      * Created by Seto on 2016/4/22.
      */
      @Qualifier
      @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})

      @Retention(RetentionPolicy.RUNTIME)

      @Documented
      public @interface NameCache {

      }

      Just a simple enough application. Please help. What's my problem?

        • 1. Re: Problem with Infinispan CDI
          sebastian.laskawiec

          Could you tell me what Infinispan version are you using? I've been fixing similar one in Infinispan 7. So here's what you might try to fix it:

          1. Use the latest Infinispan version.
          2. Produce your own EmbeddedCacheManager which would allow duplicated JMX domains.

           

          Could you please attach a full reproducer to this thread? I would like to have a look - maybe there is something specific to your example that this issue appears.

          • 2. Re: Problem with Infinispan CDI
            seto

            1. I use Infinispan 8.2.1.Final.

            2. Do I have to use an EmbeddedCacheManager which would allow duplicated JMX domains?

             

            It seems that it's a problem of Weld Shutdown Hook. Why does it produce the embedded manager again? Maybe I misunderstand the use of Infinispan CDI. Please help.

             

            If I produce my own EmbededCacheManager as below. Then the cache manager is a clustered one and Weld won't shutdown. Then no problem is reported.

            @Produces
            @ApplicationScoped
            public EmbeddedCacheManager defaultClusteredCacheManager() {

              GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder();
               ConfigurationBuilder builder = new ConfigurationBuilder();
               builder.clustering().cacheMode(CacheMode.DIST_SYNC);
              return new DefaultCacheManager(global.build(), builder.build());
            }

             

            I edited the above post. The all 3 java file sources is posted. Main Class is org.jboss.weld.environment.se.StartMain.

            The dependencies are below

            • org.jboss.weld.se:weld-se:2.3.4.Final
            • org.infinispan:infinispan-embedded:8.2.1.Final
            • org.hibernate:hibernate-core:5.1.0.Final
            • javax.cache:cache-api:1.0.0
            • 3. Re: Problem with Infinispan CDI
              sebastian.laskawiec

              If you create an EmbeddedCacheManager yourself, you need to kill it. Please have a look at one of our tests.

               

              However the root problem stays the same - why do you have 2 instances in you BeanManager? I'll try to recreate your example in some separate repository and check what's going on.

               

              Just one missing bit - do you use any beans.xml?

              • 4. Re: Problem with Infinispan CDI
                seto

                beans.xml

                <!--

                 

                 

                    JBoss, Home of Professional Open Source

                    Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual

                    contributors by the @authors tag. See the copyright.txt in the

                    distribution for a full listing of individual contributors.

                 

                 

                    Licensed under the Apache License, Version 2.0 (the "License");

                    you may not use this file except in compliance with the License.

                    You may obtain a copy of the License at

                    http://www.apache.org/licenses/LICENSE-2.0

                    Unless required by applicable law or agreed to in writing, software

                    distributed under the License is distributed on an "AS IS" BASIS,

                    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

                    See the License for the specific language governing permissions and

                    limitations under the License.

                 

                 

                -->

                <beans></beans>

                 

                log4j.properties

                #

                # JBoss, Home of Professional Open Source

                # Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual

                # contributors by the @authors tag. See the copyright.txt in the

                # distribution for a full listing of individual contributors.

                #

                # Licensed under the Apache License, Version 2.0 (the "License");

                # you may not use this file except in compliance with the License.

                # You may obtain a copy of the License at

                # http://www.apache.org/licenses/LICENSE-2.0

                # Unless required by applicable law or agreed to in writing, software

                # distributed under the License is distributed on an "AS IS" BASIS,

                # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

                # See the License for the specific language governing permissions and

                # limitations under the License.

                #

                # Set root logger level to DEBUG and its only appender to A1.

                log4j.rootLogger=WARN, A1

                 

                 

                # A1 is set to be a ConsoleAppender.

                log4j.appender.A1=org.apache.log4j.ConsoleAppender

                 

                 

                # A1 uses PatternLayout.

                log4j.appender.A1.layout=org.apache.log4j.PatternLayout

                log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

                • 5. Re: Problem with Infinispan CDI
                  seto

                  If I don't place the beans.xml to the resources. Then the weld container won't start.

                  • 6. Re: Problem with Infinispan CDI
                    seto

                    If you can't reproduce this problem, I can upload the project.

                    But I'm using Gradle with IntelliJ.

                    • 7. Re: Problem with Infinispan CDI
                      sebastian.laskawiec

                      I managed to reproduce the problem (here is my project: GitHub - slaskawi/CDI_269431)

                       

                      Your code is fine but there are a couple of problems on our side:

                       

                      So until we fix those problems, here are the options which might help you:

                      • 8. Re: Problem with Infinispan CDI
                        seto

                        Hi. I found 9.0.0.Alpha3 fixes my problem. Then I try to use 9.0.0.Alpha3.

                        A new problem is reported.

                        ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

                        Exception in thread "main" org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type CacheContainer with qualifiers @Default

                          at injection point [BackedAnnotatedField] @Inject private org.infinispan.cdi.embedded.AdvancedCacheProducer.defaultCacheContainer

                          at org.infinispan.cdi.embedded.AdvancedCacheProducer.defaultCacheContainer(AdvancedCacheProducer.java:0)

                         

                         

                          at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:359)

                          at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:281)

                          at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:134)

                          at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:155)

                          at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:518)

                          at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:68)

                          at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:66)

                          at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:63)

                          at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:56)

                          at java.util.concurrent.FutureTask.run(FutureTask.java:266)

                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

                          at java.lang.Thread.run(Thread.java:745)

                        • 9. Re: Problem with Infinispan CDI
                          sebastian.laskawiec

                          Hi Seto!

                           

                          Thanks for the heads up! There was another commit (which didn't get into Alpha3 but will be in Alpha4) that fixed this problem [1]. You may give it a go and use our SNAPSHOTs (here is an updated reproducer with [2])

                           

                          Thanks

                          Sebastian

                           

                          [1] ISPN-6242 Migrate to CDI 1.2 with annotation bean discovery · infinispan/infinispan@57ebf7b · GitHub

                          [2] GitHub - slaskawi/CDI_269431 at 9.0.0-SNAPSHOT

                          • 10. Re: Problem with Infinispan CDI
                            seto

                            I tried Alpha4. The problem has gone.

                             

                            Is this log a normal log?

                            Weld SE container STATIC_INSTANCE shut down by shutdown hook

                            And is the 8.2.4.Final also with this problem fixed? It's released after 9.0.0.Alpha4.

                            • 11. Re: Problem with Infinispan CDI
                              sebastian.laskawiec

                              You probably need to invoke weld.close(). See this test for reference.

                              • 12. Re: Problem with Infinispan CDI
                                seto

                                If I start the container use org.jboss.weld.environment.se.StartMain and ContainerInitialized event observer. Do I need to manually close weld container?

                                • 13. Re: Problem with Infinispan CDI
                                  sebastian.laskawiec

                                  No it's not necessary. You can leave it as is and let Weld shut everything down using the shutdown hook.

                                   

                                  See this manual entry for reference.