HHH-14846 - Drop JMX integration

This commit is contained in:
Steve Ebersole 2021-09-27 12:22:43 -05:00
parent 8a8a92ca5e
commit c68322df99
10 changed files with 2 additions and 403 deletions

View File

@ -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;

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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) {
}
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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<ObjectName> 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<? extends Service> 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<MBeanServer> 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 );
}
}
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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<JmxService> {
public static final JmxServiceInitiator INSTANCE = new JmxServiceInitiator();
@Override
public Class<JmxService> 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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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<? extends Service> 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);
}

View File

@ -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 );

View File

@ -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() {

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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;
}
}

View File

@ -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<Manageable> getRealManageables();
@Override
default Object getManagementBean() {
// Generally the wrapper is not Manageable itself
return null;
}
}

View File

@ -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 );