欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

在线统计人数_不同房间的统计人数

程序员文章站 2022-04-04 12:16:58
...

public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain)
throws IOException, ServletException
{
HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse)res;
HttpSession session = request.getSession();
Long lastTime = new Date().getTime();
Long updateTime = (Long)session.getAttribute("updateTime");
String liveState = (String)request.getParameter("action");
int flag = 0;
String enlive = "";
String exlive = "";
String mobile = "";
Long liveroomid = 0l;
Long roomId = 0l;
String servletPath = request.getServletPath();
String islive = (String)session.getAttribute("islive");
if (IeachConstants.IEACE_ONLINE_PEOPLES_SERVLETPATH.indexOf(servletPath) != -1)
{
if (null != islive && !"".equals(islive))
{
flag = Integer.parseInt(islive);
}
if ("goLiveRoom".equals(liveState))
{
UserInfo userInfo = (UserInfo)session.getAttribute("userInfo");
if (flag == 0)
{
if (null != userInfo)
{

roomId = Parmfiltrate.toLong(request, "roomid");
updateTime = new Date().getTime();
session.setAttribute("updateTime", updateTime);
session.setAttribute("islive", "1");

OnlineSum.entryLive(session.getId(),
roomId,
userInfo.getMobile());

}

}

}
else
{

if (flag == 1)
{

OnlineSum.exitLive(session.getId());

session.setAttribute("islive", 0);

}

}
}
if (null != updateTime && lastTime >= updateTime
|| enlive.length() > 3000)
{
int sum =
OnlineSum.getenSessionUser().size()
+ OnlineSum.getexSessionUser().size();
if (sum >= 1)
{
for (Map.Entry<String, Long> entry : OnlineSum.getenSessionUser()
.entrySet())
{
liveroomid =
((Long)OnlineSum.getenSessionUser()
.get((String)entry.getKey()));
if (!OnlineSum.getexSessionUser()
.containsKey(entry.getKey()))
{
mobile =
OnlineSum.getSessionUser()
.get((String)entry.getKey());
enlive +=
liveroomid + ":" + (String)entry.getKey() + ":"
+ mobile + ",";
}

}
for (Map.Entry<String, Long> exit : OnlineSum.getexSessionUser()
.entrySet())
{
if (!OnlineSum.getenSessionUser()
.containsKey(exit.getKey()))
{
exlive += "'" + (String)exit.getKey() + "'" + ",";
}

}
if (exlive.length() > 0)
{
exlive = exlive.substring(0, exlive.length() - 1);
}
if (enlive.length() > 0)
{
enlive = enlive.substring(0, enlive.length() - 1);
}

}

liveOnlineService.getOnlineProcedure(enlive, exlive);

// 初始化用户session
OnlineSum.init();
session.setAttribute("updateTime",
new Date().getTime() + 5 * 60 * 1000);

}
chain.doFilter(request, response);

}
相关标签: Mobile