private ClassLoaderContext getClassLoaderContext(boolean createIfAbsent) { ClassLoader contextClassLoader = ClassLoaderHelper.getContextClassLoader(); Long clKey = contextClassLoader == null ? NULL_CL_MARKER : ClassLoaderCache.getCache().putClassLoader(contextClassLoader); ClassLoaderContext classLoaderContext = _classLoaderContextMap.get(clKey); if (classLoaderContext == REMOVED_CONTEXT_MARKER) throw new MarshalContextClearedException("Service has been unloaded"); if (createIfAbsent && classLoaderContext == null) { classLoaderContext = new ClassLoaderContext(clKey); _classLoaderContextMap.put(clKey, classLoaderContext); if (clKey != NULL_CL_MARKER) { boolean classLoaderPresent = ClassLoaderCache.getCache().registerClassLoaderStateListener(clKey, this); //Double check, class loader could have been removed from last check till now if (!classLoaderPresent) { _classLoaderContextMap.remove(clKey); throw new MarshalContextClearedException("Service has been unloaded"); } } } return classLoaderContext; }
public synchronized void addAnnotation(Class<?> cl) { ClassLoaderContext classLoaderContext = getClassLoaderContext(true); classLoaderContext.addAnnotation(cl); if (_logger.isLoggable(Level.FINEST)) logFinest("Adding new annotation to outgoing context [" + cl.getName() + "], context class loader key " + classLoaderContext.getClassLoaderCacheKey()); }
public synchronized void putObjectStreamClassKey(ObjectStreamClass desc, int key) { ClassLoaderContext classLoaderContext = getClassLoaderContext(true); classLoaderContext.putObjectStreamClass(desc, key); if (_logger.isLoggable(Level.FINEST)) logFinest("Adding new ObjectStreamClass to outgoing context [" + desc.getName() + "] with specified key " + key + ", context class loader key " + classLoaderContext.getClassLoaderCacheKey()); }
public synchronized boolean containsAnnotation(Class<?> cl) { ClassLoaderContext classLoaderContext = getClassLoaderContext(false); if (classLoaderContext == null) return false; return classLoaderContext.containsAnnotation(cl); }
public synchronized int getObjectStreamClassKey(ObjectStreamClass desc) { ClassLoaderContext classLoaderContext = getClassLoaderContext(false); if (classLoaderContext == null) return 0; return classLoaderContext.getObjectStreamClassKey(desc); }