Top Description Inners Fields Constructors Methods
org.hibernate.boot.registry.classloading.internal

pack-priv abstract Class AggregatedServiceLoader<S>

extends Object
Class Inheritance
Known Direct Subclasses
org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader.ClassPathOnlyAggregatedServiceLoader, org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader.ClassPathAndModulePathAggregatedServiceLoader
Type Parameters
<S>
The type of the service contract.
Imports
java.lang.reflect.InvocationTargetException, .Method, java.util.ArrayList, .Collection, .Collections, .HashSet, .Iterator, .LinkedHashSet, .List, .ServiceConfigurationError, .ServiceLoader, .Set, java.util.function.Supplier, java.util.stream.Stream, org.hibernate.AssertionFailure, org.hibernate.internal.CoreLogging, .CoreMessageLogger

A service loader bound to an AggregatedClassLoader.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
AggregatedServiceLoader.ClassPathAndModulePathAggregatedServiceLoader<
The type of loaded services.
S
>

An AggregatedServiceLoader that will detect services defined in the class path or in the module path.

private static class
AggregatedServiceLoader.ClassPathOnlyAggregatedServiceLoader<
The type of loaded services.
S
>

An AggregatedServiceLoader that will only detect services defined in the class path, not in the module path, because it passes the aggregated classloader directly to the service loader.

Field Summary

Modifier and TypeField and Description
private static final CoreMessageLogger
private static final Method
private static final Method

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public abstract void
close()

Release all resources.

pack-priv static <S> AggregatedServiceLoader<S>
create(AggregatedClassLoader aggregatedClassLoader, Class<S> serviceContract)

public abstract Collection<S>

Returns:

All the loaded services.
getAll
()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

logback to summary
private static final CoreMessageLogger log
PROVIDER_TYPE_METHODback to summary
private static final Method PROVIDER_TYPE_METHOD
SERVICE_LOADER_STREAM_METHODback to summary
private static final Method SERVICE_LOADER_STREAM_METHOD

Constructor Detail

AggregatedServiceLoaderback to summary
pack-priv AggregatedServiceLoader()

Method Detail

closeback to summary
public abstract void close()

Release all resources.

createback to summary
pack-priv static <S> AggregatedServiceLoader<S> create(AggregatedClassLoader aggregatedClassLoader, Class<S> serviceContract)
getAllback to summary
public abstract Collection<S> getAll()
Returns:Collection<S>

All the loaded services.

org.hibernate.boot.registry.classloading.internal back to summary

private Class AggregatedServiceLoader.ClassPathAndModulePathAggregatedServiceLoader<S>

extends AggregatedServiceLoader<S>
Class Inheritance
Type Parameters
<S>
The type of loaded services.

An AggregatedServiceLoader that will detect services defined in the class path or in the module path.

This implementation only works when running Hibernate ORM on Java 9 and above. On Java 8, ClassPathOnlyAggregatedServiceLoader must be used.

When retrieving services from providers in the module path, the service loader internally uses a map from classloader to service catalog. Since the aggregated class loader is artificial and unknown from the service loader, it will never match any service from the module path.

To work around this problem, we try to get services from a service loader bound to the aggregated class loader first, then we try a service loader bound to each individual class loader.

This could result in duplicates, so we take specific care to avoid using the same service provider twice. See getAll().

Note that, in the worst case, the service retrieved from each individual class loader could load duplicate versions of classes already loaded from another class loader. For example in an aggregated class loader made up of individual class loader A, B, C: it is possible that class C1 was already loaded from A, but then we load service S1 from B, and this service will also need class C1 but won't find it in class loader B, so it will load its own version of that class.

We assume that this situation will never occur in practice because class loaders are structure in a hierarchy that prevents one class to be loaded twice.

Field Summary

Modifier and TypeField and Description
private final ServiceLoader<S>
private Collection<S>
private final List<ServiceLoader<S>>
private final Class<S>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
private void
collectServiceIfNotDuplicate(Set<S> result, Set<String> alreadyEncountered, Supplier<S> provider)

public Collection<S>
private boolean
private Collection<S>
private Stream<? extends Supplier<S>>
providerStream(ServiceLoader<S> serviceLoader)

Inherited from org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader:
create

Field Detail

aggregatedClassLoaderServiceLoaderback to summary
private final ServiceLoader<S> aggregatedClassLoaderServiceLoader
cacheback to summary
private Collection<S> cache
delegatesback to summary
private final List<ServiceLoader<S>> delegates
serviceContractback to summary
private final Class<S> serviceContract

Constructor Detail

ClassPathAndModulePathAggregatedServiceLoaderback to summary
private ClassPathAndModulePathAggregatedServiceLoader(AggregatedClassLoader aggregatedClassLoader, Class<S> serviceContract)

Method Detail

closeback to summary
public void close()

Implements abstract org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader.close.

Doc from org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader.close.

Release all resources.

Annotations
@Override
collectServiceIfNotDuplicateback to summary
private void collectServiceIfNotDuplicate(Set<S> result, Set<String> alreadyEncountered, Supplier<S> provider)
getAllback to summary
public Collection<S> getAll()

Implements abstract org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader.getAll.

Returns:Collection<S>

Doc from org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader.getAll.

All the loaded services.

Annotations
@Override
hasNextIgnoringServiceConfigurationErrorback to summary
private boolean hasNextIgnoringServiceConfigurationError(Iterator<?> iterator)
loadAllback to summary
private Collection<S> loadAll()
providerStreamback to summary
private Stream<? extends Supplier<S>> providerStream(ServiceLoader<S> serviceLoader)
Annotations
@SuppressWarnings:unchecked
org.hibernate.boot.registry.classloading.internal back to summary

private Class AggregatedServiceLoader.ClassPathOnlyAggregatedServiceLoader<S>

extends AggregatedServiceLoader<S>
Class Inheritance
Type Parameters
<S>
The type of loaded services.

An AggregatedServiceLoader that will only detect services defined in the class path, not in the module path, because it passes the aggregated classloader directly to the service loader.

This implementation is best when running Hibernate ORM on Java 8. On Java 9 and above, ClassPathAndModulePathAggregatedServiceLoader should be used.

Field Summary

Modifier and TypeField and Description
private final ServiceLoader<S>

Constructor Summary

AccessConstructor and Description
private
ClassPathOnlyAggregatedServiceLoader(AggregatedClassLoader aggregatedClassLoader, Class<S> serviceContract)

Method Summary

Modifier and TypeMethod and Description
public void
public Collection<S>
Inherited from org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader:
create

Field Detail

delegateback to summary
private final ServiceLoader<S> delegate

Constructor Detail

ClassPathOnlyAggregatedServiceLoaderback to summary
private ClassPathOnlyAggregatedServiceLoader(AggregatedClassLoader aggregatedClassLoader, Class<S> serviceContract)

Method Detail

closeback to summary
public void close()

Implements abstract org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader.close.

Doc from org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader.close.

Release all resources.

Annotations
@Override
getAllback to summary
public Collection<S> getAll()

Implements abstract org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader.getAll.

Returns:Collection<S>

Doc from org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader.getAll.

All the loaded services.

Annotations
@Override