tomcat的事件监听
//事件涉及的三个组件:事件源、事件对象、事件监听器
//一个总的事件监听器接口,所有不同分类的事件监听器都继承这个接口
public interface EventListener {
}
//例如 ServletContextListener 这个ServletContext监听器 他有两个方法,一个是初始化方法,另一个是销毁的方法。在web.xml中配置了listener,那么容器在启动时就会扫描web.xml的listener的配置,自动调用contextInitialized 方法,在容器重启时,他会先调用contextDestroyed销毁的方法,在调用contextInitialized 创建的方法。在容器关闭时,会调用contextDestroyed方法。但我刚启动完容器,立刻关闭,是不会调用到contextDestroyed方法的。我想他这里应该有设置时间的吧。
public interface ServletContextListener extends EventListener {
/**
** Notification that the web application initialization
** process is starting.
** All ServletContextListeners are notified of context
** initialization before any filter or servlet in the web
** application is initialized.
*/
public void contextInitialized ( ServletContextEvent sce ); //接受的参数是ServletContextEvent 事件源
/** ** Notification that the servlet context is about to be shut down. ** All servlets and filters have been destroy()ed before any ** ServletContextListeners are notified of context ** destruction. */
public void contextDestroyed ( ServletContextEvent sce ); }
//每一个事件对象都有一个总的事件对象类,下面这个就是了。
public class EventObject implements java.io.Serializable {
private static final long serialVersionUID = 5516075349620653480L;
/**
* The object on which the Event initially occurred.
*/
protected transient Object source;
/**
* Constructs a prototypical Event.
*
* @param source The object on which the Event initially occurred.
* @exception IllegalArgumentException if source is null.
*/
public EventObject(Object source) {
if (source == null)
throw new IllegalArgumentException("null source");
//在这里封装一个事件源
this.source = source;
}
/**
* The object on which the Event initially occurred.
*
* @return The object on which the Event initially occurred.
*/
public Object getSource() {
return source; //得到事件源
}
/**
* Returns a String representation of this EventObject.
*
* @return A a String representation of this EventObject.
*/
public String toString() {
return getClass().getName() + "[source=" + source + "]";
}
}
public class ServletContextEvent extends java.util.EventObject {
/** Construct a ServletContextEvent from the given context.
*
* @param source - the ServletContext that is sending the event.
*/
public ServletContextEvent(ServletContext source) {
super(source);
}
/**
* Return the ServletContext that changed.
*
* @return the ServletContext that sent the event.
*/
public ServletContext getServletContext () {
return (ServletContext) super.getSource();//返回一个真正的事件源
}
}
这就是tomcat的事件监听设计模型。
tomcat的事件监听的更多相关文章
- SpringBoot入门之事件监听
spring boot在启动过程中增加事件监听机制,为用户功能拓展提供极大的便利,sptingboot支持的事件类型有以下五种: ApplicationStartingEvent Applicatio ...
- Java设计模式——观察者模式(事件监听)
最近在看Tomcat和Spring的源码,在启动的时候注册了各种Listener,事件触发的时候就执行,这里就用到了设计模式中的观察者模式. 引-GUI中的事件监听 想想以前在学Java的GUI编程的 ...
- 7_3.springboot2.x启动配置原理_3.事件监听机制
事件监听机制配置在META-INF/spring.factories ApplicationContextInitializer SpringApplicationRunListenerioc容器中的 ...
- SpringBoot Application事件监听
SpringBoot Application共支持6种事件监听,按顺序分别是: ApplicationStartingEvent:在Spring最开始启动的时候触发 ApplicationEnviro ...
- springBoot高级:自动配置分析,事件监听,启动流程分析,监控,部署
知识点梳理 课堂讲义 02-SpringBoot自动配置-@Conditional使用 Condition是Spring4.0后引入的条件化配置接口,通过实现Condition接口可以完成有条件的加载 ...
- Java中用得比较顺手的事件监听
第一次听说监听是三年前,做一个webGIS的项目,当时对Listener的印象就是个"监视器",监视着界面的一举一动,一有动静就触发对应的响应. 一.概述 通过对界面的某一或某些操 ...
- 4.JAVA之GUI编程事件监听机制
事件监听机制的特点: 1.事件源 2.事件 3.监听器 4.事件处理 事件源:就是awt包或者swing包中的那些图形用户界面组件.(如:按钮) 事件:每一个事件源都有自己特点有的对应事件和共性事件. ...
- Node.js 教程 05 - EventEmitter(事件监听/发射器 )
目录: 前言 Node.js事件驱动介绍 Node.js事件 注册并发射自定义Node.js事件 EventEmitter介绍 EventEmitter常用的API error事件 继承EventEm ...
- .NET事件监听机制的局限与扩展
.NET中把“事件”看作一个基本的编程概念,并提供了非常优美的语法支持,对比如下C#和Java代码可以看出两种语言设计思想之间的差异. // C#someButton.Click += OnSomeB ...
随机推荐
- mysql循环插入数据库中数据。
DELIMITER ;; CREATE PROCEDURE test_insert () BEGIN DECLARE i INT DEFAULT 1; WHILE i<100 DO insert ...
- Navicat连接不上MySQL
[root@localhost init.d]# pwd /etc/init.d [root@localhost init.d]# mysql -u root -p Enter password: E ...
- 利用java实现抽奖转盘(着重安全控制)
本文是针对jquery 实现抽奖转盘作者的一个补充(主要用java去实现转盘结果生成及存储,解决jquery 做法 非法用户采用模拟器实现改变转盘值的风险性),针对jQuery的具体实现,请看案例:h ...
- Unity人工智能学习—确定性AI算法之追踪算法一
转自http://blog.csdn.net/zhangxiao13627093203/article/details/47451063 尽管随机运动可能完全不可预知,它还是相当无趣的,因为它完全是以 ...
- VB ListBox 添加横向滚动条
Private Declare Function SendMessage Lib "user32 " Alias "SendMessageA" (ByVal h ...
- 一个view相对于屏幕或者另外一个view 的坐标
如果想知道一个view相对于屏幕或者另外一个view 的坐标,那么可以通过如下的方法得到: UIWindow * window=[[[UIApplication sharedApplication] ...
- xcode常见错误
------------------------------------------错误列表---------------------------------------------- 1.Ter ...
- oc UIAlertController封装
#define SHOWALERT(MESSAGE) \ UIAlertController *alertController = [UIAlertController alertController ...
- Codeforces Round #346 (Div. 2) A Round-House
A. Round House 题目链接http://codeforces.com/contest/659/problem/A Description Vasya lives in a round bu ...
- ogg 初始化
192.168.27.33test11ghdb11gtrandata: 同步delete,update 使用config 文件:同步表使用进程根据SCN号和RBA和主键同步##目的:数据定时同步,从源 ...