* @param name 会议室ID
* @return
*/
public static boolean close(String name)
{
ChatService chatRoom=ChatService.get(name);
if(chatRoom!=null)
{
chatRoom.stop();
service.remove(name);
}
return true;
}
/**
* 获得一个会议室信息
* @param name 会议室ID
* @return
*/
public static ChatService get(String name)
{
if(service.containsKey(name))return (ChatService)service.get(name);
else return null;
}
public void run() {
// TODO Auto-generated method stub
//this.thread=Thread.currentThread();
while(!isStop)
{
//System.out.println("开始监控一个会议室!"+this.title);
this.flash();
try{
Thread.sleep(5000);
}
catch(Exception e)
{
e.printStackTrace();
}
}
//System.out.println("结束!");
}
public void stop()
{
this.flashAll();
isStop=true;
}
//会议室中有人发言
public boolean talk(Chat chat)
{
boolean ret=false;
if(canTalk(chat.getSender()))
{
this.msgs.add(chat);
ret=true;
}
return ret;
}
public boolean exit(ChatUser user)
{
talk(geneSystemMsg(user.getUserName()+"退出了会议室!"));
return this.users.remove(user);
}
}
//刷新信息,保存会议信息
public void flash()
{
flashChatMsg();
flashChatUser();
}
}
2、MVC处理部分的Action代码
在EasyJF的会议系统中,由于使用EasyJWeb作为MVC框架,因此处理Ajax比较简单,下面是会议室系统的核心Action主要代码。
package com.easyjf.chat.action;
public class ChatAction extends AbstractCmdAction {
private ChatService chatRoom;
public Object doBefore(WebForm form, Module module) {
// TODO Auto-generated method stub
if(chatRoom==null)chatRoom=ChatService.get((String)form.get("cid"));
return super.doBefore(form, module);
}
public Page doInit(WebForm form, Module module) {
// TODO Auto-generated method stub
return doMain(form,module);
}
//用户登录进入会议室
public Page doMain(WebForm form, Module module) {
if(chatRoom!=null){
ChatUser user=getChatUser();
if(!chatRoom.join(user))form.addResult("msg","不能加入房间,可能是权限不够!");
form.addResult("chatRoom",chatRoom);
form.addResult("user",user);
}
else
{
form.addResult("msg","会议未启动或者会议室不存在!");
}
return module.findPage("main");
}
//处理用户发言信息
public Page doSend(WebForm form, Module module) {
if(chatRoom==null)return new Page("err","/err.html","thml");//返回会议室不存在的错误
Chat chat=(Chat)form.toPo(Chat.class);
chat.setCid(chatRoom.geneId());
chatRoom.talk(chat);
return doRecive(form,module);
}
//用户接收发言信息
public Page doRecive(WebForm form, Module module) {
if(chatRoom==null)return new Page("err","/err.html","thml");//返回会议室不存在的错误
String lastReadId=CommUtil.null2String(form.get("lastReadId"));
//System.out.println(lastReadId);
form.addResult("list", chatRoom.getNewestMsg(getChatUser(),lastReadId));
return module.findPage("msgList");
}
//用户刷新会议状态信息
public Page doLoadConfig(WebForm form, Module module) {
if(chatRoom==null)return new Page("err","/err.html","thml");//返回会议室不存在的错误
form.addResult("userList", chatRoom.getUsers());
form.addResult("talkerList", chatRoom.getTalkers());
return module.findPage("config");
}
//用户退出
public Page doExit(WebForm form, Module module) {
if(chatRoom==null)return new Page("err","/err.html","t