Implement an online conference room system with AJAX+J2EE

Source: Internet
Author: User
Tags date format final functions socket string thread time interval
ajax|j2ee| Online Conference

This year everyone in the hype Web2.0, one of the technology Ajax is also followed by fire, so I wrote a paper called "Cheat Ajax" article, simply analyze the essence of AJAX technology. Although I do not like to follow the follow, but there are some areas of Ajax is more useful.

Some time ago did a EASYJF open source team of online conferencing system, used AJAX technology, the following design ideas issued to share with you.

the function of system realization

This conference room system is mainly used for members of the EASYJF open source team online meeting, the conference system simulates the traditional meeting form, can open a number of different themes at the same time meeting room, each meeting room needs to provide access control function, meeting can designate the meeting speaking mode (divided into lines, free speech two), The system can automatically record the speech information of each meeting room, which can be consulted by the participants for a long time.
The conferencing system's users support the visitor account to attend the meeting, but also provides the interface with other user's system, for instance EASYJF website Open Source Forum system.
The conference system temporarily uses text chat and provides voice and video interfaces.

second, the technical system

The server side uses the Java language and MVC uses the Easyjweb framework;
The client uses AJAX technology to interact with server-side data;
Conference history Information storage format uses text format to facilitate system installation and operation, but also easy to manage.

third, the conference room server Side Design

The conference Room server is the core part of the whole conference system, and the quality of the whole system is affected by the server-side program design.
First, abstract analysis is based on the functions to be implemented in the Conference room. A conference room object that should include the subject of the meeting, a brief introduction to the meeting, the number of participants, announcements, conference room types, access settings, room password, current attendees, current speakers, people waiting in line to speak, and other parameter information. We encapsulated him in a Java object. As shown in the following chatroom code:
public class ChatRoom{
private String cid;//主键
private String title;//聊天室主题
private String intro;//聊天室简介
private String announce;//聊天室公告
private String owner;//聊天室创建人
private Integer maxUser;//最大在线人数
private Integer intervals;//最大刷新时间间隔
private String vrtype;//访问权限
private String vrvalue;//访问值
private Integer status;//聊天室状态
private Date inputTime;

You need a class that manages the conference room, a meeting-related operation (such as starting a meeting, closing a meeting), and so on, find him directly. The class should also have automatic timing to detect the user online (prevent users from accidentally quitting), the memory of the conference history to save the information to a text file medium function. Here you can consider using a Chatservice class to provide these features:
public class ChatService implements Runnable {
private static final Map service=new HashMap();//会议室服务,系统中的当前会议室存放到该表集合中
private static final int maxServices=10;//可以同时开的最大会议室数
private static final SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
private final List msgs;//聊天信息Chat
private final List users;//在线用户,ChatUser
private final List talkers;//排队发言人数Talker
private final List manager;//会议室管理员
private Talker currentTalker;//当前发言人
public ChatService()
this.msgs=new ArrayList();
this.users=new ArrayList();
this.talkers=new ArrayList();
this.manager=new ArrayList();

Conference statement information also needs to be encapsulated into a class that represents the speaker, receiver, content, speaking time, type, and so on, roughly the following chat class:
public class Chat {
private String cid;
private String sender;
private String reciver;
private String content;
private Date vdate;
private Integer types;
private Integer status;

There is also information about the person who attended the meeting, including the name of the participant, IP address, status, and so on, as shown in the following Chatuser class:
public class ChatUser {
private String ip;
private String port;
private String userName;
private Date lastAccessTime;
private Integer status;

A talker class representing the current spokesperson is also required, indicating the current speaker, the starting time of the speech, the expected end time of the statement, and so on.
In the server side of the design, the conference room information servers should be able to run in a multi-threaded manner, that is, start a meeting to open a new thread, each meeting thread to maintain their own conference status, such as participants, speakers, save the history of the session information and empty the memory of the data and so on.

Four, the client design

The meeting room client consists of two parts, one part is the management interface of the conference room, the main package conference room "Tim check" and "Start" or "Close" the conference service operation. This part of our direct use of easyjweb tools in the Add-and-check business engine abstractcrudaction can be quickly implemented. The interface is also relatively simple, directly using the Easyjweb Tools code generation tool engine to generate it. The client in the conference room management is a traditional Java web technology, so there is nothing to consider.
The second part of the client is also the main part of the meeting system, which has two main interfaces, the first page is the selection page of the meeting room entry. It also lists the conference rooms that have been started, and the user chooses a conference room to enter, which is also the use of traditional Java Web technology. The second page is the main interface to the meeting room, which is the main interface of the entire conference system, and all the operations involved in the meeting run here. This interface requires constant interaction with the server side of the data transmission, including the user's speech, other people to the user's speech, the status of the conference room and so on. Some transmission information requires an immediate response (such as a user speaking), and some information can be set to a timed response (e.g. conference room status).
There are two main ways to interact with server-side data in a Java Web program, one is to refresh the page directly, and the other is to use the socket to communicate directly with the Web server port. Because of the relatively complex socket programming, we choose the first way to directly refresh the page, this way can be divided into several, including the traditional form submission, traditional automatic refresh Web Access data and the use of ActiveXObject objects (such as XMLHTTP) directly interacting with the server data, That's the Ajax way. Because the use of Ajax means that users do not feel the page is refreshed, better than manual or automatic refresh of the page, so we decided to choose the Ajax way to implement the client and server side of the data interaction.
When users speak, use the XMLHTTP object to post data directly to the server. In order to be able to receive other people's speech information, the need to constantly read from the server side of the data, therefore, the need to start a timer at the client, every time the automatic use of XMLHTTP object to the server to download the speaker information, and display to the conference Room information main interface. In addition, the number of attendees, the current speaker in the Conference room, the Bulletin of the Conference room, and so on, can also be updated by starting a timer from the client and interacting with the server through the XMLHTTP object.
There are also a number of operations, lock conference rooms, kicking people, the designated speaker time, to the conference room password and other functions, but also through the XMLHTTP way with the server Transfer command.

Five, the core code description

1, server-side core code
In the EASYJF open Source team meeting system, because is EASYJF official website forum system, the backstage management and so on is integrates together. The server Chatservice and chatroom are merged into a class to achieve conference Room Management and conference service functions. Part of the main code for the Chatservice class is as follows:
public class Chatservice implements Runnable {
private static final Map service=new HashMap ()//Conference Room service, the current meeting room in the system is stored in the table collection
Maximum number of meeting rooms that private static final int maxservices=10;//can open at the same time
private static final SimpleDateFormat df=new SimpleDateFormat ("Yyyy-mm-dd");
Private final List msgs;//chat information Chat
Private final List users;//online user, Chatuser
Private final List talkers;//number of speakers in line talker
Private final List manager;//Conference Room Manager
Private Talker currenttalker;//Current spokesperson
Private String cid;//Room ID
Private String title;//Conference Room topics
Private String intro;//Conference Room Introduction
Private String owner;//Meeting room creator
private int maxuser;//Max online number
private int interval;//Max refresh time interval
Private String vrtype;//access rights
Private String vrvalue;//Access value
Private String announce;
Private String password;//Room access password
private int status;//Conference Room status
Private String FilePath;
private thread thread;
Private Boolean isstop=false;
Public Chatservice ()
This.msgs=new ArrayList ();
This.users=new ArrayList ();
This.talkers=new ArrayList ();
This.manager=new ArrayList ();
this.maxuser=1000;//Max 1000 people at the same time
THIS.INTERVAL=1000*60*5;//5 minutes before the information
* Stop All Conference rooms
public static void Clear ()
if (!service.isempty ())
Iterator It=service.values (). iterator ();
while (It.hasnext ())
Chatservice chat= (Chatservice) ();
Chat.stop ();
Service.clear ();
* Create a conference Room
* @param name Conference Room ID
* @return
public static Chatservice Create (String name)
Chatservice Ret=null;
if (Service.containskey (name))
Chatservice s= (Chatservice) service.get (name);
S.stop ();
Service.remove (name);
if (Service.size () <>
Ret=new Chatservice ();
Service.put (Name,ret);
return ret;

[1] [2] Next page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.