Skip to content

Commit

Permalink
HHH-6796 Make the service configuration logic being executed by the o…
Browse files Browse the repository at this point in the history
…wning service registry
  • Loading branch information
emmanuelbernard committed Nov 2, 2011
1 parent 944ae2c commit c044422
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
Expand Up @@ -43,6 +43,7 @@
import org.hibernate.service.spi.ServiceBinding;
import org.hibernate.service.spi.ServiceException;
import org.hibernate.service.spi.ServiceInitiator;
import org.hibernate.service.spi.ServiceRegistryAwareService;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.Startable;
import org.hibernate.service.spi.Stoppable;
Expand Down Expand Up @@ -156,15 +157,26 @@ private <R extends Service> R initializeService(ServiceBinding<R> serviceBinding
return null;
}

// PHASE 2 : configure service (***potentially recursive***)
configureService( service );
// PHASE 2 : inject service (***potentially recursive***)
injectService( service );

// PHASE 3 : Start service
// PHASE 3 : configure service
serviceBinding.getServiceRegistry().configureService( service );

// PHASE 4 : Start service
startService( serviceBinding );

return service;
}

protected <T extends Service> void injectService(T service) {
applyInjections( service );

if ( ServiceRegistryAwareService.class.isInstance( service ) ) {
( (ServiceRegistryAwareService) service ).injectServices( this );
}
}

@SuppressWarnings( {"unchecked"})
protected <R extends Service> R createService(ServiceBinding<R> serviceBinding) {
final ServiceInitiator<R> serviceInitiator = serviceBinding.getServiceInitiator();
Expand All @@ -188,8 +200,6 @@ protected <R extends Service> R createService(ServiceBinding<R> serviceBinding)
}
}

protected abstract <T extends Service> void configureService(T service);

protected <T extends Service> void applyInjections(T service) {
try {
for ( Method method : service.getClass().getMethods() ) {
Expand Down
Expand Up @@ -116,4 +116,9 @@ public <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiato
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
}

}
Expand Up @@ -96,11 +96,7 @@ else if ( configuration != null ) {
}

@Override
protected <T extends Service> void configureService(T service) {
applyInjections( service );

if ( ServiceRegistryAwareService.class.isInstance( service ) ) {
( (ServiceRegistryAwareService) service ).injectServices( this );
}
public <T extends Service> void configureService(T service) {
//TODO nothing to do here or should we inject SessionFactory properties?
}
}
Expand Up @@ -70,13 +70,7 @@ public <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiato
}

@Override
protected <T extends Service> void configureService(T service) {
applyInjections( service );

if ( ServiceRegistryAwareService.class.isInstance( service ) ) {
( (ServiceRegistryAwareService) service ).injectServices( this );
}

public <T extends Service> void configureService(T service) {
if ( Configurable.class.isInstance( service ) ) {
( (Configurable) service ).configure( configurationValues );
}
Expand Down
Expand Up @@ -37,6 +37,7 @@ public final class ServiceBinding<R extends Service> {

public static interface OwningRegistry {
public <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiator);
public <R extends Service> void configureService(R service);
}

private final OwningRegistry serviceRegistry;
Expand Down

0 comments on commit c044422

Please sign in to comment.