/** * Get service keyed by spi & classLoader. * * @param classLoader The class loader as key to retrieve the related cache * @param spiName The SPI class name * @return The object instance associated to the given class loader/SPI name */ private static synchronized Object get(ClassLoader classLoader, String spiName) { Map<String, Object> spis = EnvironmentCache.get(classLoader); if (spis != null) { return spis.get(spiName); } return null; }
/** * Release all internal references to previously created service * instances associated with the current thread context class loader. * The <code>release()</code> method is called for service instances that * implement the <code>Service</code> interface. * * This is useful in environments like servlet containers, * which implement application reloading by throwing away a ClassLoader. * Dangling references to objects in that class loader would prevent * garbage collection. */ public static synchronized void release() { EnvironmentCache.release(); }
/** * Put service keyed by spi & classLoader. * * @param classLoader The {@link EnvironmentCache} key * @param spiName The SPI class name * @param service The SPI object reference */ private static synchronized void put(ClassLoader classLoader, String spiName, Object service) { if (service != null) { Map<String, Object> spis = EnvironmentCache.get(classLoader); if (spis == null) { spis = new HashMap<String, Object>(EnvironmentCache.smallHashSize); EnvironmentCache.put(classLoader, spis); } spis.put(spiName, service); } }
/** * Release any internal references to a previously created service * instance associated with the current thread context class loader. * If the SPI instance implements <code>Service</code>, then call * <code>release()</code>. * * @param spiClass The previously created service */ public static synchronized void release(Class<?> spiClass) { Map<String, Object> spis = EnvironmentCache.get(JDKHooks.getJDKHooks().getThreadContextClassLoader()); if (spis != null) { spis.remove(spiClass.getName()); } }