读懂tomact源码4:Container

2024-08-24 05:32
文章标签 源码 读懂 container tomact

本文主要是介绍读懂tomact源码4:Container,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Container的解释

 A Container is an object that can execute requests received froma client, and return responses based on those requests.  A Container mayoptionally support a pipeline of Valves that process the request in anorder configured at runtime, by implementing the Pipeline interfaceas well.

event type

/*** The ContainerEvent event type sent when a child container is added* by addChild().*/public static final String ADD_CHILD_EVENT = "addChild";/*** The ContainerEvent event type sent when a Mapper is added* by addMapper().* @deprecated Unused. Will be removed in Tomcat 8.0.x.*/@Deprecatedpublic static final String ADD_MAPPER_EVENT = "addMapper";/*** The ContainerEvent event type sent when a valve is added* by addValve(), if this Container supports pipelines.*/public static final String ADD_VALVE_EVENT = "addValve";/*** The ContainerEvent event type sent when a child container is removed by removeChild().*/public static final String REMOVE_CHILD_EVENT = "removeChild";/*** The ContainerEvent event type sent when a Mapper is removed* by removeMapper().* @deprecated Unused. Will be removed in Tomcat 8.0.x.*/@Deprecatedpublic static final String REMOVE_MAPPER_EVENT = "removeMapper";/*** The ContainerEvent event type sent when a valve is removed* by removeValve(), if this Container supports pipelines.*/public static final String REMOVE_VALVE_EVENT = "removeValve";

Properties

/*** Return descriptive information about this Container implementation * and the corresponding version number, in the format* <description>/<version>;.*/public String getInfo();/*** 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();/*** Set the Loader with which this Container is associated.* @param loader The newly associated loader*/public void setLoader(Loader loader);/*** Return the Logger with which this Container is associated.  If there is* no associated Logger, return the Logger associated with our parent* Container (if any); otherwise return <code>null</code>.*/public Log getLogger();/*** Return the Manager with which this Container is associated.  If there is* no associated Manager, return the Manager associated with our parent* Container (if any); otherwise return <code>null</code>.*/public Manager getManager();/*** Set the Manager with which this Container is associated.** @param manager The newly associated Manager*/public void setManager(Manager manager);/*** Return an object which may be utilized for mapping to this component.*/@Deprecatedpublic Object getMappingObject();/*** Return the JMX name associated with this container.*/public ObjectName getObjectName();/*** Return the Pipeline object that manages the Valves associated with* this Container.*/public Pipeline getPipeline();/*** Return the Cluster with which this Container is associated.  If there is* no associated Cluster, return the Cluster associated with our parent* Container (if any); otherwise return <code>null</code>.*/public Cluster getCluster();/*** Set the Cluster with which this Container is associated.** @param cluster the Cluster with which this Container is associated.*/public void setCluster(Cluster cluster);/*** Get the delay between the invocation of the backgroundProcess method on* this container and its children. Child containers will not be invoked* if their delay value is not negative (which would mean they are using* their own thread). Setting this to a positive value will cause* a thread to be spawn. After waiting the specified amount of time,* the thread will invoke the executePeriodic method on this container* and all its children.*/public int getBackgroundProcessorDelay();/*** Set the delay between the invocation of the execute method on this* container and its children* @param delay The delay in seconds between the invocation of*              backgroundProcess methods*/public void setBackgroundProcessorDelay(int delay);/*** Return a name string (suitable for use by humans) that describes * this Container.  Within the set of child containers belonging to a * particular parent, Container names must be unique.*/public String getName();/*** Set a name string (suitable for use by humans) that describes this* Container.  Within the set of child containers belonging to a * particular parent, Container names must be unique.* @param name New name of this container* @exception IllegalStateException if this Container has already * been added to the children of a parent Container (after which the *  name may not be changed)*/public void setName(String name);/*** Return the Container for which this Container is a child, if there is one.  If there is no defined parent, return <code>null</code>.*/public Container getParent();/*** Set the parent Container to which this Container is being added as a* child.  This Container may refuse to become attached to the specified* Container by throwing an exception.** @param container Container to which this Container is being added*  as a child** @exception IllegalArgumentException if this Container refuses to become*  attached to the specified Container*/public void setParent(Container container);/*** Return the parent class loader for this component. If not set, return* {@link #getParent()} {@link #getParentClassLoader()}. If no parent has* been set, return the system class loader.*/public ClassLoader getParentClassLoader();/*** Set the parent class loader for this component. For {@link Context}s* this call is meaningful only <strong>before</strong> a Loader has* been configured, and the specified value (if non-null) should be* passed as an argument to the class loader constructor.** @param parent The new parent class loader*/public void setParentClassLoader(ClassLoader parent);/*** Return the Realm with which this Container is associated.  If there is* no associated Realm, return the Realm associated with our parent* Container (if any); otherwise return <code>null</code>.*/public Realm getRealm();/*** Set the Realm with which this Container is associated.** @param realm The newly associated Realm*/public void setRealm(Realm realm);/*** Return the Resources with which this Container is associated.  If there* is no associated Resources object, return the Resources associated with* our parent Container (if any); otherwise return <code>null</code>.*/public DirContext getResources();/*** Set the Resources object with which this Container is associated.** @param resources The newly associated Resources*/public void setResources(DirContext resources);

Public Methods

 /*** Execute a periodic task, such as reloading, etc. This method will be* invoked inside the classloading context of this container. Unexpected* throwables will be caught and logged.*/public void backgroundProcess();/*** Add a new child Container to those associated with this Container,* if supported.  Prior to adding this Container to the set of children,* the child's <code>setParent()</code> method must be called, with this* Container as an argument.  This method may thrown an* <code>IllegalArgumentException</code> if this Container chooses not* to be attached to the specified Container, in which case it is not added** @param child New child Container to be added** @exception IllegalArgumentException if this exception is thrown by*  the <code>setParent()</code> method of the child Container* @exception IllegalArgumentException if the new child does not have*  a name unique from that of existing children of this Container* @exception IllegalStateException if this Container does not support*  child Containers*/public void addChild(Container child);/*** Add a container event listener to this component.** @param listener The listener to add*/public void addContainerListener(ContainerListener listener);/*** Add a property change listener to this component.** @param listener The listener to add*/public void addPropertyChangeListener(PropertyChangeListener listener);/*** Return the child Container, associated with this Container, with* the specified name (if any); otherwise, return <code>null</code>** @param name Name of the child Container to be retrieved*/public Container findChild(String name);/*** Return the set of children Containers associated with this Container.* If this Container has no children, a zero-length array is returned.*/public Container[] findChildren();/*** Return the set of container listeners associated with this Container.* If this Container has no registered container listeners, a zero-length* array is returned.*/public ContainerListener[] findContainerListeners();/*** Process the specified Request, and generate the corresponding Response,* according to the design of this particular Container.** @param request Request to be processed* @param response Response to be produced** @exception IOException if an input/output error occurred while*  processing* @exception ServletException if a ServletException was thrown*  while processing this request** @deprecated Unused. Will be removed in Tomcat 8.0.x.*/@Deprecatedpublic void invoke(Request request, Response response)throws IOException, ServletException;/*** Remove an existing child Container from association with this parent* Container.** @param child Existing child Container to be removed*/public void removeChild(Container child);/*** Remove a container event listener from this component.** @param listener The listener to remove*/public void removeContainerListener(ContainerListener listener);/*** Remove a property change listener from this component.** @param listener The listener to remove*/public void removePropertyChangeListener(PropertyChangeListener listener);/*** Notify all container event listeners that a particular event has* occurred for this Container.  The default implementation performs* this notification synchronously using the calling thread.** @param type Event type* @param data Event data*/public void fireContainerEvent(String type, Object data);/*** Log a request/response that was destined for this container but has been* handled earlier in the processing chain so that the request/response* still appears in the correct access logs.* @param request       Request (associated with the response) to log* @param response      Response (associated with the request) to log* @param time          Time taken to process the request/response in*                      milliseconds (use 0 if not known)* @param   useDefault  Flag that indicates that the request/response should*                      be logged in the engine's default access log*/public void logAccess(Request request, Response response, long time,boolean useDefault);/*** Identify the AccessLog to use to log a request/response that was destined* for this container but was handled earlier in the processing chain so* that the request/response still appears in the correct access logs.*/public AccessLog getAccessLog();/*** Returns the number of threads available for starting and stopping any* children associated with this container. This allows start/stop calls to* children to be processed in parallel.*/public int getStartStopThreads();/*** Sets the number of threads available for starting and stopping any* children associated with this container. This allows start/stop calls to* children to be processed in parallel.* @param   startStopThreads    The new number of threads to be used*/public void setStartStopThreads(int startStopThreads);

The following examples represent common cases


  • Engine - Representation of the entire Catalina servlet engine, most likely containing one or more subcontainers that are either Host or Context implementations, or other custom groups.
    代表完整的Servlet引擎,是最顶层的容器,在这个容器上调用setParent会抛出异常。一个Engine由多个Host容器组成
  • Host - Representation of a virtual host containing a number of Contexts.
    代表一个虚拟主机,可以运行多个应用,它负责安装和展开这些应用,其子容器为Context
  • Context - Representation of a single ServletContext, which will typically contain one or more Wrappers for the supported servlets.
    :代表ServletContext,管理多个Servlet,理论上只要有Context就可以运行Servlet了,其子容器为Wrapper
  • Wrapper - Representation of an individual servlet definition (which may support multiple servlet instances if the servlet itself implements SingleThreadModel).

代表一个Servlet,是最底部的容器,它没有子容器。它负责管理一个Servlet,包含Servlet的装载、初始化、执行和卸载等。只有Wrapper也是可以运行Servlet
类的继承关系如下:

这里写图片描述

components:Loader,Logger,Manager,Realm,Resources

  • A Container may also be associated with a number of support components
  • that provide functionality which might be shared (by attaching it to a
  • parent Container) or individually customized. The following support
  • components are currently recognized:
    • Loader - Class loader to use for integrating new Java classes
    • for this Container into the JVM in which Catalina is running.
    • Logger - Implementation of the log() method
    • signatures of the ServletContext interface.
    • Manager - Manager for the pool of Sessions associated with
    • this Container.
    • Realm - Read-only interface to a security domain, for
    • authenticating user identities and their corresponding roles.
    • Resources - JNDI directory context enabling access to static
    • resources, enabling custom linkages to existing server components when
    • Catalina is embedded in a larger server.

    *

    这篇关于读懂tomact源码4:Container的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



    http://www.chinasem.cn/article/1101584

    相关文章

    JAVA智听未来一站式有声阅读平台听书系统小程序源码

    智听未来,一站式有声阅读平台听书系统 🌟&nbsp;开篇:遇见未来,从“智听”开始 在这个快节奏的时代,你是否渴望在忙碌的间隙,找到一片属于自己的宁静角落?是否梦想着能随时随地,沉浸在知识的海洋,或是故事的奇幻世界里?今天,就让我带你一起探索“智听未来”——这一站式有声阅读平台听书系统,它正悄悄改变着我们的阅读方式,让未来触手可及! 📚&nbsp;第一站:海量资源,应有尽有 走进“智听

    Java ArrayList扩容机制 (源码解读)

    结论:初始长度为10,若所需长度小于1.5倍原长度,则按照1.5倍扩容。若不够用则按照所需长度扩容。 一. 明确类内部重要变量含义         1:数组默认长度         2:这是一个共享的空数组实例,用于明确创建长度为0时的ArrayList ,比如通过 new ArrayList<>(0),ArrayList 内部的数组 elementData 会指向这个 EMPTY_EL

    如何在Visual Studio中调试.NET源码

    今天偶然在看别人代码时,发现在他的代码里使用了Any判断List<T>是否为空。 我一般的做法是先判断是否为null,再判断Count。 看了一下Count的源码如下: 1 [__DynamicallyInvokable]2 public int Count3 {4 [__DynamicallyInvokable]5 get

    工厂ERP管理系统实现源码(JAVA)

    工厂进销存管理系统是一个集采购管理、仓库管理、生产管理和销售管理于一体的综合解决方案。该系统旨在帮助企业优化流程、提高效率、降低成本,并实时掌握各环节的运营状况。 在采购管理方面,系统能够处理采购订单、供应商管理和采购入库等流程,确保采购过程的透明和高效。仓库管理方面,实现库存的精准管理,包括入库、出库、盘点等操作,确保库存数据的准确性和实时性。 生产管理模块则涵盖了生产计划制定、物料需求计划、

    Spring 源码解读:自定义实现Bean定义的注册与解析

    引言 在Spring框架中,Bean的注册与解析是整个依赖注入流程的核心步骤。通过Bean定义,Spring容器知道如何创建、配置和管理每个Bean实例。本篇文章将通过实现一个简化版的Bean定义注册与解析机制,帮助你理解Spring框架背后的设计逻辑。我们还将对比Spring中的BeanDefinition和BeanDefinitionRegistry,以全面掌握Bean注册和解析的核心原理。

    音视频入门基础:WAV专题(10)——FFmpeg源码中计算WAV音频文件每个packet的pts、dts的实现

    一、引言 从文章《音视频入门基础:WAV专题(6)——通过FFprobe显示WAV音频文件每个数据包的信息》中我们可以知道,通过FFprobe命令可以打印WAV音频文件每个packet(也称为数据包或多媒体包)的信息,这些信息包含该packet的pts、dts: 打印出来的“pts”实际是AVPacket结构体中的成员变量pts,是以AVStream->time_base为单位的显

    kubelet组件的启动流程源码分析

    概述 摘要: 本文将总结kubelet的作用以及原理,在有一定基础认识的前提下,通过阅读kubelet源码,对kubelet组件的启动流程进行分析。 正文 kubelet的作用 这里对kubelet的作用做一个简单总结。 节点管理 节点的注册 节点状态更新 容器管理(pod生命周期管理) 监听apiserver的容器事件 容器的创建、删除(CRI) 容器的网络的创建与删除

    red5-server源码

    red5-server源码:https://github.com/Red5/red5-server

    TL-Tomcat中长连接的底层源码原理实现

    长连接:浏览器告诉tomcat不要将请求关掉。  如果不是长连接,tomcat响应后会告诉浏览器把这个连接关掉。    tomcat中有一个缓冲区  如果发送大批量数据后 又不处理  那么会堆积缓冲区 后面的请求会越来越慢。

    Windows环境利用VS2022编译 libvpx 源码教程

    libvpx libvpx 是一个开源的视频编码库,由 WebM 项目开发和维护,专门用于 VP8 和 VP9 视频编码格式的编解码处理。它支持高质量的视频压缩,广泛应用于视频会议、在线教育、视频直播服务等多种场景中。libvpx 的特点包括跨平台兼容性、硬件加速支持以及灵活的接口设计,使其可以轻松集成到各种应用程序中。 libvpx 的安装和配置过程相对简单,用户可以从官方网站下载源代码