Skip to content

Commit dbbe61c

Browse files
committed
minor cleanups to ServiceRegistryImpls
1 parent 985740e commit dbbe61c

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

hibernate-core/src/main/java/org/hibernate/boot/registry/internal/StandardServiceRegistryImpl.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.List;
99
import java.util.Map;
1010

11+
import org.hibernate.Internal;
1112
import org.hibernate.boot.registry.BootstrapServiceRegistry;
1213
import org.hibernate.boot.registry.StandardServiceInitiator;
1314
import org.hibernate.boot.registry.StandardServiceRegistry;
@@ -77,14 +78,16 @@ public static StandardServiceRegistryImpl create(
7778
List<ProvidedService<?>> providedServices,
7879
Map<String,Object> configurationValues) {
7980

80-
StandardServiceRegistryImpl instance = new StandardServiceRegistryImpl( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
81+
final StandardServiceRegistryImpl instance =
82+
new StandardServiceRegistryImpl( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
8183
instance.initialize();
8284
instance.applyServiceRegistrations( serviceInitiators, providedServices );
8385

8486
return instance;
8587
}
8688

87-
protected void applyServiceRegistrations(List<StandardServiceInitiator<?>> serviceInitiators, List<ProvidedService<?>> providedServices) {
89+
protected void applyServiceRegistrations(
90+
List<StandardServiceInitiator<?>> serviceInitiators, List<ProvidedService<?>> providedServices) {
8891
try {
8992
// process initiators
9093
for ( ServiceInitiator<?> initiator : serviceInitiators ) {
@@ -105,13 +108,15 @@ protected void applyServiceRegistrations(List<StandardServiceInitiator<?>> servi
105108
}
106109

107110
/**
108-
* Not intended for general use. We need the ability to stop and "reactivate" a registry to allow
109-
* experimentation with technologies such as GraalVM, Quarkus and Cri-O.
111+
* Not intended for general use. We need the ability to stop and "reactivate" a registry
112+
* to allow experimentation with technologies such as GraalVM, Quarkus and Cri-O.
110113
*/
111-
public synchronized void resetAndReactivate(BootstrapServiceRegistry bootstrapServiceRegistry,
112-
List<StandardServiceInitiator<?>> serviceInitiators,
113-
List<ProvidedService<?>> providedServices,
114-
Map<?, ?> configurationValues) {
114+
@Internal
115+
public synchronized void resetAndReactivate(
116+
BootstrapServiceRegistry bootstrapServiceRegistry,
117+
List<StandardServiceInitiator<?>> serviceInitiators,
118+
List<ProvidedService<?>> providedServices,
119+
Map<?, ?> configurationValues) {
115120
if ( super.isActive() ) {
116121
throw new IllegalStateException( "Can't reactivate an active registry" );
117122
}
@@ -130,8 +135,8 @@ public synchronized <R extends Service> R initiateService(ServiceInitiator<R> se
130135

131136
@Override
132137
public synchronized <R extends Service> void configureService(ServiceBinding<R> serviceBinding) {
133-
if ( serviceBinding.getService() instanceof Configurable ) {
134-
( (Configurable) serviceBinding.getService() ).configure( configurationValues );
138+
if ( serviceBinding.getService() instanceof Configurable configurable ) {
139+
configurable.configure( configurationValues );
135140
}
136141
}
137142

hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.concurrent.atomic.AtomicBoolean;
1515
import java.util.function.Consumer;
1616

17+
import org.hibernate.Internal;
1718
import org.hibernate.boot.registry.BootstrapServiceRegistry;
1819
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
1920
import 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

Comments
 (0)