Comet4J的类是自动监听 服务器启动就自动启动, 并不是客户端浏览器去请求后进的这个类 能不能在这种情况下取得用户登录后的用户名
package com.shadow.extras.comet4j;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.comet4j.core.CometContext;
import org.comet4j.core.CometEngine;
import org.hibernate.Query;
import org.hibernate.Session;
import cn.fuego.misp.web.filter.AuthenticationFilter;
import com.shadow.extras.comet4j.dao.Cometdao;
import com.shadow.extras.comet4j.dao.HibernateSessionFactory;
import com.shadow.extras.comet4j.pojo.ExpertMessage;
public class TestComet extends AuthenticationFilter implements ServletContextListener {
private static final String CHANNEL = "test";
public int szie_=1;
//public static Map map = new HashMap();
public void contextInitialized(ServletContextEvent arg0) {
CometContext cc = CometContext.getInstance();
cc.registChannel(CHANNEL);// 注册应用的channel
Thread helloAppModule = new Thread(new HelloAppModule(),
"Sender App Module");
helloAppModule.setDaemon(true);
helloAppModule.start();
}
class HelloAppModule implements Runnable {
public void run() {
while (true) {
try {
Thread.sleep(1000);
} catch (Exception ex) {
ex.printStackTrace();
}
CometEngine engine = CometContext.getInstance().getEngine();
//long l = getFreeMemory();
/* List<ExpertMessage> list=null;
list=getFreeMemory();
//szie_=list.size(); //把查出来的list长度 赋给定义的变量szie_
if(list.size()>szie_){ //如果list.size()比szie_大 就把list.size大的给szie_ 否则还是szie_大
szie_=list.size();
System.out.println("加了!!!");
}
System.out.println(szie_);
System.out.println(list.size());*/
}
}
}
public void contextDestroyed(ServletContextEvent arg0) {
}
public List<ExpertMessage> getFreeMemory() {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from ExpertMessage user");
//query.setString(0,user);
List<ExpertMessage> list =query.list();
session.close();
return list;
}
}
这个取不了