application实时统计功能的实现。。。求指教。。
来源:互联网 发布:anywhere软件源 编辑:程序博客网 时间:2024/06/05 12:52
java代码:我这里已我项目中的id作为application的key值ServletContext application = request.getSession().getServletContext();//直播实时人数统计功能HttpSession session =request.getSession();String sessionid=session.getId();//如果application中没有点播表id时新增mapif(application.getAttribute(trialDto.getTtrial().getId())==null){List<Map<String, Long>> sessionlist = new ArrayList<Map<String, Long>>();Map<String, Long> map = new HashMap<String, Long>();map.put(sessionid, new Date().getTime());sessionlist.add(map);application.setAttribute(trialDto.getTtrial().getId(), sessionlist);}else{//有id时判断list中map 的key是否包含当前的sessionidList<Map<String, Long>> onList =(List<Map<String, Long>>) application.getAttribute(trialDto.getTtrial().getId());Set<String> setkeyAll = new TreeSet<String>();for(int j=0;j<onList.size();j++){Set<String> setKey = onList.get(j).keySet();setkeyAll.addAll(setKey);}if(!setkeyAll.contains(sessionid)){//mLog1.info("不包含增加");Map<String, Long> map = new HashMap<String, Long>();map.put(sessionid, new Date().getTime());onList.add(map);}//定义过期时间,设定半小时为到期时间 这个循环其实key值只有一个,为了规范这么写for(int i=0; i<onList.size();i++){Set<String> setKey = onList.get(i).keySet();for(String key:setKey){//if(onList.get(i).get(key)<(new Date().getTime()-2000)){if(onList.get(i).get(key)<(new Date().getTime()-1800000)){onList.remove(i);i--;}}}application.setAttribute(trialDto.getTtrial().getId(), onList);}List<Map<String, Long>> onListCount =(List<Map<String, Long>>) application.getAttribute(trialDto.getTtrial().getId());//实时观看点播数int onlineCount=onListCount.size();将onlineCount传到前台使用就可以了。关闭页面和浏览器直播数减1,java代码:public String clearOnlineCount(){String restid="";if(contentsearch!=null){restid=contentsearch.getTcontent().getId();//mLog1.info("点播删除");}else{restid=trialDto.getTtrial().getId();//mLog1.info("直播删除");}HttpServletRequest request = ServletActionContext.getRequest();//点播实时人数统计功能HttpSession session =request.getSession();String sessionid=session.getId();ServletContext application = request.getSession().getServletContext();List<Map<String, Long>> onList =(List<Map<String, Long>>) application.getAttribute(restid);for(int i=0; i<onList.size();i++){Set<String> setKey = onList.get(i).keySet();for(String key:setKey){if(key.equals(sessionid)){onList.remove(i);i--;}}}application.setAttribute(restid, onList);mLog1.info("删除成功 "+sessionid+" 本视屏观看人数 "+onList.size());return SUCCESS;}
js关闭访问action代码:<script type="text/javascript"> window.onbeforeunload = onbeforeunload_handler; window.onunload = onunload_handler; function onbeforeunload_handler(){ var tcontent='<ww:property value="#request['searchVodBySearch'][0].tcontent.id" />'; xmlHttp=GetXmlHttpObject();// iscbrshow=iscbrshow;if (xmlHttp==null){alert ("您的浏览器不支持AJAX!");return;}xmlHttp.onreadystatechange=function(){if(xmlHttp.readyState==4 && xmlHttp.status==200){ // alert("删除成功"); }};xmlHttp.open("post","clearOnlineCount.action",true);xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");xmlHttp.send("contentsearch.tcontent.id="+tcontent); } </script>function GetXmlHttpObject(){ var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp;}
这个不知道访问量很大会怎么样。。。求指教直播平台的观看人数是怎么统计的。。。。
阅读全文
1 0
- application实时统计功能的实现。。。求指教。。
- 分享自己写的 火车票实时查询器-源码奉上,求指教
- 使用ASP.NET的Application对象实现在线人数统计的功能
- 算式计算器C++实现代码(顺序栈结构 增加了一些功能 求指教)
- 【Jsp】利用Application对象实现访问人数统计功能
- js实现实时日历面板的个人创作(初级新人小作,请大师指教)
- 自己编写的数据仓库梳理工具,不知道还需要什么功能,求指教
- 傅里叶变换方法求图像卷积-OpenCV实现 遇到的问题!!!求指教!!!!!!
- 求指教
- 求指教!
- 求指教
- 求指教
- 求指教
- 求指教
- 求指教,
- 求指教!!!
- 求指教
- 简单的实时提示功能的实现
- 文章标题
- Comparable和Comparator的区别
- 进程组、作业、会话
- 配置SSH无密码登陆
- Android解决ScrollView中布局不能撑满全屏的问题(记录)
- application实时统计功能的实现。。。求指教。。
- Spring中集成Hibernate
- Observer代替广播实现注册,通知,更新数据
- 如何调试分析Android中发生的tombstone
- Mysql日志解析
- GNU C
- 【C++】学习笔记五十二——友元
- 贝叶斯决策 实例
- 主题三 编译过程介绍----20.#和##运算符的使用分析