1414import java .util .concurrent .atomic .AtomicBoolean ;
1515import java .util .function .Consumer ;
1616
17+ import org .hibernate .Internal ;
1718import org .hibernate .boot .registry .BootstrapServiceRegistry ;
1819import org .hibernate .boot .registry .classloading .spi .ClassLoaderService ;
1920import org .hibernate .cfg .Environment ;
@@ -281,20 +282,18 @@ public <R extends Service> void injectDependencies(ServiceBinding<R> serviceBind
281282
282283 applyInjections ( service );
283284
284- if ( service instanceof ServiceRegistryAwareService ) {
285- ( ( ServiceRegistryAwareService ) service ) .injectServices ( this );
285+ if ( service instanceof ServiceRegistryAwareService serviceRegistryAwareService ) {
286+ serviceRegistryAwareService .injectServices ( this );
286287 }
287288 }
288289
289290 private <R extends Service > void applyInjections (R service ) {
290291 try {
291292 for ( Method method : service .getClass ().getMethods () ) {
292- InjectService injectService = method .getAnnotation ( InjectService .class );
293- if ( injectService = = null ) {
294- continue ;
293+ final InjectService injectService = method .getAnnotation ( InjectService .class );
294+ if ( injectService ! = null ) {
295+ processInjection ( service , method , injectService ) ;
295296 }
296-
297- processInjection ( service , method , injectService );
298297 }
299298 }
300299 catch (NullPointerException e ) {
@@ -339,8 +338,8 @@ private <T extends Service> void processInjection(T service, Method injectionMet
339338
340339 @ Override
341340 public <R extends Service > void startService (ServiceBinding <R > serviceBinding ) {
342- if ( serviceBinding .getService () instanceof Startable ) {
343- ( ( Startable ) serviceBinding . getService () ) .start ();
341+ if ( serviceBinding .getService () instanceof Startable startable ) {
342+ startable .start ();
344343 }
345344 }
346345
@@ -356,9 +355,8 @@ public synchronized void destroy() {
356355 //threads not owning the synchronization lock can't get an invalid Service:
357356 initializedServiceByRole .clear ();
358357 synchronized (serviceBindingList ) {
359- ListIterator <ServiceBinding <?>> serviceBindingsIterator = serviceBindingList .listIterator (
360- serviceBindingList .size ()
361- );
358+ final ListIterator <ServiceBinding <?>> serviceBindingsIterator =
359+ serviceBindingList .listIterator ( serviceBindingList .size () );
362360 while ( serviceBindingsIterator .hasPrevious () ) {
363361 final ServiceBinding <?> serviceBinding = serviceBindingsIterator .previous ();
364362 serviceBinding .getLifecycleOwner ().stopService ( serviceBinding );
@@ -378,9 +376,9 @@ public synchronized void destroy() {
378376 @ Override
379377 public synchronized <R extends Service > void stopService (ServiceBinding <R > binding ) {
380378 final Service service = binding .getService ();
381- if ( service instanceof Stoppable ) {
379+ if ( service instanceof Stoppable stoppable ) {
382380 try {
383- ( ( Stoppable ) service ) .stop ();
381+ stoppable .stop ();
384382 }
385383 catch ( Exception e ) {
386384 log .unableToStopService ( service .getClass (), e );
@@ -429,18 +427,18 @@ public synchronized void deRegisterChild(ServiceRegistryImplementor child) {
429427 * experimentation with technologies such as GraalVM, Quarkus and Cri-O.
430428 */
431429 public synchronized void resetParent (@ Nullable BootstrapServiceRegistry newParent ) {
432- if ( this . parent != null ) {
433- this . parent .deRegisterChild ( this );
430+ if ( parent != null ) {
431+ parent .deRegisterChild ( this );
434432 }
435433 if ( newParent != null ) {
436434 if ( !(newParent instanceof ServiceRegistryImplementor ) ) {
437435 throw new IllegalArgumentException ( "ServiceRegistry parent needs to implement ServiceRegistryImplementor" );
438436 }
439- this . parent = (ServiceRegistryImplementor ) newParent ;
440- this . parent .registerChild ( this );
437+ parent = (ServiceRegistryImplementor ) newParent ;
438+ parent .registerChild ( this );
441439 }
442440 else {
443- this . parent = null ;
441+ parent = null ;
444442 }
445443 }
446444
@@ -472,9 +470,10 @@ public synchronized void resetParent(@Nullable BootstrapServiceRegistry newParen
472470 }
473471
474472 /**
475- * Not intended for general use. We need the ability to stop and "reactivate" a registry to allow
476- * experimentation with technologies such as GraalVM, Quarkus and Cri-O.
473+ * Not intended for general use. We need the ability to stop and "reactivate" a registry
474+ * to allow experimentation with technologies such as GraalVM, Quarkus and Cri-O.
477475 */
476+ @ Internal
478477 public synchronized void reactivate () {
479478 if ( !active .compareAndSet ( false , true ) ) {
480479 throw new IllegalStateException ( "Was not inactive, could not reactivate" );
0 commit comments