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

View File

@ -87,9 +87,6 @@ public abstract class AbstractServiceRegistryImpl
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 abstract class AbstractServiceRegistryImpl
serviceBindingList.clear();
}
serviceBindingMap.clear();
if (parent!=null){
parent.destroy();
}
}
@Override

View File

@ -33,6 +33,7 @@ import org.hibernate.service.spi.BasicServiceInitiator;
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 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;
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 class ClassLoaderServiceImplTest {
/**
* 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 class ClassLoaderServiceImplTest {
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) {

View File

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

View File

@ -184,12 +184,13 @@ public class AuditConfiguration {
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;
}
}