From c68322df993807a69a75831106c3435351b02678 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Mon, 27 Sep 2021 12:22:43 -0500 Subject: [PATCH] HHH-14846 - Drop JMX integration --- .../jdbc/batch/internal/BatchBuilderImpl.java | 3 +- .../jmx/internal/DisabledJmxServiceImpl.java | 28 --- .../jmx/internal/JmxServiceImpl.java | 214 ------------------ .../jmx/internal/JmxServiceInitiator.java | 36 --- .../org/hibernate/jmx/spi/JmxService.java | 35 --- .../service/StandardServiceInitiators.java | 2 - .../internal/AbstractServiceRegistryImpl.java | 9 - .../org/hibernate/service/spi/Manageable.java | 45 ---- .../service/spi/OptionallyManageable.java | 30 --- .../stat/internal/StatisticsImpl.java | 3 +- 10 files changed, 2 insertions(+), 403 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/jmx/internal/DisabledJmxServiceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/jmx/internal/JmxServiceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/jmx/internal/JmxServiceInitiator.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/jmx/spi/JmxService.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/service/spi/Manageable.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/service/spi/OptionallyManageable.java diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/BatchBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/BatchBuilderImpl.java index 1dbd709628..7d99bdabbb 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/BatchBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/BatchBuilderImpl.java @@ -17,14 +17,13 @@ import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.service.spi.Configurable; -import org.hibernate.service.spi.Manageable; /** * A builder for {@link Batch} instances. * * @author Steve Ebersole */ -public class BatchBuilderImpl implements BatchBuilder, Configurable, Manageable, BatchBuilderMXBean { +public class BatchBuilderImpl implements BatchBuilder, Configurable, BatchBuilderMXBean { private static final CoreMessageLogger LOG = CoreLogging.messageLogger( BatchBuilderImpl.class ); private int jdbcBatchSize; diff --git a/hibernate-core/src/main/java/org/hibernate/jmx/internal/DisabledJmxServiceImpl.java b/hibernate-core/src/main/java/org/hibernate/jmx/internal/DisabledJmxServiceImpl.java deleted file mode 100644 index 9064efa3c3..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/jmx/internal/DisabledJmxServiceImpl.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.jmx.internal; -import javax.management.ObjectName; - -import org.hibernate.jmx.spi.JmxService; -import org.hibernate.service.spi.Manageable; - -/** - * A no-op version of the {@link JmxService} - * - * @author Steve Ebersole - */ -public class DisabledJmxServiceImpl implements JmxService { - public static final DisabledJmxServiceImpl INSTANCE = new DisabledJmxServiceImpl(); - - @Override - public void registerService(Manageable service, Class serviceRole) { - } - - @Override - public void registerMBean(ObjectName objectName, Object mBean) { - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/jmx/internal/JmxServiceImpl.java b/hibernate-core/src/main/java/org/hibernate/jmx/internal/JmxServiceImpl.java deleted file mode 100644 index 8e3f629b28..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/jmx/internal/JmxServiceImpl.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.jmx.internal; - -import java.lang.management.ManagementFactory; -import java.util.ArrayList; -import java.util.Map; -import javax.management.MBeanServer; -import javax.management.MBeanServerFactory; -import javax.management.MalformedObjectNameException; -import javax.management.ObjectName; - -import org.hibernate.HibernateException; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.cfg.Environment; -import org.hibernate.internal.CoreLogging; -import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.internal.util.config.ConfigurationHelper; -import org.hibernate.jmx.spi.JmxService; -import org.hibernate.service.Service; -import org.hibernate.service.spi.Manageable; -import org.hibernate.service.spi.OptionallyManageable; -import org.hibernate.service.spi.Stoppable; - -/** - * Standard implementation of JMX services - * - * @author Steve Ebersole - */ -public class JmxServiceImpl implements JmxService, Stoppable { - private static final CoreMessageLogger LOG = CoreLogging.messageLogger( JmxServiceImpl.class ); - - public static final String OBJ_NAME_TEMPLATE = "%s:sessionFactory=%s,serviceRole=%s,serviceType=%s"; - - private final boolean usePlatformServer; - private final String agentId; - private final String defaultDomain; - private final String sessionFactoryName; - - public JmxServiceImpl(Map configValues) { - usePlatformServer = ConfigurationHelper.getBoolean( AvailableSettings.JMX_PLATFORM_SERVER, configValues ); - agentId = (String) configValues.get( AvailableSettings.JMX_AGENT_ID ); - defaultDomain = (String) configValues.get( AvailableSettings.JMX_DOMAIN_NAME ); - - String defaultSessionFactoryName = ConfigurationHelper.getString( - Environment.SESSION_FACTORY_NAME, - configValues - ); - if ( defaultSessionFactoryName == null ) { - defaultSessionFactoryName = ConfigurationHelper.getString( - Environment.PERSISTENCE_UNIT_NAME, - configValues - ); - } - - sessionFactoryName = ConfigurationHelper.getString( - AvailableSettings.JMX_SF_NAME, - configValues, - defaultSessionFactoryName - ); - } - - private boolean startedServer; - private ArrayList registeredMBeans; - - @Override - public void stop() { - try { - // if we either started the JMX server or we registered some MBeans we at least need to look up - // MBean server and do *some* work on shutdown. - if ( startedServer || registeredMBeans != null ) { - MBeanServer mBeanServer = findServer(); - if ( mBeanServer == null ) { - LOG.unableToLocateMBeanServer(); - return; - } - - // release any MBeans we registered - if ( registeredMBeans != null ) { - for ( ObjectName objectName : registeredMBeans ) { - try { - LOG.tracev( "Unregistering registered MBean [ON={0}]", objectName ); - mBeanServer.unregisterMBean( objectName ); - } - catch ( Exception e ) { - LOG.debugf( "Unable to unregsiter registered MBean [ON=%s] : %s", objectName, e.toString() ); - } - } - } - - // stop the MBean server if we started it - if ( startedServer ) { - LOG.trace( "Attempting to release created MBeanServer" ); - try { - MBeanServerFactory.releaseMBeanServer( mBeanServer ); - } - catch ( Exception e ) { - LOG.unableToReleaseCreatedMBeanServer( e.toString() ); - } - } - } - } - finally { - startedServer = false; - if ( registeredMBeans != null ) { - registeredMBeans.clear(); - registeredMBeans = null; - } - } - } - - - // todo : should serviceRole come first in ObjectName template? depends on the groupings we want in the UI. - // as-is mbeans from each sessionFactory are grouped primarily. - - @Override - public void registerService(Manageable service, Class serviceRole) { - if ( OptionallyManageable.class.isInstance( service ) ) { - for ( Manageable realManageable : ( (OptionallyManageable) service ).getRealManageables() ) { - registerService( realManageable,serviceRole ); - } - return; - } - - final String domain = service.getManagementDomain() == null - ? AvailableSettings.JMX_DEFAULT_OBJ_NAME_DOMAIN - : service.getManagementDomain(); - final String serviceType = service.getManagementServiceType() == null - ? service.getClass().getName() - : service.getManagementServiceType(); - try { - final ObjectName objectName = new ObjectName( - String.format( - OBJ_NAME_TEMPLATE, - domain, - sessionFactoryName, - serviceRole.getName(), - serviceType - ) - ); - registerMBean( objectName, service.getManagementBean() ); - } - catch ( MalformedObjectNameException e ) { - throw new HibernateException( "Unable to generate service ObjectName", e ); - } - } - - @Override - public void registerMBean(ObjectName objectName, Object mBean) { - MBeanServer mBeanServer = findServer(); - if ( mBeanServer == null ) { - if ( startedServer ) { - throw new HibernateException( "Could not locate previously started MBeanServer" ); - } - mBeanServer = startMBeanServer(); - startedServer = true; - } - - try { - mBeanServer.registerMBean( mBean, objectName ); - if ( registeredMBeans == null ) { - registeredMBeans = new ArrayList<>(); - } - registeredMBeans.add( objectName ); - } - catch ( Exception e ) { - throw new HibernateException( "Unable to register MBean [ON=" + objectName + "]", e ); - } - } - - /** - * Locate the MBean server to use based on user input from startup. - * - * @return The MBean server to use. - */ - private MBeanServer findServer() { - if ( usePlatformServer ) { - // they specified to use the platform (vm) server - return ManagementFactory.getPlatformMBeanServer(); - } - - // otherwise lookup all servers by (optional) agentId. - // IMPL NOTE : the findMBeanServer call treats a null agentId to mean match all... - ArrayList mbeanServers = MBeanServerFactory.findMBeanServer( agentId ); - - if ( defaultDomain == null ) { - // they did not specify a domain by which to locate a particular MBeanServer to use, so chose the first - return mbeanServers.get( 0 ); - } - - for ( MBeanServer mbeanServer : mbeanServers ) { - // they did specify a domain, so attempt to locate an MBeanServer with a matching default domain, returning it - // if we find it. - if ( defaultDomain.equals( mbeanServer.getDefaultDomain() ) ) { - return mbeanServer; - } - } - - return null; - } - - private MBeanServer startMBeanServer() { - try { - return MBeanServerFactory.createMBeanServer( defaultDomain ); - } - catch ( Exception e ) { - throw new HibernateException( "Unable to start MBeanServer", e ); - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/jmx/internal/JmxServiceInitiator.java b/hibernate-core/src/main/java/org/hibernate/jmx/internal/JmxServiceInitiator.java deleted file mode 100644 index 6c16036854..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/jmx/internal/JmxServiceInitiator.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.jmx.internal; - -import java.util.Map; - -import org.hibernate.boot.registry.StandardServiceInitiator; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.internal.util.config.ConfigurationHelper; -import org.hibernate.jmx.spi.JmxService; -import org.hibernate.service.spi.ServiceRegistryImplementor; - -/** - * Standard initiator for the standard {@link JmxService} service - * - * @author Steve Ebersole - */ -public class JmxServiceInitiator implements StandardServiceInitiator { - public static final JmxServiceInitiator INSTANCE = new JmxServiceInitiator(); - - @Override - public Class getServiceInitiated() { - return JmxService.class; - } - - @Override - public JmxService initiateService(Map configurationValues, ServiceRegistryImplementor registry) { - return ConfigurationHelper.getBoolean( AvailableSettings.JMX_ENABLED, configurationValues, false ) - ? new JmxServiceImpl( configurationValues ) - : DisabledJmxServiceImpl.INSTANCE; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/jmx/spi/JmxService.java b/hibernate-core/src/main/java/org/hibernate/jmx/spi/JmxService.java deleted file mode 100644 index 5050696583..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/jmx/spi/JmxService.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.jmx.spi; - -import javax.management.ObjectName; - -import org.hibernate.service.Service; -import org.hibernate.service.spi.Manageable; - -/** - * Service providing simplified access to JMX related features needed by Hibernate. - * - * @author Steve Ebersole - */ -public interface JmxService extends Service { - /** - * Handles registration of a manageable service. - * - * @param service The manageable service - * @param serviceRole The service's role. - */ - void registerService(Manageable service, Class serviceRole); - - /** - * Registers the given {@code mBean} under the given {@code objectName} - * - * @param objectName The name under which to register the MBean - * @param mBean The MBean to register - */ - void registerMBean(ObjectName objectName, Object mBean); -} diff --git a/hibernate-core/src/main/java/org/hibernate/service/StandardServiceInitiators.java b/hibernate-core/src/main/java/org/hibernate/service/StandardServiceInitiators.java index 4c5367044c..3b6df6e008 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/StandardServiceInitiators.java +++ b/hibernate-core/src/main/java/org/hibernate/service/StandardServiceInitiators.java @@ -30,7 +30,6 @@ import org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiat import org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformResolverInitiator; import org.hibernate.event.internal.EntityCopyObserverFactoryInitiator; import org.hibernate.id.factory.internal.MutableIdentifierGeneratorFactoryInitiator; -import org.hibernate.jmx.internal.JmxServiceInitiator; import org.hibernate.persister.internal.PersisterClassResolverInitiator; import org.hibernate.persister.internal.PersisterFactoryInitiator; import org.hibernate.property.access.internal.PropertyAccessStrategyResolverInitiator; @@ -69,7 +68,6 @@ public final class StandardServiceInitiators { serviceInitiators.add( JdbcEnvironmentInitiator.INSTANCE ); serviceInitiators.add( JndiServiceInitiator.INSTANCE ); - serviceInitiators.add( JmxServiceInitiator.INSTANCE ); serviceInitiators.add( PersisterClassResolverInitiator.INSTANCE ); serviceInitiators.add( PersisterFactoryInitiator.INSTANCE ); diff --git a/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java b/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java index 2d8e825cef..bd70120c54 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java @@ -22,12 +22,10 @@ import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.internal.util.config.ConfigurationHelper; -import org.hibernate.jmx.spi.JmxService; import org.hibernate.service.Service; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.UnknownServiceException; import org.hibernate.service.spi.InjectService; -import org.hibernate.service.spi.Manageable; import org.hibernate.service.spi.ServiceBinding; import org.hibernate.service.spi.ServiceException; import org.hibernate.service.spi.ServiceInitiator; @@ -343,13 +341,6 @@ public abstract class AbstractServiceRegistryImpl if ( Startable.class.isInstance( serviceBinding.getService() ) ) { ( (Startable) serviceBinding.getService() ).start(); } - - if ( Manageable.class.isInstance( serviceBinding.getService() ) ) { - getService( JmxService.class ).registerService( - (Manageable) serviceBinding.getService(), - serviceBinding.getServiceRole() - ); - } } public boolean isActive() { diff --git a/hibernate-core/src/main/java/org/hibernate/service/spi/Manageable.java b/hibernate-core/src/main/java/org/hibernate/service/spi/Manageable.java deleted file mode 100644 index afc47301bc..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/service/spi/Manageable.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.service.spi; - -/** - * Optional {@link org.hibernate.service.Service} contract for services which can be managed in JMX - * - * @author Steve Ebersole - */ -public interface Manageable { - /** - * Get the domain name to be used in registering the management bean. May be {@code null} to indicate Hibernate's - * default domain ({@code org.hibernate.core}) should be used. - * - * @return The management domain. - */ - default String getManagementDomain() { - // use Hibernate default domain - return null; - } - - /** - * Allows the service to specify a special 'serviceType' portion of the object name. {@code null} indicates - * we should use the default scheme, which is to use the name of the service impl class for this purpose. - * - * @return The custom 'serviceType' name. - */ - default String getManagementServiceType() { - // use Hibernate default domain - return null; - } - - /** - * The management bean (MBean) for this service. - * - * @return The management bean. - */ - default Object getManagementBean() { - return this; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/service/spi/OptionallyManageable.java b/hibernate-core/src/main/java/org/hibernate/service/spi/OptionallyManageable.java deleted file mode 100644 index f3c486e97c..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/service/spi/OptionallyManageable.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.service.spi; - -import java.util.List; - -/** - * Extension to Manageable for things that are optionally Manageable depending - * on some internal state. E.g. services that wrap other services wanting to - * delegate manageability if the wrapped service is Manageable. - * - * @author Steve Ebersole - */ -public interface OptionallyManageable extends Manageable { - /** - * Any wrapped services that are Manageable. Never return `null`; an empty - * List should be returned instead. - */ - List getRealManageables(); - - @Override - default Object getManagementBean() { - // Generally the wrapper is not Manageable itself - return null; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/stat/internal/StatisticsImpl.java b/hibernate-core/src/main/java/org/hibernate/stat/internal/StatisticsImpl.java index 8a49d50cf5..64c46cab24 100644 --- a/hibernate-core/src/main/java/org/hibernate/stat/internal/StatisticsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/stat/internal/StatisticsImpl.java @@ -21,7 +21,6 @@ import org.hibernate.metamodel.model.domain.NavigableRole; import org.hibernate.metamodel.spi.MetamodelImplementor; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.service.Service; -import org.hibernate.service.spi.Manageable; import org.hibernate.stat.Statistics; import org.hibernate.stat.spi.StatisticsImplementor; @@ -34,7 +33,7 @@ import static org.hibernate.internal.CoreLogging.messageLogger; * @author Sanne Grinovero */ @SuppressWarnings({ "unchecked" }) -public class StatisticsImpl implements StatisticsImplementor, Service, Manageable { +public class StatisticsImpl implements StatisticsImplementor, Service { private static final CoreMessageLogger LOG = messageLogger( StatisticsImpl.class );