a6d367a1b0822ecd1eec1957342336125e518861.svn-base 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package com.system.push;
  2. import java.util.Collection;
  3. import java.util.Iterator;
  4. import org.directwebremoting.Browser;
  5. import org.directwebremoting.ScriptBuffer;
  6. import org.directwebremoting.ScriptSession;
  7. /**
  8. * 消息推送执行类
  9. * @author zhuanghuiliang
  10. * @date 2015-10-13
  11. */
  12. public class Task implements Runnable{
  13. //推送的信息
  14. private String msg = "";
  15. //调用页面的函数名称
  16. private String scriptStr = "sendMessage";
  17. //构造函数,为msg赋值
  18. public Task(String msg) {
  19. this.msg = msg;
  20. }
  21. //构造函数,为msg和scriptStr赋值
  22. public Task(String msg, String scriptStr) {
  23. this.msg = msg;
  24. this.scriptStr = scriptStr;
  25. }
  26. @SuppressWarnings({ "rawtypes" })
  27. public void run() {
  28. Collection sessions = Browser.getTargetSessions();
  29. ScriptSession scriptSession;
  30. for (Iterator i = sessions.iterator(); i.hasNext();) {
  31. scriptSession = (ScriptSession) i.next();
  32. // ScriptBuffer scriptbuffer = new ScriptBuffer("sendMessage('" +
  33. // msg + "');");
  34. ScriptBuffer scriptbuffer = new ScriptBuffer();
  35. scriptbuffer.appendCall(scriptStr, msg);
  36. scriptSession.addScript(scriptbuffer);
  37. }
  38. }
  39. }