Class Caching.CachingProviderRegistry
- java.lang.Object
-
- javax.cache.Caching.CachingProviderRegistry
-
- Enclosing class:
- Caching
private static class Caching.CachingProviderRegistry extends java.lang.ObjectMaintains a registry of loadedCachingProviders scoped byClassLoader.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.WeakHashMap<java.lang.ClassLoader,java.util.LinkedHashMap<java.lang.String,CachingProvider>>cachingProvidersTheCachingProviders by Class Name organized by theClassLoaderwas used to load them.private java.lang.ClassLoaderclassLoaderThe defaultClassLoader.
-
Constructor Summary
Constructors Constructor Description CachingProviderRegistry()Constructs a CachingProviderManager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CachingProvidergetCachingProvider()Obtains the onlyCachingProviderdefined by thegetDefaultClassLoader().CachingProvidergetCachingProvider(java.lang.ClassLoader classLoader)Obtains the onlyCachingProviderdefined by the specifiedClassLoader.CachingProvidergetCachingProvider(java.lang.String fullyQualifiedClassName)Obtain theCachingProviderthat is implemented by the specified fully qualified class name using thegetDefaultClassLoader().CachingProvidergetCachingProvider(java.lang.String fullyQualifiedClassName, java.lang.ClassLoader classLoader)Obtain theCachingProviderthat is implemented by the specified fully qualified class name using the providedClassLoader.java.lang.Iterable<CachingProvider>getCachingProviders()Obtain theCachingProviders that are available via thegetDefaultClassLoader().java.lang.Iterable<CachingProvider>getCachingProviders(java.lang.ClassLoader classLoader)Obtain theCachingProviders that are available via the specifiedClassLoader.java.lang.ClassLoadergetDefaultClassLoader()Obtains theClassLoaderto use for API methods that don't explicitly require aClassLoaderbut internally require one.protected CachingProviderloadCachingProvider(java.lang.String fullyQualifiedClassName, java.lang.ClassLoader classLoader)Load and instantiate theCachingProviderwith the specified fully qualified class name using the providedClassLoadervoidsetDefaultClassLoader(java.lang.ClassLoader classLoader)Set theClassLoaderto use for API methods that don't explicitly require aClassLoader, but internally use one.
-
-
-
Field Detail
-
cachingProviders
private java.util.WeakHashMap<java.lang.ClassLoader,java.util.LinkedHashMap<java.lang.String,CachingProvider>> cachingProviders
TheCachingProviders by Class Name organized by theClassLoaderwas used to load them.
-
classLoader
private volatile java.lang.ClassLoader classLoader
The defaultClassLoader. WhennulltheThread.getContextClassLoader()will be used.
-
-
Method Detail
-
getDefaultClassLoader
public java.lang.ClassLoader getDefaultClassLoader()
Obtains theClassLoaderto use for API methods that don't explicitly require aClassLoaderbut internally require one.By default this is the
Thread.getContextClassLoader().- Returns:
- the default
ClassLoader
-
setDefaultClassLoader
public void setDefaultClassLoader(java.lang.ClassLoader classLoader)
Set theClassLoaderto use for API methods that don't explicitly require aClassLoader, but internally use one.- Parameters:
classLoader- theClassLoaderornullif the callingThread.getContextClassLoader()should be used
-
getCachingProvider
public CachingProvider getCachingProvider()
Obtains the onlyCachingProviderdefined by thegetDefaultClassLoader().Should zero or more than one
CachingProviders be available, a CacheException is thrown.- Returns:
- the
CachingProvider - Throws:
CacheException- should zero or more than oneCachingProviderbe available or aCachingProvidercould not be loaded- See Also:
getCachingProvider(ClassLoader),getCachingProviders(ClassLoader)
-
getCachingProvider
public CachingProvider getCachingProvider(java.lang.ClassLoader classLoader)
Obtains the onlyCachingProviderdefined by the specifiedClassLoader.Should zero or more than one
CachingProviders be available, a CacheException is thrown.- Parameters:
classLoader- theClassLoaderto use for loading theCachingProvider- Returns:
- the
CachingProvider - Throws:
CacheException- should zero or more than oneCachingProviderbe available or aCachingProvidercould not be loaded- See Also:
getCachingProviders(ClassLoader)
-
getCachingProviders
public java.lang.Iterable<CachingProvider> getCachingProviders()
Obtain theCachingProviders that are available via thegetDefaultClassLoader().If a
javax.cache.spi.cachingprovidersystem property is defined, only thatCachingProviderspecified by that property is returned. Otherwise allCachingProviders that are available via aServiceLoaderforCachingProviders using the defaultClassLoader(and those explicitly requested viagetCachingProvider(String)) are returned.- Returns:
- an
IterableofCachingProviders loaded by the defaultClassLoader
-
getCachingProviders
public java.lang.Iterable<CachingProvider> getCachingProviders(java.lang.ClassLoader classLoader)
Obtain theCachingProviders that are available via the specifiedClassLoader.If a
javax.cache.spi.cachingprovidersystem property is defined, only thatCachingProviderspecified by that property is returned. Otherwise allCachingProviders that are available via aServiceLoaderforCachingProviders using the specifiedClassLoader(and those explicitly requested viagetCachingProvider(String, ClassLoader)) are returned.- Parameters:
classLoader- theClassLoaderof the returnedCachingProviders- Returns:
- an
IterableofCachingProviders loaded by the specifiedClassLoader
-
getCachingProvider
public CachingProvider getCachingProvider(java.lang.String fullyQualifiedClassName)
Obtain theCachingProviderthat is implemented by the specified fully qualified class name using thegetDefaultClassLoader(). Should thisCachingProvideralready be loaded it is simply returned, otherwise an attempt will be made to load and instantiate the specified class name (using a no-args constructor).- Parameters:
fullyQualifiedClassName- the fully qualified class name of theCachingProvider- Returns:
- the
CachingProvider - Throws:
CacheException- when theCachingProvidercan't be created
-
loadCachingProvider
protected CachingProvider loadCachingProvider(java.lang.String fullyQualifiedClassName, java.lang.ClassLoader classLoader) throws CacheException
Load and instantiate theCachingProviderwith the specified fully qualified class name using the providedClassLoader- Parameters:
fullyQualifiedClassName- the name of theCachingProviderclassclassLoader- theClassLoaderto use- Returns:
- a new
CachingProviderinstance - Throws:
CacheException- if the specifiedCachingProvidercould not be loaded or the specified class is not aCachingProvider
-
getCachingProvider
public CachingProvider getCachingProvider(java.lang.String fullyQualifiedClassName, java.lang.ClassLoader classLoader)
Obtain theCachingProviderthat is implemented by the specified fully qualified class name using the providedClassLoader. Should thisCachingProvideralready be loaded it is returned, otherwise an attempt will be made to load and instantiate the specified class (using a no-args constructor).- Parameters:
fullyQualifiedClassName- the fully qualified class name of theCachingProviderclassLoader- theClassLoaderto load theCachingProvider- Returns:
- the
CachingProvider - Throws:
CacheException- when theCachingProvidercan't be created
-
-