/** * Returns the name of this cache container. * @return the cache container name */ default String getName() { return this.getCacheManagerConfiguration().globalJmxStatistics().cacheManagerName(); }
@Override public void cacheManagerStarted(GlobalComponentRegistry gcr) { // This works because the interpreter is not yet used internally, otherwise it would have to be in cacheManagerStarting GlobalJmxStatisticsConfiguration globalCfg = gcr.getGlobalConfiguration().globalJmxStatistics(); MBeanServer mbeanServer = JmxUtil.lookupMBeanServer(globalCfg.mbeanServerLookup(), globalCfg.properties()); String groupName = getGroupName(globalCfg.cacheManagerName()); Interpreter interpreter = new Interpreter(); gcr.registerComponent(interpreter, Interpreter.class); // Pick up metadata from the component metadata repository ManageableComponentMetadata meta = gcr.getComponentMetadataRepo().findComponentMetadata(Interpreter.class) .toManageableComponentMetadata(); // And use this metadata when registering the transport as a dynamic MBean try { ResourceDMBean mbean = new ResourceDMBean(interpreter, meta); interpreterObjName = new ObjectName(String.format("%s:%s,component=Interpreter", globalCfg.domain(), groupName)); JmxUtil.registerMBean(mbean, interpreterObjName, mbeanServer); } catch (Exception e) { interpreterObjName = null; log.jmxRegistrationFailed(); } }
public void testHealthCheckAPI() throws Exception { //given //we need this to start a cache with a custom name cacheManagers.get(0).getCache("test").put("1", "1"); final MBeanServer mBeanServer = PerThreadMBeanServerLookup.getThreadMBeanServer(); //when String domain0 = manager(0).getCacheManagerConfiguration().globalJmxStatistics().domain(); ObjectName healthAPI0 = TestingUtil.getCacheManagerObjectName(domain0, "DefaultCacheManager", HealthJMXExposer.OBJECT_NAME); Object numberOfCpus = mBeanServer.getAttribute(healthAPI0, "NumberOfCpus"); Object totalMemoryKb = mBeanServer.getAttribute(healthAPI0, "TotalMemoryKb"); Object freeMemoryKb = mBeanServer.getAttribute(healthAPI0, "FreeMemoryKb"); Object clusterHealth = mBeanServer.getAttribute(healthAPI0, "ClusterHealth"); Object clusterName = mBeanServer.getAttribute(healthAPI0, "ClusterName"); Object numberOfNodes = mBeanServer.getAttribute(healthAPI0, "NumberOfNodes"); Object cacheHealth = mBeanServer.getAttribute(healthAPI0, "CacheHealth"); //then assertTrue((int) numberOfCpus > 0); assertTrue((long) totalMemoryKb > 0); assertTrue((long) freeMemoryKb > 0); assertEquals((String) clusterHealth, HealthStatus.HEALTHY.toString()); assertEquals((String) clusterName, "ISPN"); assertEquals((int) numberOfNodes, 1); assertEquals(((String[]) cacheHealth)[0], "test"); assertEquals(((String[]) cacheHealth)[1], HealthStatus.HEALTHY.toString()); } }
assertTrue(gc.globalJmxStatistics().enabled()); assertTrue(gc.globalJmxStatistics().allowDuplicateDomains()); assertEquals("funky_domain", gc.globalJmxStatistics().domain()); assertTrue(gc.globalJmxStatistics().mbeanServerLookup() instanceof PerThreadMBeanServerLookup);
@Test public final void testAddConfigurations() throws Exception { final InfinispanEmbeddedCacheManagerFactoryBean objectUnderTest = new InfinispanEmbeddedCacheManagerFactoryBean(); GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); // Now prepare a cache configuration. ConfigurationBuilder builder = new ConfigurationBuilder(); builder.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL); // Now add them to the object that we are testing. objectUnderTest.addCustomGlobalConfiguration(gcb); objectUnderTest.addCustomCacheConfiguration(builder); objectUnderTest.afterPropertiesSet(); // Get the cache manager and make assertions. final EmbeddedCacheManager infinispanEmbeddedCacheManager = objectUnderTest.getObject(); assertEquals(infinispanEmbeddedCacheManager.getCacheManagerConfiguration().globalJmxStatistics() .allowDuplicateDomains(), gcb.build().globalJmxStatistics().allowDuplicateDomains()); assertEquals(infinispanEmbeddedCacheManager.getDefaultCacheConfiguration().transaction() .transactionMode().isTransactional(), builder.build().transaction().transactionMode().isTransactional()); } }
@Override public void cacheManagerStopping(GlobalComponentRegistry gcr) { if (interpreterObjName != null) { GlobalJmxStatisticsConfiguration jmxConfig = gcr.getGlobalConfiguration().globalJmxStatistics(); MBeanServer mbeanServer = JmxUtil.lookupMBeanServer(jmxConfig.mbeanServerLookup(), jmxConfig.properties()); try { JmxUtil.unregisterMBean(interpreterObjName, mbeanServer); } catch (Exception e) { log.jmxUnregistrationFailed(); } } } }
@Override protected ConfigurationBuilder getConfigurationBuilder() { ConfigurationBuilder builder = new ConfigurationBuilder(); Configuration templateConfiguration = this.dependencies.getTemplateConfiguration(); if (templateConfiguration != null) { builder.read(templateConfiguration); } Configuration configuration = this.builder.build(); builder.read(configuration); builder.template(configuration.isTemplate()); builder.jmxStatistics().enabled(this.dependencies.getCacheContainer().getCacheManagerConfiguration().globalJmxStatistics().enabled()); TransactionManager tm = this.dependencies.getTransactionManager(); if (tm != null) { builder.transaction().transactionManagerLookup(new TransactionManagerProvider(tm)); } TransactionSynchronizationRegistry tsr = this.dependencies.getTransactionSynchronizationRegistry(); if (tsr != null) { builder.transaction().transactionSynchronizationRegistryLookup(new TransactionSynchronizationRegistryProvider(tsr)); } return builder; } }
mbeanServer = JmxUtil.lookupMBeanServer(jmxConfig.mbeanServerLookup(), jmxConfig.properties()); String queryGroupName = getQueryGroupName(jmxConfig.cacheManagerName(), cache.getName()); String jmxDomain = JmxUtil.buildJmxDomain(jmxConfig.domain(), mbeanServer, queryGroupName);
@Override public void cacheManagerStarted(GlobalComponentRegistry gcr) { GlobalConfiguration globalCfg = gcr.getGlobalConfiguration(); MBeanServer mbeanServer = JmxUtil.lookupMBeanServer(globalCfg); String groupName = getGroupName(globalCfg); String jmxDomain = globalCfg.globalJmxStatistics().domain(); Interpreter interpreter = new Interpreter(); gcr.registerComponent(interpreter, Interpreter.class); // Pick up metadata from the component metadata repository ManageableComponentMetadata meta = gcr.getComponentMetadataRepo().findComponentMetadata(Interpreter.class) .toManageableComponentMetadata(); // And use this metadata when registering the transport as a dynamic MBean try { ResourceDMBean mbean = new ResourceDMBean(interpreter, meta); interpreterObjName = new ObjectName(String.format("%s:%s,component=Interpreter", jmxDomain, groupName)); JmxUtil.registerMBean(mbean, interpreterObjName, mbeanServer); } catch (Exception e) { interpreterObjName = null; log.jmxRegistrationFailed(); } }
@Test public final void testAddConfigurations() throws Exception { final InfinispanEmbeddedCacheManagerFactoryBean objectUnderTest = new InfinispanEmbeddedCacheManagerFactoryBean(); GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); // Now prepare a cache configuration. ConfigurationBuilder builder = new ConfigurationBuilder(); builder.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL); // Now add them to the object that we are testing. objectUnderTest.addCustomGlobalConfiguration(gcb); objectUnderTest.addCustomCacheConfiguration(builder); objectUnderTest.afterPropertiesSet(); // Get the cache manager and make assertions. final EmbeddedCacheManager infinispanEmbeddedCacheManager = objectUnderTest.getObject(); assertEquals(infinispanEmbeddedCacheManager.getCacheManagerConfiguration().globalJmxStatistics() .allowDuplicateDomains(), gcb.build().globalJmxStatistics().allowDuplicateDomains()); assertEquals(infinispanEmbeddedCacheManager.getDefaultCacheConfiguration().transaction() .transactionMode().isTransactional(), builder.build().transaction().transactionMode().isTransactional()); } }
try { EmbeddedCacheManager manager = factory.getCacheManager(); assertTrue(manager.getCacheManagerConfiguration().globalJmxStatistics().enabled()); InfinispanBaseRegion region = factory.buildEntityRegion("com.acme.Address", AccessType.TRANSACTIONAL); AdvancedCache cache = region.getCache();
@Override public int hashCode() { return this.cache.getCacheManager().getCacheManagerConfiguration().globalJmxStatistics().cacheManagerName().hashCode() ^ this.cache.getName().hashCode(); }
public void check(ConfigurationBuilderHolder holder) { GlobalConfiguration g = getGlobalConfiguration(holder); assertEquals("maximal", g.globalJmxStatistics().cacheManagerName()); assertTrue(g.globalJmxStatistics().enabled()); assertEquals("my-domain", g.globalJmxStatistics().domain()); assertTrue(g.globalJmxStatistics().mbeanServerLookup() instanceof CustomMBeanServerPropertiesTest.TestLookup); assertEquals(1, g.globalJmxStatistics().properties().size()); assertEquals("value", g.globalJmxStatistics().properties().getProperty("key"));
private ObjectName counterObjectName(int managerIndex) { final String domain = manager(managerIndex).getCacheManagerConfiguration().globalJmxStatistics().domain(); return TestingUtil.getCacheManagerObjectName(domain, "DefaultCacheManager", EmbeddedCounterManager.OBJECT_NAME); } }
@Test public final void testAddConfigurations() throws Exception { final InfinispanEmbeddedCacheManagerFactoryBean objectUnderTest = new InfinispanEmbeddedCacheManagerFactoryBean(); // Allow duplicate domains. A good little configuration modification to make. If this isn't enabled, // JMXDomainConflicts occur which break the testsuite. This way we can also have a non-default configuration to // check. GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); gcb.globalJmxStatistics().allowDuplicateDomains(true); // Now prepare a cache configuration. ConfigurationBuilder builder = new ConfigurationBuilder(); builder.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL); // Now add them to the object that we are testing. objectUnderTest.addCustomGlobalConfiguration(gcb); objectUnderTest.addCustomCacheConfiguration(builder); objectUnderTest.afterPropertiesSet(); // Get the cache manager and make assertions. final EmbeddedCacheManager infinispanEmbeddedCacheManager = objectUnderTest.getObject(); assertEquals(infinispanEmbeddedCacheManager.getCacheManagerConfiguration().globalJmxStatistics() .allowDuplicateDomains(), gcb.build().globalJmxStatistics().allowDuplicateDomains()); assertEquals(infinispanEmbeddedCacheManager.getDefaultCacheConfiguration().transaction() .transactionMode().isTransactional(), builder.build().transaction().transactionMode().isTransactional()); } }
try { EmbeddedCacheManager manager = factory.getCacheManager(); assertFalse(manager.getCacheManagerConfiguration().globalJmxStatistics().enabled()); assertNotNull(factory.getBaseConfiguration(person)); assertFalse(isDefinedCache(factory, person));
@Override public boolean equals(Object object) { if ((object == null) || !(object instanceof InfinispanXAResourceRecovery)) return false; InfinispanXAResourceRecovery recovery = (InfinispanXAResourceRecovery) object; return this.cache.getCacheManager().getCacheManagerConfiguration().globalJmxStatistics().cacheManagerName().equals(recovery.cache.getCacheManager().getCacheManagerConfiguration().globalJmxStatistics().cacheManagerName()) && this.cache.getName().equals(recovery.cache.getName()); }
public void testConfigurationProperties() throws Exception { GlobalConfigurationBuilder globalConfiguration = GlobalConfigurationBuilder.defaultClusteredBuilder(); globalConfiguration.transport().siteId("TESTVALUE1"); globalConfiguration.transport().rackId("TESTVALUE2"); globalConfiguration.transport().machineId("TESTVALUE3"); globalConfiguration.globalJmxStatistics().enable().mBeanServerLookup(new PerThreadMBeanServerLookup()); cm = TestCacheManagerFactory.createClusteredCacheManager(globalConfiguration, new ConfigurationBuilder()); String jmxDomain = cm.getCacheManagerConfiguration().globalJmxStatistics().domain(); ConfigurationBuilder localCache = config(); localCache.memory().storageType(StorageType.BINARY); cm.defineConfiguration("local_cache1", localCache.build()); localCache.memory().storageType(StorageType.OBJECT); cm.defineConfiguration("local_cache2", localCache.build()); cm.getCache("local_cache1"); cm.getCache("local_cache2"); MBeanServer mBeanServer = PerThreadMBeanServerLookup.getThreadMBeanServer(); Properties props1 = (Properties) mBeanServer.getAttribute(getCacheObjectName(jmxDomain, "local_cache1(local)", "Cache"), "configurationAsProperties"); Properties props2 = (Properties) mBeanServer.getAttribute(getCacheObjectName(jmxDomain, "local_cache2(local)", "Cache"), "configurationAsProperties"); Properties propsGlobal = (Properties) mBeanServer.getAttribute(getCacheManagerObjectName(jmxDomain), "globalConfigurationAsProperties"); assert "BINARY".equals(props1.getProperty("memory.storageType")); assert "OBJECT".equals(props2.getProperty("memory.storageType")); log.tracef("propsGlobal=%s", propsGlobal); assert "TESTVALUE1".equals(propsGlobal.getProperty("transport.siteId")); assert "TESTVALUE2".equals(propsGlobal.getProperty("transport.rackId")); assert "TESTVALUE3".equals(propsGlobal.getProperty("transport.machineId")); }
@Test public void testIfSpringEmbeddedCacheManagerFactoryBeanAllowesOverridingConfigurationWithEmptyInputStream() throws Exception { objectUnderTest = SpringEmbeddedCacheManagerFactoryBeanBuilder .defaultBuilder().build(); GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); // Now prepare a cache configuration. ConfigurationBuilder builder = new ConfigurationBuilder(); builder.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL); // Now add them to the object that we are testing. objectUnderTest.addCustomGlobalConfiguration(gcb); objectUnderTest.addCustomCacheConfiguration(builder); objectUnderTest.afterPropertiesSet(); // Get the cache manager and make assertions. final EmbeddedCacheManager infinispanEmbeddedCacheManager = objectUnderTest.getObject().getNativeCacheManager(); assertEquals(infinispanEmbeddedCacheManager.getCacheManagerConfiguration().globalJmxStatistics() .allowDuplicateDomains(), true); assertEquals(infinispanEmbeddedCacheManager.getDefaultCacheConfiguration().transaction().transactionMode().isTransactional(), false); } }
@Override protected void initChannel() { try { this.channel = this.factory.createChannel(this.configuration.globalJmxStatistics().cacheManagerName()); this.channel.setDiscardOwnMessages(false); } catch (Exception e) { throw new CacheException(e); } } }