/** * 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); }
/** * 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); }
/** * 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 */ 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); }
/** * Deregister the MBean for this * <code>Loader</code> object. * * @param loader The Loader to be managed * * @exception Exception if an MBean cannot be deregistered */ 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); }
public void begin(Attributes attributes) throws Exception { // Look up the required parent class loader Container container = (Container) digester.peek(); ClassLoader parentClassLoader = container.getParentClassLoader(); // Instantiate a new Loader implementation object String className = loaderClass; if (attributeName != null) { String value = attributes.getValue(attributeName); if (value != null) className = value; } Class clazz = Class.forName(className); Class types[] = { ClassLoader.class }; Object args[] = { parentClassLoader }; Constructor constructor = clazz.getDeclaredConstructor(types); Loader loader = (Loader) constructor.newInstance(args); // Push the new loader onto the stack digester.push(loader); if (digester.getDebug() >= 1) digester.log("new " + loader.getClass().getName()); }
/** * 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 */ public static ModelMBean 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(); ModelMBean mbean = managed.createMBean(loader); ObjectName oname = createObjectName(domain, loader); mserver.registerMBean(mbean, oname); return (mbean); }
/** * Deregister the MBean for this * <code>Loader</code> object. * * @param loader The Loader to be managed * * @exception Exception if an MBean cannot be deregistered */ public 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); mserver.unregisterMBean(oname); }
/** * Is this an instance of the default <code>Loader</code> configuration, * with all-default properties? * * @param loader Loader to be tested */ private boolean isDefaultLoader(Loader loader) { if (!(loader instanceof WebappLoader)) { return (false); } WebappLoader wloader = (WebappLoader) loader; if ((wloader.getCheckInterval() != 15) || (wloader.getDebug() != 0) || (wloader.getDelegate() != false) || !wloader.getLoaderClass().equals ("org.apache.catalina.loader.WebappClassLoader")) { return (false); } return (true); }
private void initializeSerializer() throws ClassNotFoundException, IllegalAccessException, InstantiationException { log.info("Attempting to use serializer :" + serializationStrategyClass); serializer = (Serializer) Class.forName(serializationStrategyClass).newInstance(); Loader loader = null; /* 默认支持tomcat7.x if (getContainer() != null) { loader = getContainer().getLoader(); } */ // 修改为支持tomcat8.x Context context = this.getContext(); if (context != null) { loader = context.getLoader(); } ClassLoader classLoader = null; if (loader != null) { classLoader = loader.getClassLoader(); } serializer.setClassLoader(classLoader); }
void initializeSerializer() throws ReflectiveOperationException { log.info("Attempting to use serializer :" + serializationStrategyClass); serializer = (Serializer) Class.forName(serializationStrategyClass).newInstance(); Loader loader = null; if (getContext() != null) { loader = getContext().getLoader(); } ClassLoader classLoader = null; if (loader != null) { classLoader = loader.getClassLoader(); } serializer.setClassLoader(classLoader); }
/** * 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); }
/** * 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); }
private void initializeSerializer() throws ClassNotFoundException, IllegalAccessException, InstantiationException { log.info("Attempting to use serializer :" + serializationStrategyClass); serializer = (Serializer) Class.forName(serializationStrategyClass).newInstance(); Loader loader = null; Context context = this.getContext(); if (context != null) { loader = context.getLoader(); } /* * if (getContainer() != null) { loader = getContainer().getLoader(); }*/ ClassLoader classLoader = null; if (loader != null) { classLoader = loader.getClassLoader(); } serializer.setClassLoader(classLoader); }
/** * 初始化序列化 * @throws ClassNotFoundException * @throws IllegalAccessException * @throws InstantiationException */ private void initializeSerializer() throws ClassNotFoundException, IllegalAccessException, InstantiationException { log.info("Attempting to use serializer :" + serializationStrategyClass); serializer = (Serializer) Class.forName(serializationStrategyClass).newInstance(); Loader loader = null; if (getContainer() != null) { loader = getContainer().getLoader(); } ClassLoader classLoader = null; if (loader != null) { classLoader = loader.getClassLoader(); } serializer.setClassLoader(classLoader); }
/** * Create an <code>ObjectName</code> for this * <code>Loader</code> object. * * @param domain Domain in which this name is to be created * @param loader The Loader to be named * * @exception MalformedObjectNameException if a name cannot be created */ static ObjectName createObjectName(String domain, Loader loader) throws MalformedObjectNameException { ObjectName name = null; Container container = loader.getContainer(); if (container instanceof Engine) { name = new ObjectName(domain + ":type=Loader"); } else if (container instanceof Host) { name = new ObjectName(domain + ":type=Loader,host=" + container.getName()); } else if (container instanceof Context) { Context context = ((Context)container); ContextName cn = new ContextName(context.getName(), false); Container host = context.getParent(); name = new ObjectName(domain + ":type=Loader,context=" + cn.getDisplayName() + ",host=" + host.getName()); } return (name); }
/** * Create an <code>ObjectName</code> for this * <code>Loader</code> object. * * @param domain Domain in which this name is to be created * @param loader The Loader to be named * * @exception MalformedObjectNameException if a name cannot be created */ static ObjectName createObjectName(String domain, Loader loader) throws MalformedObjectNameException { ObjectName name = null; Container container = loader.getContainer(); if (container instanceof Engine) { name = new ObjectName(domain + ":type=Loader"); } else if (container instanceof Host) { name = new ObjectName(domain + ":type=Loader,host=" + container.getName()); } else if (container instanceof Context) { Context context = ((Context)container); ContextName cn = new ContextName(context.getName()); Container host = context.getParent(); name = new ObjectName(domain + ":type=Loader,context=" + cn.getDisplayName() + ",host=" + host.getName()); } return (name); }
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; }
/** * {@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); } } }
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()}; } }
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()}; } }
/** * 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); }
/** * 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); }
/** * 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>. */ public Loader getLoader() { if (loader != null) return (loader); if (parent != null) return (parent.getLoader()); return (null); }