HHH-8363 ClassLoaderServiceImpl should be defined as Stoppable
- also fix problem with JpaIntegrator holding references to beanmanager Conflicts: hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/spi/ClassLoaderService.java hibernate-entitymanager/src/main/java/org/hibernate/jpa/event/spi/JpaIntegrator.java
This commit is contained in:
parent
d8cb021e3d
commit
b09466f1db
|
@ -294,6 +294,7 @@ public final class SessionFactoryImpl
|
|||
for ( Integrator integrator : integrators ) {
|
||||
integrator.disintegrate( SessionFactoryImpl.this, SessionFactoryImpl.this.serviceRegistry );
|
||||
}
|
||||
integrators.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -715,6 +716,7 @@ public final class SessionFactoryImpl
|
|||
for ( Integrator integrator : integrators ) {
|
||||
integrator.disintegrate( SessionFactoryImpl.this, SessionFactoryImpl.this.serviceRegistry );
|
||||
}
|
||||
integrators.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ import java.util.Enumeration;
|
|||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
|
@ -52,6 +53,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
private static final Logger log = Logger.getLogger( ClassLoaderServiceImpl.class );
|
||||
|
||||
private final ClassLoader aggregatedClassLoader;
|
||||
private final LinkedList<ServiceLoader> loaders = new LinkedList<ServiceLoader>();
|
||||
|
||||
public ClassLoaderServiceImpl() {
|
||||
this( ClassLoaderServiceImpl.class.getClassLoader() );
|
||||
|
@ -231,14 +233,23 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
|
||||
@Override
|
||||
public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract) {
|
||||
final ServiceLoader<S> loader = ServiceLoader.load( serviceContract, aggregatedClassLoader );
|
||||
final LinkedHashSet<S> services = new LinkedHashSet<S>();
|
||||
for ( S service : loader ) {
|
||||
ServiceLoader<S> serviceLoader = ServiceLoader.load( serviceContract, aggregatedClassLoader );
|
||||
final LinkedHashSet<S> services = new LinkedHashSet<S>();
|
||||
for ( S service : serviceLoader) {
|
||||
services.add( service );
|
||||
}
|
||||
|
||||
loaders.add(serviceLoader);
|
||||
return services;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
while (!loaders.isEmpty()){
|
||||
ServiceLoader loader = loaders.removeLast();
|
||||
loader.reload();//clear service loader providers
|
||||
}
|
||||
}
|
||||
|
||||
private static class AggregatedClassLoader extends ClassLoader {
|
||||
private final ClassLoader[] individualClassLoaders;
|
||||
|
||||
|
|
|
@ -29,13 +29,14 @@ import java.util.LinkedHashSet;
|
|||
import java.util.List;
|
||||
|
||||
import org.hibernate.service.Service;
|
||||
import org.hibernate.service.spi.Stoppable;
|
||||
|
||||
/**
|
||||
* A service for interacting with class loaders
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ClassLoaderService extends Service {
|
||||
public interface ClassLoaderService extends Service, Stoppable {
|
||||
/**
|
||||
* Locate a class by name
|
||||
*
|
||||
|
|
|
@ -57,18 +57,7 @@ import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class JpaIntegrator implements Integrator {
|
||||
private static final DuplicationStrategy JPA_DUPLICATION_STRATEGY = new DuplicationStrategy() {
|
||||
@Override
|
||||
public boolean areMatch(Object listener, Object original) {
|
||||
return listener.getClass().equals( original.getClass() ) &&
|
||||
HibernateEntityManagerEventListener.class.isInstance( original );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action getAction() {
|
||||
return Action.KEEP_ORIGINAL;
|
||||
}
|
||||
};
|
||||
private static final DuplicationStrategy JPA_DUPLICATION_STRATEGY = new JPADuplicationStrategy();
|
||||
|
||||
private static final DuplicationStrategy JACC_DUPLICATION_STRATEGY = new DuplicationStrategy() {
|
||||
@Override
|
||||
|
@ -260,4 +249,17 @@ public class JpaIntegrator implements Integrator {
|
|||
throw new HibernateException( "Could not instantiate requested listener [" + listenerImpl + "]", e );
|
||||
}
|
||||
}
|
||||
|
||||
private static class JPADuplicationStrategy implements DuplicationStrategy {
|
||||
@Override
|
||||
public boolean areMatch(Object listener, Object original) {
|
||||
return listener.getClass().equals( original.getClass() ) &&
|
||||
HibernateEntityManagerEventListener.class.isInstance( original );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action getAction() {
|
||||
return Action.KEEP_ORIGINAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue