org.apache.catalina.Loader Java Examples
The following examples show how to use
org.apache.catalina.Loader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MBeanUtils.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Create, register, and return an MBean for this * <code>Loader</code> object. * * @param loader The Loader to be managed * * @exception Exception if an MBean cannot be created or registered * * @deprecated Unused. Will be removed in Tomcat 8.0.x */ @Deprecated static DynamicMBean createMBean(Loader loader) throws Exception { String mname = createManagedName(loader); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { Exception e = new Exception("ManagedBean is not found with "+mname); throw new MBeanException(e); } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); DynamicMBean mbean = managed.createMBean(loader); ObjectName oname = createObjectName(domain, loader); if( mserver.isRegistered( oname )) { // side effect: stop it mserver.unregisterMBean( oname ); } mserver.registerMBean(mbean, oname); return (mbean); }
Example #2
Source File: ClusterManagerBase.java From Tomcat8-Source-Read with MIT License | 6 votes |
public static ClassLoader[] getClassLoaders(Context context) { ClassLoader tccl = Thread.currentThread().getContextClassLoader(); Loader loader = context.getLoader(); ClassLoader classLoader = null; if (loader != null) { classLoader = loader.getClassLoader(); } if (classLoader == null) { classLoader = tccl; } if (classLoader == tccl) { return new ClassLoader[] {classLoader}; } else { return new ClassLoader[] {classLoader, tccl}; } }
Example #3
Source File: TomcatWebAppBuilder.java From tomee with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public void destroy(final StandardContext standardContext) { final Loader standardContextLoader = standardContext.getLoader(); if (LazyStopLoader.class.isInstance(standardContextLoader)) { final Loader delegate = LazyStopLoader.class.cast(standardContextLoader).getDelegateLoader(); if (TomEEWebappLoader.class.isInstance(delegate)) { final TomEEWebappLoader webappLoader = TomEEWebappLoader.class.cast(delegate); final ClassLoader loader = webappLoader.internalLoader(); webappLoader.clearLoader(); if (TomEEWebappClassLoader.class.isInstance(loader)) { TomEEWebappClassLoader.class.cast(loader).internalDestroy(); } } } final WebResourceRoot root = standardContext.getResources(); if (LazyStopStandardRoot.class.isInstance(root)) { try { LazyStopStandardRoot.class.cast(root).internalDestroy(); } catch (final LifecycleException e) { throw new IllegalStateException(e); } } }
Example #4
Source File: TomcatWebAppBuilder.java From tomee with Apache License 2.0 | 6 votes |
private static TomEEWebappClassLoader lazyClassLoader(final org.apache.catalina.Context child) { if (child == null) { return null; } final Loader loader = child.getLoader(); if (loader == null || !(loader instanceof LazyStopLoader)) { return null; } final ClassLoader old = ((LazyStopLoader) loader).getStopClassLoader(); if (old == null || !(old instanceof TomEEWebappClassLoader)) { return null; } return (TomEEWebappClassLoader) old; }
Example #5
Source File: MBeanUtils.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Deregister the MBean for this * <code>Loader</code> object. * * @param loader The Loader to be managed * * @exception Exception if an MBean cannot be deregistered * @deprecated Unused. Will be removed in Tomcat 8.0.x */ @Deprecated static void destroyMBean(Loader loader) throws Exception { String mname = createManagedName(loader); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { return; } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); ObjectName oname = createObjectName(domain, loader); if( mserver.isRegistered(oname) ) mserver.unregisterMBean(oname); }
Example #6
Source File: LoaderSF.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Store the only the Loader elements, when not default * * @see NamingResourcesSF#storeChildren(PrintWriter, int, Object, StoreDescription) */ @Override public void store(PrintWriter aWriter, int indent, Object aElement) throws Exception { StoreDescription elementDesc = getRegistry().findDescription( aElement.getClass()); if (elementDesc != null) { Loader loader = (Loader) aElement; if (!isDefaultLoader(loader)) { if (log.isDebugEnabled()) log.debug("store " + elementDesc.getTag() + "( " + aElement + " )"); getStoreAppender().printIndent(aWriter, indent + 2); getStoreAppender().printTag(aWriter, indent + 2, loader, elementDesc); } } else { if (log.isWarnEnabled()) { log .warn("Descriptor for element" + aElement.getClass() + " not configured or element class not StandardManager!"); } } }
Example #7
Source File: MBeanUtils.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Deregister the MBean for this * <code>Loader</code> object. * * @param loader The Loader to be managed * * @exception Exception if an MBean cannot be deregistered * @deprecated Unused. Will be removed in Tomcat 8.0.x */ @Deprecated static void destroyMBean(Loader loader) throws Exception { String mname = createManagedName(loader); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { return; } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); ObjectName oname = createObjectName(domain, loader); if( mserver.isRegistered(oname) ) mserver.unregisterMBean(oname); }
Example #8
Source File: MBeanUtils.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Create, register, and return an MBean for this * <code>Loader</code> object. * * @param loader The Loader to be managed * * @exception Exception if an MBean cannot be created or registered * * @deprecated Unused. Will be removed in Tomcat 8.0.x */ @Deprecated static DynamicMBean createMBean(Loader loader) throws Exception { String mname = createManagedName(loader); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { Exception e = new Exception("ManagedBean is not found with "+mname); throw new MBeanException(e); } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); DynamicMBean mbean = managed.createMBean(loader); ObjectName oname = createObjectName(domain, loader); if( mserver.isRegistered( oname )) { // side effect: stop it mserver.unregisterMBean( oname ); } mserver.registerMBean(mbean, oname); return (mbean); }
Example #9
Source File: Embedded.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Create and return a class loader manager that can be customized, and * then attached to a Context, before it is started. * * @param parent ClassLoader that will be the parent of the one * created by this Loader */ public Loader createLoader(ClassLoader parent) { if( log.isDebugEnabled() ) log.debug("Creating Loader with parent class loader '" + parent + "'"); WebappLoader loader = new WebappLoader(parent); return (loader); }
Example #10
Source File: Embedded.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Create and return a class loader manager that can be customized, and * then attached to a Context, before it is started. * * @param parent ClassLoader that will be the parent of the one * created by this Loader */ public Loader createLoader(ClassLoader parent) { if( log.isDebugEnabled() ) log.debug("Creating Loader with parent class loader '" + parent + "'"); WebappLoader loader = new WebappLoader(parent); return (loader); }
Example #11
Source File: ReplicatedContext.java From tomcatsrc with Apache License 2.0 | 5 votes |
public ClassLoader[] getClassLoaders() { Loader loader = null; ClassLoader classLoader = null; loader = this.getLoader(); if (loader != null) classLoader = loader.getClassLoader(); if ( classLoader == null ) classLoader = Thread.currentThread().getContextClassLoader(); if ( classLoader == Thread.currentThread().getContextClassLoader() ) { return new ClassLoader[] {classLoader}; } else { return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()}; } }
Example #12
Source File: ClusterManagerBase.java From tomcatsrc with Apache License 2.0 | 5 votes |
public static ClassLoader[] getClassLoaders(Container container) { Loader loader = null; ClassLoader classLoader = null; if (container != null) loader = container.getLoader(); if (loader != null) classLoader = loader.getClassLoader(); else classLoader = Thread.currentThread().getContextClassLoader(); if ( classLoader == Thread.currentThread().getContextClassLoader() ) { return new ClassLoader[] {classLoader}; } else { return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()}; } }
Example #13
Source File: ContainerBase.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Return the Loader with which this Container is associated. If there is * no associated Loader, return the Loader associated with our parent * Container (if any); otherwise, return <code>null</code>. */ @Override public Loader getLoader() { if (loader != null) return (loader); if (parent != null) return (parent.getLoader()); return (null); }
Example #14
Source File: ReplicatedContext.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
public ClassLoader[] getClassLoaders() { Loader loader = null; ClassLoader classLoader = null; loader = this.getLoader(); if (loader != null) classLoader = loader.getClassLoader(); if ( classLoader == null ) classLoader = Thread.currentThread().getContextClassLoader(); if ( classLoader == Thread.currentThread().getContextClassLoader() ) { return new ClassLoader[] {classLoader}; } else { return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()}; } }
Example #15
Source File: ClusterManagerBase.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
public static ClassLoader[] getClassLoaders(Container container) { Loader loader = null; ClassLoader classLoader = null; if (container != null) loader = container.getLoader(); if (loader != null) classLoader = loader.getClassLoader(); else classLoader = Thread.currentThread().getContextClassLoader(); if ( classLoader == Thread.currentThread().getContextClassLoader() ) { return new ClassLoader[] {classLoader}; } else { return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()}; } }
Example #16
Source File: ContainerBase.java From Tomcat8-Source-Read with MIT License | 5 votes |
protected void processChildren(Container container) { ClassLoader originalClassLoader = null; try { if (container instanceof Context) { Loader loader = ((Context) container).getLoader(); // Loader will be null for FailedContext instances if (loader == null) { return; } // Ensure background processing for Contexts and Wrappers // is performed under the web app's class loader originalClassLoader = ((Context) container).bind(false, null); } container.backgroundProcess(); Container[] children = container.findChildren(); for (int i = 0; i < children.length; i++) { if (children[i].getBackgroundProcessorDelay() <= 0) { processChildren(children[i]); } } } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.error("Exception invoking periodic operation: ", t); } finally { if (container instanceof Context) { ((Context) container).unbind(false, originalClassLoader); } } }
Example #17
Source File: LoaderSF.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Is this an instance of the default <code>Loader</code> configuration, * with all-default properties? * * @param loader * Loader to be tested * @return <code>true</code> if this is an instance of the default loader */ protected boolean isDefaultLoader(Loader loader) { if (!(loader instanceof WebappLoader)) { return false; } WebappLoader wloader = (WebappLoader) loader; if ((wloader.getDelegate() != false) || !wloader.getLoaderClass().equals( "org.apache.catalina.loader.WebappClassLoader")) { return false; } return true; }
Example #18
Source File: TomcatWebAppBuilder.java From tomee with Apache License 2.0 | 5 votes |
private void initContextLoader(final StandardContext standardContext) { final Loader standardContextLoader = standardContext.getLoader(); if (standardContextLoader != null && ( (!TomEEWebappLoader.class.equals(standardContextLoader.getClass()) && !WebappLoader.class.equals(standardContextLoader.getClass())) || (WebappLoader.class.equals(standardContextLoader.getClass()) && !WebappLoader.class.cast(standardContextLoader).getLoaderClass().startsWith("org.apache.tom"))) ) { // custom loader, we don't know it // and since we don't have a full delegate pattern for our lazy stop loader // simply skip lazy stop loader - normally sides effect will be an early shutdown for ears and some particular features // only affecting the app if the classes were not laoded at all return; } if (standardContextLoader != null && TomEEWebappLoader.class.isInstance(standardContextLoader)) { standardContextLoader.setContext(standardContext); return; // no need to replace the loader } // we just want to wrap it to lazy stop it (afterstop) // to avoid classnotfound in @PreDestoy or destroyApplication() final TomEEWebappLoader loader = new TomEEWebappLoader(); loader.setDelegate(standardContext.getDelegate()); loader.setLoaderClass(TomEEWebappClassLoader.class.getName()); final Loader lazyStopLoader = new LazyStopLoader(loader); standardContext.setLoader(lazyStopLoader); }
Example #19
Source File: ReplicatedContext.java From Tomcat8-Source-Read with MIT License | 5 votes |
public ClassLoader[] getClassLoaders() { Loader loader = null; ClassLoader classLoader = null; loader = this.getLoader(); if (loader != null) classLoader = loader.getClassLoader(); if ( classLoader == null ) classLoader = Thread.currentThread().getContextClassLoader(); if ( classLoader == Thread.currentThread().getContextClassLoader() ) { return new ClassLoader[] {classLoader}; } else { return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()}; } }
Example #20
Source File: TomcatWebAppBuilder.java From tomee with Apache License 2.0 | 4 votes |
private static DeploymentLoader.ExternalConfiguration configuredClasspath(final StandardContext standardContext) { Loader loader = standardContext.getLoader(); if (loader != null && LazyStopLoader.class.isInstance(loader)) { loader = LazyStopLoader.class.cast(loader).getDelegateLoader(); } if (loader != null) { final ClassLoader cl = standardContext.getLoader().getClassLoader(); if (cl == null) { return null; } final Collection<String> cp = new LinkedList<>(); final WebResourceRoot webResources = standardContext.getResources(); if (webResources != null) { // to enhance for (final WebResourceSet[] sets : asList(webResources.getPreResources(), webResources.getPostResources(), webResources.getJarResources())) { for (final WebResourceSet wr : sets) { final URL base = wr.getBaseUrl(); if (base != null) { final File baseFile = URLs.toFile(base); if (baseFile.isDirectory()) { final String[] libs = wr.list("/WEB-INF/lib/"); if (libs != null) { for (final String resource : libs) { cp.add(new File(baseFile, resource).getAbsolutePath()); } } final WebResource classes = wr.getResource("/WEB-INF/classes/"); if (classes != null) { final String path = classes.getCanonicalPath(); if (path != null) { cp.add(path); } } } else if (baseFile.exists() && baseFile.getName().endsWith(".jar") && wr.getResource("/WEB-INF/classes/").exists()) { try { cp.add(baseFile.getCanonicalPath()); } catch (final IOException e) { throw new IllegalStateException(e); } } } } } } if (!cp.isEmpty()) { return new DeploymentLoader.ExternalConfiguration(cp.toArray(new String[cp.size()]), null /*for now doesnt make sense, todo: configure*/); } } return null; }
Example #21
Source File: TesterHost.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public void setLoader(Loader loader) { // NO-OP }
Example #22
Source File: TesterHost.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public Loader getLoader() { return null; }
Example #23
Source File: LazyStopLoader.java From tomee with Apache License 2.0 | 4 votes |
public LazyStopLoader(final Loader loader) { delegate = loader; }
Example #24
Source File: TesterContext.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public void setLoader(Loader loader) { // NO-OP }
Example #25
Source File: TesterContext.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public Loader getLoader() { return null; }
Example #26
Source File: LazyStopLoader.java From tomee with Apache License 2.0 | 4 votes |
public Loader getDelegateLoader() { return delegate; }
Example #27
Source File: FailedContext.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public void setLoader(Loader loader) { /* NO-OP */ }
Example #28
Source File: FailedContext.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public Loader getLoader() { return null; }
Example #29
Source File: TesterContext.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Override public void setLoader(Loader loader) { // NO-OP }
Example #30
Source File: TesterContext.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Override public Loader getLoader() { return null; }