jkas 事件监听

1、配置

[LISTENER]

;是否开启监听器

listener_enable=1

;监听器指定调用类设置,该类必须继承Listener

listener_class=test.z.listener.Test

 

2、监听类及方法编写

监听类必须继承于Listener,重写以下监听方法分别监听不同事件

 public void sessionCreate(HttpSessionEvent hse){};//session创建,用户首次访问
 public void sessionAdd(HttpSessionBindingEvent hsbe){};//session添加
 public void sessionUpdate(HttpSessionBindingEvent hsbe){};//session更新
 public void sessionRemove(HttpSessionBindingEvent hsbe){};//session删除
 public void sessionDestroy(HttpSessionEvent hse){};//session销毁

 public void requestInit(ServletRequestEvent sre){}; //request初始
 public void requestAdd(ServletRequestAttributeEvent srae){};//request添加
 public void requestUpdate(ServletRequestAttributeEvent srae){};//request更新
 public void requestRemove(ServletRequestAttributeEvent srae){};//request删除
 public void requestDestroy(ServletRequestEvent sre){};//request销毁

 

 public void applicationAdd(ServletContextAttributeEvent scae){};//application变量添加
 public void applicationUpdate(ServletContextAttributeEvent scae){};//application变量更新
 public void applicationRemove(ServletContextAttributeEvent scae){};//application删除

 

public void JkasInit(Config conf)//框架初始化,仅启动时执行,不受配置监听开关影响

public void JkasDestroy(Config conf)//框架销毁时执行,不受配置监听开关影响

 

 public void zkconnected(){}; //zookeeper连接
 public void zkdisconnected(){};//zookeeper断开连接
 public void zkcreated(String node,byte[] value){};//zookeeper创建节点
 public void zkupdated(String node,byte[] value){};//zookeeper修改节点
 public void zkdeleted(String node){};//zookeeper删除节点

 

案例:监听session添加事件及session删除事件

 

package test.z.listener;
import org.jkas.core.Listener;
import javax.servlet.http.HttpSessionBindingEvent;
public class Test extends Listener
{  public void sessionAdd(HttpSessionBindingEvent hsbe)
 {log("info","session add");
 }

 public void sessionRemove(HttpSessionBindingEvent hsbe)
 {log("info","session remove");
 }
}