[infinispan-issues] [JBoss JIRA] (ISPN-4971) CDI uses default EmbeddedCacheManager producer from infinispan-cdi.jar instead of custom one
Sebastian Łaskawiec (JIRA)
issues at jboss.org
Mon Jan 19 04:21:49 EST 2015
[ https://issues.jboss.org/browse/ISPN-4971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13033397#comment-13033397 ]
Sebastian Łaskawiec commented on ISPN-4971:
-------------------------------------------
When deploying this code on App Server, there is a race condition in {{DefaultEmbeddedCacheManagerProducer#getDefaultEmbeddedCacheManager}}. Those EmbeddedCache producers are deployed in separate deployment units (the former is in CDI Extension and the latter in WAR). On the other hand this approach works fine in CDI module, mainly because there is only one deployment unit there.
Since {{@OverrideDefault}} is deprecated and will be removed, I suggest modifying test code like this:
{code}
public class EmbeddedCacheManagerProducer {
@Produces
@ApplicationScoped
public EmbeddedCacheManager getDefaultEmbeddedCacheManager(Configuration defaultConfiguration) {
GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder().globalJmxStatistics().allowDuplicateDomains(true).build();
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.read(defaultConfiguration);
return new DefaultCacheManager(globalConfiguration, builder.build());
}
private void stopCacheManager(@Disposes EmbeddedCacheManager defaultEmbeddedCacheManager) {
defaultEmbeddedCacheManager.stop();
}
}
{code}
Note that {{@OverrideDefault}} is gone and there is no need to check whether there is an instance of {{EmbeddedCache}} ({{Instance<EmbeddedCacheManager>}}).
> CDI uses default EmbeddedCacheManager producer from infinispan-cdi.jar instead of custom one
> --------------------------------------------------------------------------------------------
>
> Key: ISPN-4971
> URL: https://issues.jboss.org/browse/ISPN-4971
> Project: Infinispan
> Issue Type: Bug
> Components: CDI Integration
> Affects Versions: 7.0.0.CR1, 7.0.0.CR2, 7.0.0.Final
> Reporter: Vitalii Chepeliuk
> Assignee: Sebastian Łaskawiec
>
> Custom producer has allowDuplicateDomains set to true look following code
> {code}
> public class EmbeddedCacheManagerProducer {
> /**
> * Produces the default embedded cache manager.
> *
> * @param providedDefaultEmbeddedCacheManager the provided default embedded cache manager.
> * @param defaultConfiguration the default configuration produced by the {@link EmbeddedCacheManagerProducer}.
> * @return the default embedded cache manager used by the application.
> */
> @Produces
> @ApplicationScoped
> public EmbeddedCacheManager getDefaultEmbeddedCacheManager(@OverrideDefault Instance<EmbeddedCacheManager> providedDefaultEmbeddedCacheManager, Configuration defaultConfiguration) {
> GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder().globalJmxStatistics().allowDuplicateDomains(true).build();
> ConfigurationBuilder builder = new ConfigurationBuilder();
> builder.read(defaultConfiguration);
> return new DefaultCacheManager(globalConfiguration, builder.build());
> }
> /**
> * Stops the default embedded cache manager when the corresponding instance is released.
> *
> * @param defaultEmbeddedCacheManager the default embedded cache manager.
> */
> private void stopCacheManager(@Disposes EmbeddedCacheManager defaultEmbeddedCacheManager) {
> defaultEmbeddedCacheManager.stop();
> }
> }
> {code}
> And default ones from infinispan-cdi.jar is
> {code}
> public class DefaultEmbeddedCacheManagerProducer {
> private static final Log log = LogFactory.getLog(DefaultEmbeddedCacheManagerProducer.class, Log.class);
> /**
> * Produces the default embedded cache manager.
> *
> * @param providedDefaultEmbeddedCacheManager the provided default embedded cache manager.
> * @param defaultConfiguration the default configuration produced by the {@link DefaultEmbeddedCacheConfigurationProducer}.
> * @return the default embedded cache manager used by the application.
> */
> @Produces
> @ApplicationScoped
> @DefaultBean(EmbeddedCacheManager.class)
> public EmbeddedCacheManager getDefaultEmbeddedCacheManager(@OverrideDefault Instance<EmbeddedCacheManager> providedDefaultEmbeddedCacheManager, Configuration defaultConfiguration) {
> if (!providedDefaultEmbeddedCacheManager.isUnsatisfied()) {
> log.tracef("Default embedded cache manager overridden by '%s'", providedDefaultEmbeddedCacheManager);
> return providedDefaultEmbeddedCacheManager.get();
> }
> return new DefaultCacheManager(defaultConfiguration);
> }
> /**
> * Stops the default embedded cache manager when the corresponding instance is released.
> *
> * @param defaultEmbeddedCacheManager the default embedded cache manager.
> */
> private void stopCacheManager(@Disposes EmbeddedCacheManager defaultEmbeddedCacheManager) {
> defaultEmbeddedCacheManager.stop();
> }
> }
> {code}
> When tests are deployed to APP server then following ERROR occurs
> 10:19:58,494 ERROR [org.infinispan.jmx.JmxUtil] (http-localhost.localdomain/127.0.0.1:8080-1) ISPN000034: There's already an cache manager instance 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
> 10:19:58,526 ERROR [org.infinispan.jmx.JmxUtil] (http-localhost.localdomain/127.0.0.1:8080-1) ISPN000034: There's already an cache manager instance 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
> 10:19:58,598 ERROR [org.infinispan.jmx.JmxUtil] (http-localhost.localdomain/127.0.0.1:8080-1) ISPN000034: There's already an cache manager instance 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
> What means that out custom producer is sometimes not used and does not override default produced EmbeddedCacheManager
--
This message was sent by Atlassian JIRA
(v6.3.11#6341)
More information about the infinispan-issues
mailing list