private void printComponentStats(PrintWriter pw, Cache<?, ?> cache, Object component) { if (component == null) { return; } ComponentMetadataRepo mr = cache.getAdvancedCache().getComponentRegistry().getComponentMetadataRepo(); ComponentMetadata cm = mr.findComponentMetadata(component.getClass().getName()); if (cm == null || !(cm instanceof ManageableComponentMetadata)) { return; } ManageableComponentMetadata mcm = cm.toManageableComponentMetadata(); pw.printf("%s: {\n", mcm.getJmxObjectName()); List<JmxAttributeMetadata> attrs = new ArrayList<>(mcm.getAttributeMetadata()); Collections.sort(attrs, Comparator.comparing(JmxAttributeMetadata::getName)); for (JmxAttributeMetadata s : attrs) { pw.printf(" %s: %s\n", s.getName(), getAttributeValue(component, s)); } pw.println("}"); }
private AsyncInterceptorChain newInterceptorChain(AsyncInterceptor... interceptors) { ComponentMetadataRepo componentMetadataRepo = new ComponentMetadataRepo(); componentMetadataRepo.initialize(Collections.emptyList(), InterceptorChainTest.class.getClassLoader()); AsyncInterceptorChain chain = new AsyncInterceptorChainImpl(componentMetadataRepo); for (AsyncInterceptor i : interceptors) { chain.appendInterceptor(i, false); } return chain; } }
public void testRegisterLocalCache() throws Exception { EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(false); cacheContainers.add(cm); cm.start(); ConfigurationBuilder configuration = config(); configuration.clustering().cacheMode(CacheMode.LOCAL); cm.defineConfiguration("first", configuration.build()); Cache first = cm.getCache("first"); ComponentMetadataRepo metadataRepo = cm.getGlobalComponentRegistry().getComponentMetadataRepo(); ComponentMetadata metadata = metadataRepo.getComponentMetadata(first.getClass()); ResourceDMBean mbean = new ResourceDMBean(first, metadata.toManageableComponentMetadata()); Collection<ResourceDMBean> mbeans = singleton(mbean); ComponentsJmxRegistration regComponents = buildRegistrator(first); regComponents.registerMBeans(mbeans); String name = regComponents.getObjectName("Cache").toString(); ObjectName name1 = new ObjectName(name); assert mBeanServer.isRegistered(name1); regComponents.unregisterMBeans(mbeans); assert !mBeanServer.isRegistered(name1); assertCorrectJmxName(name1, first); }
gcr.getComponentMetadataRepo().injectFactoryForComponent( PersistenceManager.class, CustomCacheLoaderManagerFactory.class);
public void testRegisterReplicatedCache() throws Exception { GlobalConfigurationBuilder globalConfiguration = GlobalConfigurationBuilder.defaultClusteredBuilder(); globalConfiguration.globalJmxStatistics().enable(); EmbeddedCacheManager cm = TestCacheManagerFactory.createClusteredCacheManager(globalConfiguration, new ConfigurationBuilder()); cacheContainers.add(cm); cm.start(); ConfigurationBuilder configurationOverride = config(); configurationOverride.clustering().cacheMode(CacheMode.REPL_SYNC); cm.defineConfiguration("first", configurationOverride.build()); Cache first = cm.getCache("first"); ComponentMetadataRepo metadataRepo = cm.getGlobalComponentRegistry().getComponentMetadataRepo(); ComponentMetadata metadata = metadataRepo.getComponentMetadata(first.getClass()); ResourceDMBean mbean = new ResourceDMBean(first, metadata.toManageableComponentMetadata()); Collection<ResourceDMBean> mbeans = singleton(mbean); ComponentsJmxRegistration regComponents = buildRegistrator(first); regComponents.registerMBeans(mbeans); String name = regComponents.getObjectName("Cache").toString(); ObjectName name1 = new ObjectName(name); assertCorrectJmxName(name1, first); assert mBeanServer.isRegistered(name1); regComponents.unregisterMBeans(mbeans); assert !mBeanServer.isRegistered(name1); }
gcr.getComponentMetadataRepo().injectFactoryForComponent( PersistenceManager.class, CustomCacheLoaderManagerFactory.class);
private void printComponentStats(PrintWriter pw, Cache<?, ?> cache, Object component) { if (component == null) { return; } ComponentMetadataRepo mr = cache.getAdvancedCache().getComponentRegistry().getComponentMetadataRepo(); ComponentMetadata cm = mr.findComponentMetadata(component.getClass().getName()); if (cm == null || !(cm instanceof ManageableComponentMetadata)) { return; } ManageableComponentMetadata mcm = cm.toManageableComponentMetadata(); pw.printf("%s: {\n", mcm.getJmxObjectName()); for (JmxAttributeMetadata s : mcm.getAttributeMetadata()) { pw.printf(" %s: %s\n", s.getName(), getAttributeValue(component, s)); } pw.println("}"); }
@BeforeMethod(alwaysRun = true) public void setup() { metadataRepo = new ComponentMetadataRepo(); ClassLoader classLoader = this.getClass().getClassLoader(); metadataRepo.initialize(ModuleProperties.getModuleMetadataFiles(classLoader), classLoader); globalRegistry = new BasicComponentRegistryImpl(classLoader, metadataRepo, Scopes.GLOBAL, null); cacheRegistry = new BasicComponentRegistryImpl(classLoader, metadataRepo, Scopes.NAMED_CACHE, globalRegistry); }
ComponentMetadata metadata = metadataRepo.getComponentMetadata(replicatedCache.getClass()); ResourceDMBean replicatedMBean = new ResourceDMBean(replicatedCache, metadata.toManageableComponentMetadata()); ResourceDMBean localMBean = new ResourceDMBean(localCache, metadata.toManageableComponentMetadata());
gcr.getComponentMetadataRepo().injectFactoryForComponent( PersistenceManager.class, CustomCacheLoaderManagerFactory.class);
@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(); } }
public void testConcurrentAddRemove() throws Exception { ComponentMetadataRepo componentMetadataRepo = new ComponentMetadataRepo(); componentMetadataRepo.initialize(Collections.emptyList(), AsyncInterceptorChainTest.class.getClassLoader()); AsyncInterceptorChainImpl ic = new AsyncInterceptorChainImpl(componentMetadataRepo); ic.addInterceptor(new DummyCallInterceptor(), 0);
@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 testConcurrentAddRemove() throws Exception { ComponentMetadataRepo componentMetadataRepo = new ComponentMetadataRepo(); componentMetadataRepo.initialize(Collections.emptyList(), InterceptorChainTest.class.getClassLoader()); AsyncInterceptorChainImpl asyncInterceptorChain = new AsyncInterceptorChainImpl(componentMetadataRepo); GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder().build(); InterceptorChain ic = new InterceptorChain(); TestingUtil.inject(ic, asyncInterceptorChain); ic.setFirstInChain(new DummyCallInterceptor()); ic.addInterceptor(new DummyActivationInterceptor(), 1); CyclicBarrier barrier = new CyclicBarrier(4); List<Future<Void>> futures = new ArrayList<Future<Void>>(2); // We do test concurrent add/remove of different types per thread, // so that the final result is predictable (testable) and that we // can not possibly fail because of the InterceptorChain checking // that no interceptor is ever added twice. futures.add(fork(new InterceptorChainUpdater(ic, barrier, new DummyCacheMgmtInterceptor()))); futures.add(fork(new InterceptorChainUpdater(ic, barrier, new DummyDistCacheWriterInterceptor()))); futures.add(fork(new InterceptorChainUpdater(ic, barrier, new DummyInvalidationInterceptor()))); barrier.await(); // wait for all threads to be ready barrier.await(); // wait for all threads to finish log.debug("All threads finished, let's shutdown the executor and check whether any exceptions were reported"); for (Future<Void> future : futures) future.get(); assert ic.containsInterceptorType(DummyCallInterceptor.class); assert ic.containsInterceptorType(DummyActivationInterceptor.class); assert ic.containsInterceptorType(DummyCacheMgmtInterceptor.class); assert ic.containsInterceptorType(DummyDistCacheWriterInterceptor.class); assert ic.containsInterceptorType(DummyInvalidationInterceptor.class); assert ic.asList().size() == 5 : "Resulting interceptor chain was actually " + ic.asList(); }
.findComponentMetadata(MassIndexer.class) .toManageableComponentMetadata(); try {
.findComponentMetadata(MassIndexer.class) .toManageableComponentMetadata(); try {