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:
Brett Meyer 2013-09-17 18:50:59 -04:00 committed by Brett Meyer
parent 2ce3aa1f09
commit 5da80756fe
6 changed files with 28 additions and 25 deletions

View File

@ -252,11 +252,11 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
@Override @Override
public void stop() { public void stop() {
for (ServiceLoader serviceLoader : serviceLoaders.values()) { for ( ServiceLoader serviceLoader : serviceLoaders.values() ) {
serviceLoader.reload(); // clear service loader providers serviceLoader.reload(); // clear service loader providers
} }
serviceLoaders.clear(); serviceLoaders.clear();
if (aggregatedClassLoader!=null){ if ( aggregatedClassLoader != null ) {
aggregatedClassLoader.destroy(); aggregatedClassLoader.destroy();
aggregatedClassLoader = null; aggregatedClassLoader = null;
} }

View File

@ -87,9 +87,6 @@ public abstract class AbstractServiceRegistryImpl
protected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) { protected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) {
final ServiceBinding serviceBinding = new ServiceBinding( this, initiator ); final ServiceBinding serviceBinding = new ServiceBinding( this, initiator );
serviceBindingMap.put( initiator.getServiceInitiated(), serviceBinding ); serviceBindingMap.put( initiator.getServiceInitiated(), serviceBinding );
synchronized ( serviceBindingList ) {
serviceBindingList.add( serviceBinding );
}
} }
protected <R extends Service> void createServiceBinding(ProvidedService<R> providedService) { protected <R extends Service> void createServiceBinding(ProvidedService<R> providedService) {
@ -278,10 +275,6 @@ public abstract class AbstractServiceRegistryImpl
serviceBindingList.clear(); serviceBindingList.clear();
} }
serviceBindingMap.clear(); serviceBindingMap.clear();
if (parent!=null){
parent.destroy();
}
} }
@Override @Override

View File

@ -33,6 +33,7 @@ import org.hibernate.service.spi.BasicServiceInitiator;
import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.Configurable;
import org.hibernate.service.spi.ServiceBinding; import org.hibernate.service.spi.ServiceBinding;
import org.hibernate.service.spi.ServiceInitiator; import org.hibernate.service.spi.ServiceInitiator;
import org.hibernate.service.spi.ServiceRegistryImplementor;
/** /**
* Hibernate implementation of the standard service registry. * Hibernate implementation of the standard service registry.
@ -76,4 +77,12 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
} }
} }
@Override
public void destroy() {
super.destroy();
if ( getParentServiceRegistry() != null ) {
( (ServiceRegistryImplementor) getParentServiceRegistry() ).destroy();
}
}
} }

View File

@ -1,7 +1,7 @@
package org.hibernate.test.service; package org.hibernate.test.service;
import static org.junit.Assert.assertNotNull; 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 static org.junit.Assert.assertSame;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -55,6 +55,8 @@ public class ClassLoaderServiceImplTest {
/** /**
* HHH-8363 discovered multiple leaks within CLS. Most notably, it wasn't getting GC'd due to holding * 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. * 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 @Test
@TestForIssue(jiraKey = "HHH-8363") @TestForIssue(jiraKey = "HHH-8363")
@ -74,11 +76,9 @@ public class ClassLoaderServiceImplTest {
ServiceRegistryBuilder.destroy( serviceRegistry ); ServiceRegistryBuilder.destroy( serviceRegistry );
// Should return null -- aggregratedClassLoader blown away.
testIntegrator2 = findTestIntegrator( classLoaderService ); testIntegrator2 = findTestIntegrator( classLoaderService );
assertNotNull( testIntegrator2 ); assertNull( testIntegrator2 );
// destroy should have cleared the ServiceLoader caches, forcing the services to be re-created when called upon
assertNotSame( testIntegrator1, testIntegrator2 );
} }
private TestIntegrator findTestIntegrator(ClassLoaderService classLoaderService) { private TestIntegrator findTestIntegrator(ClassLoaderService classLoaderService) {

View File

@ -34,18 +34,18 @@ public class TestIntegrator implements Integrator {
@Override @Override
public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) { SessionFactoryServiceRegistry serviceRegistry) {
System.out.println("foo");
} }
@Override @Override
public void integrate(MetadataImplementor metadata, SessionFactoryImplementor sessionFactory, public void integrate(MetadataImplementor metadata, SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) { SessionFactoryServiceRegistry serviceRegistry) {
System.out.println("foo");
} }
@Override @Override
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
System.out.println("foo");
} }
} }

View File

@ -185,9 +185,10 @@ public class AuditConfiguration {
} }
public void destroy() { public void destroy() {
for (Map.Entry<Configuration, AuditConfiguration> c: new HashSet<Map.Entry<Configuration, AuditConfiguration>>(cfgs.entrySet())){ for ( Map.Entry<Configuration, AuditConfiguration> c : new HashSet<Map.Entry<Configuration, AuditConfiguration>>(
if (c.getValue() == this){//this is nasty cleanup fix, whole static CFGS should be reworked cfgs.entrySet() ) ) {
cfgs.remove(c.getKey()); if ( c.getValue() == this ) { // this is nasty cleanup fix, whole static CFGS should be reworked
cfgs.remove( c.getKey() );
} }
} }
classLoaderService = null; classLoaderService = null;