private void registerQueryMBeans ( ComponentRegistry cr , Configuration cfg , SearchIntegrator searchIntegrator ) { AdvancedCache < ? , ? > cache = cr . getComponent ( Cache . class ) . getAdvancedCache ( ) ; // Resolve MBean server instance GlobalJmxStatisticsConfiguration jmxConfig = cr . getGlobalComponentRegistry ( ) . getGlobalConfiguration ( ) . globalJmxStatistics ( ) ; if ( ! jmxConfig . enabled ( ) ) return ; if ( mbeanServer == null ) { mbeanServer = JmxUtil . lookupMBeanServer ( jmxConfig . mbeanServerLookup ( ) , jmxConfig . properties ( ) ) ; } // Resolve jmx domain to use for query MBeans String queryGroupName = getQueryGroupName ( jmxConfig . cacheManagerName ( ) , cache . getName ( ) ) ; String jmxDomain = JmxUtil . buildJmxDomain ( jmxConfig . domain ( ) , mbeanServer , queryGroupName ) ; // Register query statistics MBean, but only enable it if Infinispan config says so try { ObjectName statsObjName = new ObjectName ( jmxDomain + ":" + queryGroupName + ",component=Statistics" ) ; InfinispanQueryStatisticsInfo stats = new InfinispanQueryStatisticsInfo ( searchIntegrator , statsObjName ) ; stats . setStatisticsEnabled ( cfg . jmxStatistics ( ) . enabled ( ) ) ; JmxUtil . registerMBean ( stats , statsObjName , mbeanServer ) ; cr . registerComponent ( stats , InfinispanQueryStatisticsInfo . class ) ; } catch ( Exception e ) { throw new CacheException ( "Unable to register query statistics MBean" , e ) ; } // Register mass indexer MBean, picking metadata from repo ManageableComponentMetadata massIndexerCompMetadata = cr . getGlobalComponentRegistry ( ) . getComponentMetadataRepo ( ) . findComponentMetadata ( MassIndexer . class ) . toManageableComponentMetadata ( ) ; try { KeyTransformationHandler keyTransformationHandler = ComponentRegistryUtils . getKeyTransformationHandler ( cache ) ; TimeService timeService = ComponentRegistryUtils . getTimeService ( cache ) ; // TODO: MassIndexer should be some kind of query cache component? DistributedExecutorMassIndexer massIndexer = new DistributedExecutorMassIndexer ( cache , searchIntegrator , keyTransformationHandler , timeService ) ; ResourceDMBean mbean = new ResourceDMBean ( massIndexer , massIndexerCompMetadata ) ; ObjectName massIndexerObjName = new ObjectName ( jmxDomain + ":" + queryGroupName + ",component=" + massIndexerCompMetadata . getJmxObjectName ( ) ) ; JmxUtil . registerMBean ( mbean , massIndexerObjName , mbeanServer ) ; } catch ( Exception e ) { throw new CacheException ( "Unable to create MassIndexer MBean" , e ) ; } }
Register query statistics and mass - indexer MBeans for a cache .