HHH-15219 Re-introduce the ability to stop and then reactivate a ServiceRegistry

This commit is contained in:
Sanne Grinovero 2022-04-21 09:55:29 +01:00 committed by Sanne Grinovero
parent 8dcbed8d45
commit 46b3c10d8f
2 changed files with 25 additions and 1 deletions

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.boot.registry.internal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -94,6 +95,24 @@ 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.
*/
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!" );
}
super.resetParent( bootstrapServiceRegistry );
this.configurationValues = new HashMap( configurationValues );
super.reactivate();
applyServiceRegistrations( serviceInitiators, providedServices );
}
@Override
public synchronized <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiator) {
// todo : add check/error for unexpected initiator types?

View File

@ -416,7 +416,8 @@ public abstract class AbstractServiceRegistryImpl
}
/**
* Very advanced and tricky to handle: not designed for this. Intended for experiments only!
* 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 resetParent(BootstrapServiceRegistry newParent) {
if ( this.parent != null ) {
@ -434,6 +435,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.
*/
public synchronized void reactivate() {
if ( !active.compareAndSet(false, true) ) {
throw new IllegalStateException( "Was not inactive, could not reactivate!" );