123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package com.system.push;
- import java.util.Collection;
- import java.util.Iterator;
- import org.directwebremoting.Browser;
- import org.directwebremoting.ScriptBuffer;
- import org.directwebremoting.ScriptSession;
- /**
- * 消息推送执行类
- * @author zhuanghuiliang
- * @date 2015-10-13
- */
- public class Task implements Runnable{
- //推送的信息
- private String msg = "";
- //调用页面的函数名称
- private String scriptStr = "sendMessage";
- //构造函数,为msg赋值
- public Task(String msg) {
- this.msg = msg;
- }
- //构造函数,为msg和scriptStr赋值
- public Task(String msg, String scriptStr) {
- this.msg = msg;
- this.scriptStr = scriptStr;
- }
- @SuppressWarnings({ "rawtypes" })
- public void run() {
- Collection sessions = Browser.getTargetSessions();
- ScriptSession scriptSession;
- for (Iterator i = sessions.iterator(); i.hasNext();) {
- scriptSession = (ScriptSession) i.next();
- // ScriptBuffer scriptbuffer = new ScriptBuffer("sendMessage('" +
- // msg + "');");
- ScriptBuffer scriptbuffer = new ScriptBuffer();
- scriptbuffer.appendCall(scriptStr, msg);
- scriptSession.addScript(scriptbuffer);
- }
- }
- }
|