/** * {@inheritDoc} */ @Override public ClassLoader getDefaultClassLoader() { return ClassLoading.getDefaultClassLoader(); }
/** * Constructs an instance of XmlConfiguration from the given XML DOM. * <p> * The default ClassLoader will first try to use the thread context class loader, followed by the ClassLoader that * loaded the Ehcache classes. * * @param xml XML Document Object Model * * @throws XmlConfigurationException if anything went wrong parsing the XML */ public XmlConfiguration(Document xml) throws XmlConfigurationException { this(xml, ClassLoading.getDefaultClassLoader()); }
/** * Constructs an instance of XmlConfiguration mapping to the XML file located at {@code url}. * <p> * The default ClassLoader will first try to use the thread context class loader, followed by the ClassLoader that * loaded the Ehcache classes. * * @param url URL pointing to the XML file's location * * @throws XmlConfigurationException if anything went wrong parsing the XML */ public XmlConfiguration(URL url) throws XmlConfigurationException { this(url, ClassLoading.getDefaultClassLoader()); }
/** * Creates a new configuration with the specified {@link CacheConfiguration cache configurations}, class loader and * {@link org.ehcache.spi.service.ServiceConfiguration service configurations}. * * @param caches a map from alias to cache configuration * @param classLoader the class loader to use for user types * @param services an array of service configurations */ public DefaultConfiguration(Map<String, CacheConfiguration<?, ?>> caches, ClassLoader classLoader, ServiceCreationConfiguration<?>... services) { this.services = unmodifiableCollection(Arrays.asList(services)); this.caches = new ConcurrentHashMap<>(caches); this.classLoader = classLoader == null ? ClassLoading.getDefaultClassLoader() : classLoader; }
public EhcacheManager(Configuration config, UnaryOperator<ServiceLocator.DependencySet> customization, boolean useLoaderInAtomics) { final String simpleName = this.getClass().getSimpleName(); this.simpleName = (simpleName.isEmpty() ? this.getClass().getName() : simpleName); this.configuration = new DefaultConfiguration(config); this.cacheManagerClassLoader = config.getClassLoader() != null ? config.getClassLoader() : ClassLoading.getDefaultClassLoader(); this.useLoaderInAtomics = useLoaderInAtomics; validateServicesConfigs(); this.serviceLocator = resolveServices(customization); }
for (String className : optionalAnnotation.value()) { try { Class<?> dependencyClass = delegationChain(getDefaultClassLoader(), clazz.getClassLoader()).loadClass(className); if (Service.class.isAssignableFrom(dependencyClass)) { @SuppressWarnings("unchecked")
@Override public final ClassLoader getClassLoader() { ClassLoader classLoader = cacheBinding.getCache().getRuntimeConfiguration().getClassLoader(); return classLoader == null ? ClassLoading.getDefaultClassLoader() : classLoader; }
@Test public void testDefaultClassLoader() throws Exception { String resource = getClass().getName().replace('.', '/').concat(".class"); ClassLoader thisLoader = getClass().getClassLoader(); ClassLoader defaultClassLoader = ClassLoading.getDefaultClassLoader(); Thread.currentThread().setContextClassLoader(null); assertSame(thisLoader.loadClass(getClass().getName()), defaultClassLoader.loadClass(getClass().getName())); assertEquals(thisLoader.getResource(resource), defaultClassLoader.getResource(resource)); assertThat(list(defaultClassLoader.getResources(resource)), is(list(thisLoader.getResources(resource)))); Thread.currentThread().setContextClassLoader(new FindNothingLoader()); assertSame(thisLoader.loadClass(getClass().getName()), defaultClassLoader.loadClass(getClass().getName())); assertEquals(thisLoader.getResource(resource), defaultClassLoader.getResource(resource)); assertThat(list(defaultClassLoader.getResources(resource)), is(list(thisLoader.getResources(resource)))); URL url = new URL("file:///tmp"); ClassLoader tc = new TestClassLoader(url); Thread.currentThread().setContextClassLoader(tc); Class<?> c = defaultClassLoader.loadClass(getClass().getName()); assertNotSame(getClass(), c); assertSame(tc, c.getClassLoader()); assertEquals(url, defaultClassLoader.getResource(resource)); assertThat(list(defaultClassLoader.getResources(resource)), contains(url, thisLoader.getResource(resource))); }
cacheClassLoader = classLoader; } else { cacheClassLoader = ClassLoading.getDefaultClassLoader();
@Test public void testNoClassLoaderSpecified() { Map<String, CacheConfiguration<?, ?>> caches = newCacheMap(); caches.put("foo", new BaseCacheConfiguration<>(Object.class, Object.class, null, null, null, ResourcePoolsHelper.createHeapOnlyPools())); DefaultConfiguration config = new DefaultConfiguration(caches, null); final Store.Provider storeProvider = mock(Store.Provider.class); when(storeProvider.rank(any(Set.class), any(Collection.class))).thenReturn(1); final Store mock = mock(Store.class); final CacheEventDispatcherFactory cenlProvider = mock(CacheEventDispatcherFactory.class); final CacheEventDispatcher<Object, Object> cenlServiceMock = mock(CacheEventDispatcher.class); when(cenlProvider.createCacheEventDispatcher(mock)).thenReturn(cenlServiceMock); final Collection<Service> services = getServices(storeProvider, cenlProvider); when(storeProvider .createStore(ArgumentMatchers.<Store.Configuration>any(), ArgumentMatchers.<ServiceConfiguration[]>any())).thenReturn(mock); EhcacheManager cacheManager = new EhcacheManager(config, services); cacheManager.init(); assertSame(ClassLoading.getDefaultClassLoader(), cacheManager.getClassLoader()); assertSame(cacheManager.getClassLoader(), cacheManager.getCache("foo", Object.class, Object.class).getRuntimeConfiguration().getClassLoader()); }
@Test public void testNoClassLoaderSpecified() throws Exception { URL resource = XmlConfigurationTest.class.getResource("/configs/one-cache.xml"); XmlConfiguration config = new XmlConfiguration(new XmlConfiguration(resource)); assertSame(config.getClassLoader(), ClassLoading.getDefaultClassLoader()); assertNull(config.getCacheConfigurations().get("bar").getClassLoader()); }
@Test public void unparseServiceConfigurationWithInstance() { TestSerializer3<Integer> testSerializer3 = new TestSerializer3<>(ClassLoading.getDefaultClassLoader()); TestSerializer4<Integer> testSerializer4 = new TestSerializer4<>(ClassLoading.getDefaultClassLoader()); DefaultSerializerConfiguration<Integer> config1 = new DefaultSerializerConfiguration<>(testSerializer3, DefaultSerializerConfiguration.Type.KEY); DefaultSerializerConfiguration<Integer> config2 = new DefaultSerializerConfiguration<>(testSerializer4, DefaultSerializerConfiguration.Type.VALUE); CacheConfiguration<?, ?> cacheConfig = newCacheConfigurationBuilder(Description.class, Person.class, heap(10)) .add(config1).add(config2).build(); CacheType cacheType = new CacheType(); CacheEntryType keyType = new CacheEntryType(); keyType.setValue("foo"); cacheType.setKeyType(keyType); CacheEntryType valueType = new CacheEntryType(); valueType.setValue("bar"); cacheType.setValueType(valueType); assertThatExceptionOfType(XmlConfigurationException.class).isThrownBy(() -> new DefaultSerializerConfigurationParser().unparseServiceConfiguration(cacheConfig, cacheType)) .withMessage("%s", "XML translation for instance based initialization for " + "DefaultSerializerConfiguration is not supported"); } }