Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.List;
import java.util.Map;

import org.hibernate.Internal;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.boot.registry.StandardServiceRegistry;
Expand Down Expand Up @@ -77,14 +78,16 @@ public static StandardServiceRegistryImpl create(
List<ProvidedService<?>> providedServices,
Map<String,Object> configurationValues) {

StandardServiceRegistryImpl instance = new StandardServiceRegistryImpl( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
final StandardServiceRegistryImpl instance =
new StandardServiceRegistryImpl( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
instance.initialize();
instance.applyServiceRegistrations( serviceInitiators, providedServices );

return instance;
}

protected void applyServiceRegistrations(List<StandardServiceInitiator<?>> serviceInitiators, List<ProvidedService<?>> providedServices) {
protected void applyServiceRegistrations(
List<StandardServiceInitiator<?>> serviceInitiators, List<ProvidedService<?>> providedServices) {
try {
// process initiators
for ( ServiceInitiator<?> initiator : serviceInitiators ) {
Expand All @@ -105,13 +108,15 @@ protected void applyServiceRegistrations(List<StandardServiceInitiator<?>> servi
}

/**
* Not intended for general use. We need the ability to stop and "reactivate" a registry to allow
* experimentation with technologies such as GraalVM, Quarkus and Cri-O.
* Not intended for general use. We need the ability to stop and "reactivate" a registry
* to allow experimentation with technologies such as GraalVM, Quarkus and Cri-O.
*/
public synchronized void resetAndReactivate(BootstrapServiceRegistry bootstrapServiceRegistry,
List<StandardServiceInitiator<?>> serviceInitiators,
List<ProvidedService<?>> providedServices,
Map<?, ?> configurationValues) {
@Internal
public synchronized void resetAndReactivate(
BootstrapServiceRegistry bootstrapServiceRegistry,
List<StandardServiceInitiator<?>> serviceInitiators,
List<ProvidedService<?>> providedServices,
Map<?, ?> configurationValues) {
if ( super.isActive() ) {
throw new IllegalStateException( "Can't reactivate an active registry" );
}
Expand All @@ -130,8 +135,8 @@ public synchronized <R extends Service> R initiateService(ServiceInitiator<R> se

@Override
public synchronized <R extends Service> void configureService(ServiceBinding<R> serviceBinding) {
if ( serviceBinding.getService() instanceof Configurable ) {
( (Configurable) serviceBinding.getService() ).configure( configurationValues );
if ( serviceBinding.getService() instanceof Configurable configurable ) {
configurable.configure( configurationValues );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;

import org.hibernate.Internal;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.Environment;
Expand Down Expand Up @@ -281,20 +282,18 @@ public <R extends Service> void injectDependencies(ServiceBinding<R> serviceBind

applyInjections( service );

if ( service instanceof ServiceRegistryAwareService ) {
( (ServiceRegistryAwareService) service ).injectServices( this );
if ( service instanceof ServiceRegistryAwareService serviceRegistryAwareService ) {
serviceRegistryAwareService.injectServices( this );
}
}

private <R extends Service> void applyInjections(R service) {
try {
for ( Method method : service.getClass().getMethods() ) {
InjectService injectService = method.getAnnotation( InjectService.class );
if ( injectService == null ) {
continue;
final InjectService injectService = method.getAnnotation( InjectService.class );
if ( injectService != null ) {
processInjection( service, method, injectService );
}

processInjection( service, method, injectService );
}
}
catch (NullPointerException e) {
Expand Down Expand Up @@ -339,8 +338,8 @@ private <T extends Service> void processInjection(T service, Method injectionMet

@Override
public <R extends Service> void startService(ServiceBinding<R> serviceBinding) {
if ( serviceBinding.getService() instanceof Startable ) {
( (Startable) serviceBinding.getService() ).start();
if ( serviceBinding.getService() instanceof Startable startable ) {
startable.start();
}
}

Expand All @@ -356,9 +355,8 @@ public synchronized void destroy() {
//threads not owning the synchronization lock can't get an invalid Service:
initializedServiceByRole.clear();
synchronized (serviceBindingList) {
ListIterator<ServiceBinding<?>> serviceBindingsIterator = serviceBindingList.listIterator(
serviceBindingList.size()
);
final ListIterator<ServiceBinding<?>> serviceBindingsIterator =
serviceBindingList.listIterator( serviceBindingList.size() );
while ( serviceBindingsIterator.hasPrevious() ) {
final ServiceBinding<?> serviceBinding = serviceBindingsIterator.previous();
serviceBinding.getLifecycleOwner().stopService( serviceBinding );
Expand All @@ -378,9 +376,9 @@ public synchronized void destroy() {
@Override
public synchronized <R extends Service> void stopService(ServiceBinding<R> binding) {
final Service service = binding.getService();
if ( service instanceof Stoppable ) {
if ( service instanceof Stoppable stoppable ) {
try {
( (Stoppable) service ).stop();
stoppable.stop();
}
catch ( Exception e ) {
log.unableToStopService( service.getClass(), e );
Expand Down Expand Up @@ -429,18 +427,18 @@ public synchronized void deRegisterChild(ServiceRegistryImplementor child) {
* experimentation with technologies such as GraalVM, Quarkus and Cri-O.
*/
public synchronized void resetParent(@Nullable BootstrapServiceRegistry newParent) {
if ( this.parent != null ) {
this.parent.deRegisterChild( this );
if ( parent != null ) {
parent.deRegisterChild( this );
}
if ( newParent != null ) {
if ( !(newParent instanceof ServiceRegistryImplementor) ) {
throw new IllegalArgumentException( "ServiceRegistry parent needs to implement ServiceRegistryImplementor" );
}
this.parent = (ServiceRegistryImplementor) newParent;
this.parent.registerChild( this );
parent = (ServiceRegistryImplementor) newParent;
parent.registerChild( this );
}
else {
this.parent = null;
parent = null;
}
}

Expand Down Expand Up @@ -472,9 +470,10 @@ public synchronized void resetParent(@Nullable BootstrapServiceRegistry newParen
}

/**
* Not intended for general use. We need the ability to stop and "reactivate" a registry to allow
* experimentation with technologies such as GraalVM, Quarkus and Cri-O.
* Not intended for general use. We need the ability to stop and "reactivate" a registry
* to allow experimentation with technologies such as GraalVM, Quarkus and Cri-O.
*/
@Internal
public synchronized void reactivate() {
if ( !active.compareAndSet( false, true ) ) {
throw new IllegalStateException( "Was not inactive, could not reactivate" );
Expand Down