package application.comet;
import java.util.Collection;
import javax.servlet.ServletContext;
import org.directwebremoting.Browser;
import org.directwebremoting.ScriptBuffer;
import org.directwebremoting.ScriptSession;
import org.directwebremoting.ScriptSessionFilter;
import org.directwebremoting.ServerContext;
import org.directwebremoting.ServerContextFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.web.context.ServletContextAware;
public class NotifyClient implements ApplicationListener, ServletContextAware {
private ServletContext servletContext = null;
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
}
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof InfoEvent) {
final PerformInfo info = (PerformInfo) event.getSource();
send(info.getReceiver(), info.getMsg());
}
}
/**
* 推给指定用户
* @param userid
* @param request
* @return
*/
private void send(final String receiverid, final String msg) {
Browser.withAllSessionsFiltered(new ScriptSessionFilter() {
public boolean match(ScriptSession session) {
if (session.getAttribute("userId") == null)
return false;
else
return (session.getAttribute("userId")).equals(receiverid);
}
}, new Runnable() {
public void run() {
Collection<ScriptSession> colls = Browser.getTargetSessions();
for (ScriptSession scriptSession : colls) {
scriptSession.addScript(initFunctionCall(
"dwr.util.setValue", "info", msg));
}
}
});
}
private ScriptBuffer initFunctionCall(String funcName, Object... params) {
ScriptBuffer script = new ScriptBuffer();
script.appendScript(funcName).appendScript("(");
for (int i = 0; i < params.length; ++i) {
if (i != 0) {
script.appendScript(",");
}
script.appendData(params[i]);
}
script.appendScript(");");
return script;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
dwr-comet.rar (35个子文件)
dwr-comet
.project 1KB
.settings
.jsdtscope 500B
org.eclipse.core.resources.prefs 133B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
.mymetadata 300B
WebRoot
login.jsp 1KB
WEB-INF
dwr.xml 314B
web.xml 1KB
applicationContext.xml 309B
lib
log4j-1.2.15.jar 383KB
dwr.jar 1.08MB
commons-logging-1.1.1.jar 59KB
spring.jar 2.78MB
classes
log4j.properties 881B
application
comet
NotifyClient.class 2KB
InitScriptSession.class 2KB
InitScriptSession$1.class 2KB
PerformInfo.class 1KB
NotifyClient$1.class 1KB
NotifyClient$2.class 2KB
DwrService.class 2KB
InfoEvent.class 379B
index.jsp 2KB
comet_act.jsp 654B
META-INF
MANIFEST.MF 39B
comet.jsp 1KB
action.jsp 584B
.myeclipse
src
log4j.properties 881B
application
comet
PerformInfo.java 905B
InfoEvent.java 198B
DwrService.java 1KB
NotifyClient.java 2KB
InitScriptSession.java 2KB
.classpath 845B
共 35 条
- 1
soundfly
- 粉丝: 27
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页