mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-10 05:04:52 +00:00
HHH-8363 SessionFactoryServiceRegistryImpl should not call
parent#destroy, test failures, formatting Conflicts: hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java hibernate-core/src/main/java/org/hibernate/boot/registry/internal/StandardServiceRegistryImpl.java hibernate-core/src/test/java/org/hibernate/test/service/ClassLoaderServiceImplTest.java hibernate-envers/src/main/java/org/hibernate/envers/configuration/spi/AuditConfiguration.java
This commit is contained in:
parent
2ce3aa1f09
commit
5da80756fe
@ -252,11 +252,11 @@ public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract) {
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
for (ServiceLoader serviceLoader : serviceLoaders.values()) {
|
||||
for ( ServiceLoader serviceLoader : serviceLoaders.values() ) {
|
||||
serviceLoader.reload(); // clear service loader providers
|
||||
}
|
||||
serviceLoaders.clear();
|
||||
if (aggregatedClassLoader!=null){
|
||||
if ( aggregatedClassLoader != null ) {
|
||||
aggregatedClassLoader.destroy();
|
||||
aggregatedClassLoader = null;
|
||||
}
|
||||
|
@ -87,9 +87,6 @@ public AbstractServiceRegistryImpl(BootstrapServiceRegistry bootstrapServiceRegi
|
||||
protected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) {
|
||||
final ServiceBinding serviceBinding = new ServiceBinding( this, initiator );
|
||||
serviceBindingMap.put( initiator.getServiceInitiated(), serviceBinding );
|
||||
synchronized ( serviceBindingList ) {
|
||||
serviceBindingList.add( serviceBinding );
|
||||
}
|
||||
}
|
||||
|
||||
protected <R extends Service> void createServiceBinding(ProvidedService<R> providedService) {
|
||||
@ -278,10 +275,6 @@ public void destroy() {
|
||||
serviceBindingList.clear();
|
||||
}
|
||||
serviceBindingMap.clear();
|
||||
|
||||
if (parent!=null){
|
||||
parent.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,6 +33,7 @@
|
||||
import org.hibernate.service.spi.Configurable;
|
||||
import org.hibernate.service.spi.ServiceBinding;
|
||||
import org.hibernate.service.spi.ServiceInitiator;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
/**
|
||||
* Hibernate implementation of the standard service registry.
|
||||
@ -76,4 +77,12 @@ public <R extends Service> void configureService(ServiceBinding<R> serviceBindin
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
if ( getParentServiceRegistry() != null ) {
|
||||
( (ServiceRegistryImplementor) getParentServiceRegistry() ).destroy();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.hibernate.test.service;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -55,6 +55,8 @@ public void testSystemClassLoaderNotOverriding() throws IOException, ClassNotFou
|
||||
/**
|
||||
* HHH-8363 discovered multiple leaks within CLS. Most notably, it wasn't getting GC'd due to holding
|
||||
* references to ServiceLoaders. Ensure that the addition of Stoppable functionality cleans up properly.
|
||||
*
|
||||
* TODO: Is there a way to test that the ServiceLoader was actually reset?
|
||||
*/
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-8363")
|
||||
@ -74,11 +76,9 @@ public void testStoppableClassLoaderService() {
|
||||
|
||||
ServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
|
||||
// Should return null -- aggregratedClassLoader blown away.
|
||||
testIntegrator2 = findTestIntegrator( classLoaderService );
|
||||
assertNotNull( testIntegrator2 );
|
||||
|
||||
// destroy should have cleared the ServiceLoader caches, forcing the services to be re-created when called upon
|
||||
assertNotSame( testIntegrator1, testIntegrator2 );
|
||||
assertNull( testIntegrator2 );
|
||||
}
|
||||
|
||||
private TestIntegrator findTestIntegrator(ClassLoaderService classLoaderService) {
|
||||
|
@ -34,18 +34,18 @@ public class TestIntegrator implements Integrator {
|
||||
@Override
|
||||
public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
System.out.println("foo");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void integrate(MetadataImplementor metadata, SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
System.out.println("foo");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
System.out.println("foo");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -184,12 +184,13 @@ public synchronized static AuditConfiguration getFor(Configuration cfg, ClassLoa
|
||||
return verCfg;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
for (Map.Entry<Configuration, AuditConfiguration> c: new HashSet<Map.Entry<Configuration, AuditConfiguration>>(cfgs.entrySet())){
|
||||
if (c.getValue() == this){//this is nasty cleanup fix, whole static CFGS should be reworked
|
||||
cfgs.remove(c.getKey());
|
||||
}
|
||||
}
|
||||
classLoaderService = null;
|
||||
}
|
||||
public void destroy() {
|
||||
for ( Map.Entry<Configuration, AuditConfiguration> c : new HashSet<Map.Entry<Configuration, AuditConfiguration>>(
|
||||
cfgs.entrySet() ) ) {
|
||||
if ( c.getValue() == this ) { // this is nasty cleanup fix, whole static CFGS should be reworked
|
||||
cfgs.remove( c.getKey() );
|
||||
}
|
||||
}
|
||||
classLoaderService = null;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user