HHH-6796 Make the service configuration logic being executed by the owning service registry
This commit is contained in:
parent
944ae2c488
commit
c04442281b
|
@ -43,6 +43,7 @@ import org.hibernate.service.spi.Manageable;
|
||||||
import org.hibernate.service.spi.ServiceBinding;
|
import org.hibernate.service.spi.ServiceBinding;
|
||||||
import org.hibernate.service.spi.ServiceException;
|
import org.hibernate.service.spi.ServiceException;
|
||||||
import org.hibernate.service.spi.ServiceInitiator;
|
import org.hibernate.service.spi.ServiceInitiator;
|
||||||
|
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
import org.hibernate.service.spi.Startable;
|
import org.hibernate.service.spi.Startable;
|
||||||
import org.hibernate.service.spi.Stoppable;
|
import org.hibernate.service.spi.Stoppable;
|
||||||
|
@ -156,15 +157,26 @@ public abstract class AbstractServiceRegistryImpl implements ServiceRegistryImpl
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PHASE 2 : configure service (***potentially recursive***)
|
// PHASE 2 : inject service (***potentially recursive***)
|
||||||
configureService( service );
|
injectService( service );
|
||||||
|
|
||||||
// PHASE 3 : Start service
|
// PHASE 3 : configure service
|
||||||
|
serviceBinding.getServiceRegistry().configureService( service );
|
||||||
|
|
||||||
|
// PHASE 4 : Start service
|
||||||
startService( serviceBinding );
|
startService( serviceBinding );
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected <T extends Service> void injectService(T service) {
|
||||||
|
applyInjections( service );
|
||||||
|
|
||||||
|
if ( ServiceRegistryAwareService.class.isInstance( service ) ) {
|
||||||
|
( (ServiceRegistryAwareService) service ).injectServices( this );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
protected <R extends Service> R createService(ServiceBinding<R> serviceBinding) {
|
protected <R extends Service> R createService(ServiceBinding<R> serviceBinding) {
|
||||||
final ServiceInitiator<R> serviceInitiator = serviceBinding.getServiceInitiator();
|
final ServiceInitiator<R> serviceInitiator = serviceBinding.getServiceInitiator();
|
||||||
|
@ -188,8 +200,6 @@ public abstract class AbstractServiceRegistryImpl implements ServiceRegistryImpl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract <T extends Service> void configureService(T service);
|
|
||||||
|
|
||||||
protected <T extends Service> void applyInjections(T service) {
|
protected <T extends Service> void applyInjections(T service) {
|
||||||
try {
|
try {
|
||||||
for ( Method method : service.getClass().getMethods() ) {
|
for ( Method method : service.getClass().getMethods() ) {
|
||||||
|
|
|
@ -116,4 +116,9 @@ public class BootstrapServiceRegistryImpl
|
||||||
throw new ServiceException( "Boot-strap registry should only contain directly built services" );
|
throw new ServiceException( "Boot-strap registry should only contain directly built services" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <R extends Service> void configureService(R service) {
|
||||||
|
//nothing do to for bootstrap style services
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,11 +96,7 @@ public class SessionFactoryServiceRegistryImpl extends AbstractServiceRegistryIm
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T extends Service> void configureService(T service) {
|
public <T extends Service> void configureService(T service) {
|
||||||
applyInjections( service );
|
//TODO nothing to do here or should we inject SessionFactory properties?
|
||||||
|
|
||||||
if ( ServiceRegistryAwareService.class.isInstance( service ) ) {
|
|
||||||
( (ServiceRegistryAwareService) service ).injectServices( this );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,13 +70,7 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T extends Service> void configureService(T service) {
|
public <T extends Service> void configureService(T service) {
|
||||||
applyInjections( service );
|
|
||||||
|
|
||||||
if ( ServiceRegistryAwareService.class.isInstance( service ) ) {
|
|
||||||
( (ServiceRegistryAwareService) service ).injectServices( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( Configurable.class.isInstance( service ) ) {
|
if ( Configurable.class.isInstance( service ) ) {
|
||||||
( (Configurable) service ).configure( configurationValues );
|
( (Configurable) service ).configure( configurationValues );
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ public final class ServiceBinding<R extends Service> {
|
||||||
|
|
||||||
public static interface OwningRegistry {
|
public static interface OwningRegistry {
|
||||||
public <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiator);
|
public <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiator);
|
||||||
|
public <R extends Service> void configureService(R service);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final OwningRegistry serviceRegistry;
|
private final OwningRegistry serviceRegistry;
|
||||||
|
|
Loading…
Reference in New Issue