org.apache.catalina.Loader类的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(167)

本文整理了Java中org.apache.catalina.Loader类的一些代码示例,展示了Loader类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Loader类的具体详情如下:
包路径:org.apache.catalina.Loader
类名称:Loader

Loader介绍

[英]A Loader represents a Java ClassLoader implementation that can be used by a Container to load class files (within a repository associated with the Loader) that are designed to be reloaded upon request, as well as a mechanism to detect whether changes have occurred in the underlying repository.

In order for a Loader implementation to successfully operate with a Context implementation that implements reloading, it must obey the following constraints:

  • Must implement Lifecycle so that the Context can indicate that a new class loader is required.
  • The start() method must unconditionally create a new ClassLoader implementation.
  • The stop() method must throw away its reference to the ClassLoader previously utilized, so that the class loader, all classes loaded by it, and all objects of those classes, can be garbage collected.
  • Must allow a call to stop() to be followed by a call to start() on the same Loader instance.
  • Based on a policy chosen by the implementation, must call the Context.reload() method on the owning Context when a change to one or more of the class files loaded by this class loader is detected.
    [中]加载器表示Java类加载器实现,容器可以使用它来加载类文件(在与加载器关联的存储库中),这些类文件设计为在请求时重新加载,以及检测底层存储库中是否发生了更改的机制。
    为了使Loader实现与实现重新加载的Context实现成功运行,它必须遵守以下约束:
    *必须实现Lifecycle,以便上下文可以指示需要新的类加载器。
    *start()方法必须无条件地创建新的ClassLoader实现。
    *stop()方法必须放弃对先前使用的ClassLoader的引用,以便类装入器、它装入的所有类以及这些类的所有对象都可以被垃圾收集。
    *必须允许在同一Loader实例上先调用stop(),然后再调用start()
    *根据实现选择的策略,当检测到此类加载器加载的一个或多个类文件发生更改时,必须调用所属Context上的Context.reload()方法。

代码示例

代码示例来源:origin: apache/geode

File store = sessionStore(context.getPath());
if (store == null) {
 getLogger().debug("No session store file found");
 return;
if (getLogger().isDebugEnabled()) {
 getLogger().debug("Loading sessions from " + store.getAbsolutePath());
 bis = new BufferedInputStream(fis);
 if (getTheContext() != null) {
  loader = getTheContext().getLoader();
  classLoader = loader.getClassLoader();

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

/**
 * Attempt to load a class using the given Container's class loader. If the
 * class cannot be loaded, a debug level log message will be written to the
 * Container's log and null will be returned.
 * @param context The class loader of this context will be used to attempt
 *  to load the class
 * @param className The class name
 * @return the loaded class or <code>null</code> if loading failed
 */
public static Class<?> loadClass(Context context, String className) {
  ClassLoader cl = context.getLoader().getClassLoader();
  Log log = context.getLogger();
  Class<?> clazz = null;
  try {
    clazz = cl.loadClass(className);
  } catch (ClassNotFoundException | NoClassDefFoundError | ClassFormatError e) {
    log.debug(sm.getString("introspection.classLoadFailed", className), e);
  } catch (Throwable t) {
    ExceptionUtils.handleThrowable(t);
    log.debug(sm.getString("introspection.classLoadFailed", className), t);
  }
  return clazz;
}

代码示例来源:origin: org.jboss.as/jboss-as-webservices-server-integration

private StandardContext startWebApp(Host host) throws Exception {
  StandardContext context = new StandardContext();
  try {
    context.setPath(contextRoot);
    context.addLifecycleListener(new ContextConfig());
    File docBase = new File(serverTempDir, contextRoot);
    if (!docBase.exists()) {
    loader.setContainer(host);
    context.setLoader(loader);
    context.setInstanceManager(new LocalInstanceManager());

代码示例来源:origin: org.glassfish.main.web/web-core

protected void processChildren(Container container, ClassLoader cl) {
  try {
    if (container.getLoader() != null) {
      Thread.currentThread().setContextClassLoader
        (container.getLoader().getClassLoader());
    }
    container.backgroundProcess();
  } catch (Throwable t) {
    log.log(Level.SEVERE, LogFacade.EXCEPTION_INVOKES_PERIODIC_OP, t);
  } finally {
    Thread.currentThread().setContextClassLoader(cl);
  }
  Container[] children = container.findChildren();
  for (int i = 0; i < children.length; i++) {
    if (children[i].getBackgroundProcessorDelay() <= 0) {
      processChildren(children[i], cl);
    }
  }
}

代码示例来源:origin: codefollower/Tomcat-Research

@Override
public void backgroundProcess() {
  if (!getState().isAvailable())
    return;
  Loader loader = getLoader();
  if (loader != null) {
    try {
      loader.backgroundProcess();
    } catch (Exception e) {
      log.warn(sm.getString(
          "standardContext.backgroundProcess.loader", loader), e);
  Manager manager = getManager();
  if (manager != null) {
    try {
      manager.backgroundProcess();
    } catch (Exception e) {
      log.warn(sm.getString(
          "standardContext.backgroundProcess.manager", manager),
          e);
      resources.backgroundProcess();
    } catch (Exception e) {
      log.warn(sm.getString(
          "standardContext.backgroundProcess.resources",
          resources), e);

代码示例来源:origin: org.apache.geronimo.ext.tomcat/catalina

/**
 * 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);
}

代码示例来源:origin: psi-probe/psi-probe

@Override
public void listContextJsps(Context context, Summary summary, boolean compile) {
 ServletConfig servletConfig = (ServletConfig) context.findChild("jsp");
 if (servletConfig != null) {
  synchronized (servletConfig) {
   ServletContext sctx = context.getServletContext();
   Options opt = new EmbeddedServletOptions(servletConfig, sctx);
      new URLClassLoader(new URL[0], context.getLoader().getClassLoader())) {

代码示例来源:origin: psi-probe/psi-probe

Loader loader = ctx.getLoader();
ClassLoader classLoader = loader.getClassLoader();
Log4J2WebLoggerContextUtilsAccessor webLoggerContextUtilsAccessor =
  new Log4J2WebLoggerContextUtilsAccessor(classLoader);
Log4J2LoggerContextAccessor loggerContextAccessor =
  webLoggerContextUtilsAccessor.getWebLoggerContext(ctx.getServletContext());
List<Object> loggerContexts = getLoggerContexts(classLoader);
Object loggerConfig = null;

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

private void setClassLoaderProperty(String name, boolean value) {
  ClassLoader cl = getLoader().getClassLoader();
  if (!IntrospectionUtils.setProperty(cl, name, Boolean.toString(value))) {
    // Failed to set
    log.info(sm.getString(
        "standardContext.webappClassLoader.missingProperty",
        name, Boolean.toString(value)));
  }
}

代码示例来源:origin: com.ovea.tajin.server/tajin-server-tomcat7

cluster.backgroundProcess();
} catch (Exception e) {
  log.warn(sm.getString("containerBase.backgroundProcess.cluster", cluster), e);                
  loader.backgroundProcess();
} catch (Exception e) {
  log.warn(sm.getString("containerBase.backgroundProcess.loader", loader), e);                
  manager.backgroundProcess();
} catch (Exception e) {
  log.warn(sm.getString("containerBase.backgroundProcess.manager", manager), e);

代码示例来源:origin: magro/memcached-session-manager

@Override
public ClassLoader getContainerClassLoader() {
  return getContainer().getLoader().getClassLoader();
}

代码示例来源:origin: psi-probe/psi-probe

ClassLoader cl = ctx.getLoader().getClassLoader();
Object contextLogger = ctx.getLogger();
if (contextLogger != null) {
 if (contextLogger.getClass().getName().startsWith("org.apache.commons.logging")) {
 ServletContext servletContext = ctx.getServletContext();
 try {
  Log4J2LoggerContextAccessor loggerContextAccessor = null;

代码示例来源:origin: org.glassfish.web/web-glue

@SuppressWarnings("unchecked")
  private Class<? extends Servlet> loadServletClass(String className)
      throws ClassNotFoundException {
    return (Class <? extends Servlet>)
        ctx.getLoader().getClassLoader().loadClass(className);
  }
}

代码示例来源:origin: org.gatein.wci/wci-tomcat7

TC7WebAppContext(Context context) throws Exception
{
 super(context.getServletContext(), context.getLoader().getClassLoader(), context.getPath());
 this.context = context;
}

代码示例来源:origin: org.apache.geronimo.ext.tomcat/catalina

/**
 * Attempt to load a class using the given Container's class loader. If the
 * class cannot be loaded, a debug level log message will be written to the
 * Container's log and null will be returned.
 */
public static Class<?> loadClass(Container container, String className) {
  ClassLoader cl = container.getLoader().getClassLoader();
  Log log = container.getLogger();
  Class<?> clazz = null;
  try {
    clazz = cl.loadClass(className);
  } catch (ClassNotFoundException e) {
    log.debug(sm.getString("introspection.classLoadFailed"), e);
  } catch (NoClassDefFoundError e) {
    log.debug(sm.getString("introspection.classLoadFailed"), e);
  } catch (ClassFormatError e) {
    log.debug(sm.getString("introspection.classLoadFailed"), e);
  } catch (Throwable t) {
    ExceptionUtils.handleThrowable(t);
    log.debug(sm.getString("introspection.classLoadFailed"), t);
  }
  return clazz;
}

代码示例来源:origin: org.apache.openejb/tomee-catalina

} catch (Exception e) {
      logger.error("can't parse context xml for webapp " + webApp.path, e);
      standardContext = new StandardContext();
    } finally {
      CONTEXT_DIGESTER.reset();
  standardContext = new StandardContext();
if (standardContext.getPath() != null) {
  webApp.contextRoot = standardContext.getPath();
  standardContext.setDelegate(true);
  standardContext.setLoader(new TomEEWebappLoader(appInfo.path, classLoader));
  standardContext.getLoader().setDelegate(true);

代码示例来源:origin: org.jboss.as/jboss-as-webservices-server-integration

private static StandardContext startWebApp(Host host, WSEndpointDeploymentUnit unit) throws Exception {
  StandardContext context = new StandardContext();
  try {
    JBossWebMetaData jbwebMD = unit.getAttachment(WSAttachmentKeys.JBOSSWEB_METADATA_KEY);
    context.setPath(jbwebMD.getContextRoot());
    context.addLifecycleListener(new ContextConfig());
    ServerConfigService config = (ServerConfigService)unit.getServiceRegistry().getService(WSServices.CONFIG_SERVICE).getService();
    File docBase = new File(config.getValue().getServerTempDir(), jbwebMD.getContextRoot());
    if (!docBase.exists()) {
      docBase.mkdirs();
    }
    context.setDocBase(docBase.getPath());
    final Loader loader = new WebCtxLoader(unit.getAttachment(WSAttachmentKeys.CLASSLOADER_KEY));
    loader.setContainer(host);
    context.setLoader(loader);
    context.setInstanceManager(new LocalInstanceManager());
    addServlets(jbwebMD, context);
    host.addChild(context);
    context.create();
  } catch (Exception e) {
    throw MESSAGES.createContextPhaseFailed(e);
  }
  try {
    context.start();
  } catch (LifecycleException e) {
    throw MESSAGES.startContextPhaseFailed(e);
  }
  return context;
}

代码示例来源:origin: chexagon/redis-session-manager

@Override
public void invoke(Request request, Response response) throws IOException, ServletException {
  Context context = request.getContext();
  if (context == null) {
    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, sm.getString("standardHost.noContext"));
    return;
  }
  Thread.currentThread().setContextClassLoader(context.getLoader().getClassLoader());
  boolean processed = false;
  try {
    if (ignorePattern == null || !ignorePattern.matcher(request.getRequestURI()).matches()) {
      processed = true;
      if (log.isTraceEnabled()) {
        log.trace("Will save to redis after request for [" + getQueryString(request) + "]");
      }
    } else {
      if (log.isTraceEnabled()) {
        log.trace("Ignoring [" + getQueryString(request) + "]");
      }
    }
    getNext().invoke(request, response);
  } finally {
    manager.afterRequest(processed);
  }
}

代码示例来源:origin: magro/memcached-session-manager

@Override
public ClassLoader getContainerClassLoader() {
  return getContext().getLoader().getClassLoader();
}

代码示例来源:origin: org.apache.catalina/com.springsource.org.apache.catalina

((Lifecycle) oldLoader).stop();
  } catch (LifecycleException e) {
    log.error("ContainerBase.setLoader: stop: ", e);
  loader.setContainer(this);
if (getState().isAvailable() && (loader != null) &&
  (loader instanceof Lifecycle)) {
    ((Lifecycle) loader).start();
  } catch (LifecycleException e) {
    log.error("ContainerBase.setLoader: start: ", e);

相关文章