diff --git a/hibernate-core/src/main/java/org/hibernate/boot/registry/internal/StandardServiceRegistryImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/registry/internal/StandardServiceRegistryImpl.java index 13b1148a83..aefa728afe 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/registry/internal/StandardServiceRegistryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/registry/internal/StandardServiceRegistryImpl.java @@ -8,6 +8,7 @@ import java.util.HashMap; 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; @@ -77,14 +78,16 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp List> providedServices, Map 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> serviceInitiators, List> providedServices) { + protected void applyServiceRegistrations( + List> serviceInitiators, List> providedServices) { try { // process initiators for ( ServiceInitiator initiator : serviceInitiators ) { @@ -105,13 +108,15 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp } /** - * 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> serviceInitiators, - List> providedServices, - Map configurationValues) { + @Internal + public synchronized void resetAndReactivate( + BootstrapServiceRegistry bootstrapServiceRegistry, + List> serviceInitiators, + List> providedServices, + Map configurationValues) { if ( super.isActive() ) { throw new IllegalStateException( "Can't reactivate an active registry" ); } @@ -130,8 +135,8 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp @Override public synchronized void configureService(ServiceBinding serviceBinding) { - if ( serviceBinding.getService() instanceof Configurable ) { - ( (Configurable) serviceBinding.getService() ).configure( configurationValues ); + if ( serviceBinding.getService() instanceof Configurable configurable ) { + configurable.configure( configurationValues ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java b/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java index e7f0c02486..406cc1c4fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java @@ -14,6 +14,7 @@ import java.util.concurrent.ConcurrentMap; 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; @@ -281,20 +282,18 @@ public abstract class AbstractServiceRegistryImpl applyInjections( service ); - if ( service instanceof ServiceRegistryAwareService ) { - ( (ServiceRegistryAwareService) service ).injectServices( this ); + if ( service instanceof ServiceRegistryAwareService serviceRegistryAwareService ) { + serviceRegistryAwareService.injectServices( this ); } } private 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) { @@ -339,8 +338,8 @@ public abstract class AbstractServiceRegistryImpl @Override public void startService(ServiceBinding serviceBinding) { - if ( serviceBinding.getService() instanceof Startable ) { - ( (Startable) serviceBinding.getService() ).start(); + if ( serviceBinding.getService() instanceof Startable startable ) { + startable.start(); } } @@ -356,9 +355,8 @@ public abstract class AbstractServiceRegistryImpl //threads not owning the synchronization lock can't get an invalid Service: initializedServiceByRole.clear(); synchronized (serviceBindingList) { - ListIterator> serviceBindingsIterator = serviceBindingList.listIterator( - serviceBindingList.size() - ); + final ListIterator> serviceBindingsIterator = + serviceBindingList.listIterator( serviceBindingList.size() ); while ( serviceBindingsIterator.hasPrevious() ) { final ServiceBinding serviceBinding = serviceBindingsIterator.previous(); serviceBinding.getLifecycleOwner().stopService( serviceBinding ); @@ -378,9 +376,9 @@ public abstract class AbstractServiceRegistryImpl @Override public synchronized void stopService(ServiceBinding 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 ); @@ -429,18 +427,18 @@ public abstract class AbstractServiceRegistryImpl * 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; } } @@ -472,9 +470,10 @@ public abstract class AbstractServiceRegistryImpl } /** - * 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" );