- continue refactoring users

This commit is contained in:
Richard Alam 2013-06-10 22:12:34 +00:00
parent 2cddb430b3
commit f285dc2fab
11 changed files with 98 additions and 210 deletions

View File

@ -148,7 +148,7 @@ public class BigBlueButtonApplication extends MultiThreadedApplicationAdapter {
String debugInfo = "internalUserID=" + internalUserID + ",username=" + username + ",role=" + role + "," +
",voiceConf=" + voiceBridge + ",room=" + room + ",externalUserid=" + externalUserID;
log.debug("User [{}] connected to room [{}]", debugInfo, room);
participantsApplication.createRoom(room);
participantsApplication.createRoom(room, record);
connInvokerService.addConnection(bbbSession.getInternalUserID(), connection);

View File

@ -22,8 +22,7 @@ package org.bigbluebutton.conference;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.bigbluebutton.conference.meeting.messaging.red5.ClientMessage;
import org.bigbluebutton.conference.meeting.messaging.red5.BroadcastClientMessage;
import org.bigbluebutton.conference.meeting.messaging.red5.ConnectionInvokerService;
import org.red5.server.api.Red5;
@ -39,7 +38,7 @@ public class BigBlueButtonService {
messageToSend.put(key, params.get(key));
}
ClientMessage m = new ClientMessage(ClientMessage.BROADCAST, getMeetingId(), (String) params.get("messageID"), messageToSend);
BroadcastClientMessage m = new BroadcastClientMessage(getMeetingId(), (String) params.get("messageID"), messageToSend);
connInvokerService.sendMessage(m);
}

View File

@ -22,6 +22,7 @@ package org.bigbluebutton.conference;
import org.slf4j.Logger;
import org.bigbluebutton.conference.service.participants.messaging.redis.UsersMessagePublisher;
import org.bigbluebutton.conference.service.participants.recorder.redis.UsersEventRecorder;
import org.bigbluebutton.conference.service.participants.red5.UsersClientMessageSender;
import org.red5.logging.Red5LoggerFactory;
import java.util.concurrent.ConcurrentHashMap;
import java.util.ArrayList;
@ -32,55 +33,57 @@ import java.util.Map;
public class Meeting {
private static Logger log = Red5LoggerFactory.getLogger( Meeting.class, "bigbluebutton" );
ArrayList<String> currentPresenter = null;
private String name;
private String meetingID;
private Boolean recorded = false;
private Map <String, User> users;
private UsersEventRecorder usersEventRecorder;
private UsersMessagePublisher usersMessagePublisher;
public void setUsersEventRecorder(UsersEventRecorder recorder) {
usersEventRecorder = recorder;
}
public void setUsersMessagePublisher(UsersMessagePublisher usersMessagePublisher) {
this.usersMessagePublisher = usersMessagePublisher;
}
public Meeting(UsersEventRecorder recorder, UsersMessagePublisher usersMessagePublisher) {
private UsersClientMessageSender usersClientMessageSender;
public Meeting(String meetingID, Boolean recorded, UsersEventRecorder recorder, UsersMessagePublisher usersMessagePublisher, UsersClientMessageSender usersClientMessageSender) {
this.meetingID = meetingID;
this.recorded = recorded;
usersEventRecorder = recorder;
this.usersMessagePublisher = usersMessagePublisher;
users = new ConcurrentHashMap<String, User>();
}
public void addParticipant(User participant) {
public String getMeetingID() {
return meetingID;
}
public void addParticipant(User user) {
synchronized (this) {
log.debug("adding participant " + participant.getInternalUserID());
users.put(participant.getInternalUserID(), participant);
users.put(user.getInternalUserID(), user);
}
log.debug("Informing roomlisteners " + listeners.size());
for (Iterator it = listeners.values().iterator(); it.hasNext();) {
IRoomListener listener = (IRoomListener) it.next();
log.debug("calling participantJoined on listener " + listener.getName());
listener.participantJoined(participant);
if (recorded) {
usersEventRecorder.userJoined(meetingID, user);
}
usersMessagePublisher.participantJoined(meetingID, user);
usersClientMessageSender.participantJoined(meetingID, user);
}
public void removeParticipant(String userid) {
boolean present = false;
User p = null;
User user = null;
synchronized (this) {
present = users.containsKey(userid);
if (present) {
log.debug("removing participant");
p = users.remove(userid);
user = users.remove(userid);
}
}
if (present) {
for (Iterator it = listeners.values().iterator(); it.hasNext();) {
IRoomListener listener = (IRoomListener) it.next();
log.debug("calling participantLeft on listener " + listener.getName());
listener.participantLeft(p);
if (recorded) {
usersEventRecorder.userLeft(meetingID, user);
}
usersMessagePublisher.participantLeft(meetingID, user);
usersClientMessageSender.participantLeft(meetingID, user);
}
}
@ -90,28 +93,26 @@ public class Meeting {
synchronized (this) {
present = users.containsKey(userid);
if (present) {
log.debug("change participant status");
p = users.get(userid);
p.setStatus(status, value);
//participants.put(userid, p);
//unmodifiableMap = Collections.unmodifiableMap(participants);
}
}
if (present) {
for (Iterator it = listeners.values().iterator(); it.hasNext();) {
IRoomListener listener = (IRoomListener) it.next();
log.debug("calling participantStatusChange on listener " + listener.getName());
listener.participantStatusChange(p, status, value);
if (recorded) {
usersEventRecorder.userStatusChange(meetingID, p, status, value);
}
usersMessagePublisher.participantStatusChange(meetingID, p, status, value);
usersClientMessageSender.participantStatusChange(meetingID, p, status, value);
}
}
public void endAndKickAll() {
for (Iterator it = listeners.values().iterator(); it.hasNext();) {
IRoomListener listener = (IRoomListener) it.next();
log.debug("calling endAndKickAll on listener " + listener.getName());
listener.endAndKickAll();
if (recorded) {
usersEventRecorder.endAndKickAll(meetingID);
}
usersClientMessageSender.endAndKickAll(meetingID);
}
public Map getParticipants() {
@ -123,7 +124,6 @@ public class Meeting {
}
public int getNumberOfParticipants() {
log.debug("Returning number of participants: " + users.size());
return users.size();
}
@ -143,13 +143,14 @@ public class Meeting {
return currentPresenter;
}
public void assignPresenter(ArrayList<String> presenter){
public void assignPresenter(String newPresenterID, String newPresenterName, String assignedBy){
ArrayList<String> presenter = new ArrayList<String>();
presenter.add(newPresenterID);
presenter.add(newPresenterName);
presenter.add(assignedBy);
currentPresenter = presenter;
for (Iterator iter = listeners.values().iterator(); iter.hasNext();) {
log.debug("calling on listener");
IRoomListener listener = (IRoomListener) iter.next();
log.debug("calling sendUpdateMessage on listener " + listener.getName());
listener.assignPresenter(presenter);
}
usersEventRecorder.assignPresenter(meetingID, newPresenterID, newPresenterName, assignedBy);
usersClientMessageSender.assignPresenter(meetingID, newPresenterID, newPresenterName, assignedBy);
}
}

View File

@ -20,15 +20,11 @@ package org.bigbluebutton.conference;
import org.slf4j.Logger;
import org.bigbluebutton.conference.meeting.messaging.MessagePublisher;
import org.bigbluebutton.conference.service.messaging.MessagingService;
import org.bigbluebutton.conference.service.messaging.redis.MessageHandler;
import org.bigbluebutton.conference.service.poll.PollApplication;
import org.bigbluebutton.conference.service.presentation.ConversionUpdatesMessageListener;
import org.bigbluebutton.conference.service.participants.messaging.redis.UsersMessagePublisher;
import org.bigbluebutton.conference.service.participants.recorder.redis.UsersEventRecorder;
import org.bigbluebutton.conference.service.participants.red5.UsersClientMessageSender;
import org.red5.logging.Red5LoggerFactory;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -38,17 +34,18 @@ public class MeetingsManager {
private final Map <String, Meeting> meetings;
private MessagePublisher publisher;
private UsersEventRecorder usersEventRecorder;
private UsersMessagePublisher usersMessagePublisher;
private UsersClientMessageSender usersClientMessageSender;
public MeetingsManager() {
meetings = new ConcurrentHashMap<String, Meeting>();
}
public void addRoom(Meeting room) {
// room.addRoomListener(new ParticipantUpdatingRoomListener(room, messagingService));
publisher.meetingStarted(room.getName());
meetings.put(room.getName(), room);
public void createMeeting(String meetingID, Boolean recorded) {
Meeting room = new Meeting(meetingID, recorded, usersEventRecorder, usersMessagePublisher, usersClientMessageSender);
meetings.put(meetingID, room);
publisher.meetingStarted(meetingID);
}
public void removeRoom(String name) {
@ -92,16 +89,7 @@ public class MeetingsManager {
log.warn("Getting participants from a non-existing room " + roomName);
return null;
}
public void addRoomListener(String roomName, IRoomListener listener) {
Meeting r = getRoom(roomName);
if (r != null) {
r.addRoomListener(listener);
return;
}
log.warn("Adding listener to a non-existing room " + roomName);
}
public void addParticipant(String roomName, User participant) {
log.debug("Add participant " + participant.getName());
Meeting r = getRoom(roomName);
@ -139,10 +127,10 @@ public class MeetingsManager {
return null;
}
public void assignPresenter(String room, ArrayList<String> presenter){
public void assignPresenter(String room, String newPresenterID, String newPresenterName, String assignedBy){
Meeting r = getRoom(room);
if (r != null) {
r.assignPresenter(presenter);
r.assignPresenter(newPresenterID, newPresenterName, assignedBy);
return;
}
}
@ -157,4 +145,17 @@ public class MeetingsManager {
public void setPublisher(MessagePublisher publisher) {
this.publisher = publisher;
}
public void setUsersEventRecorder(UsersEventRecorder usersEventRecorder) {
this.usersEventRecorder = usersEventRecorder;
}
public void setUsersMessagePublisher(UsersMessagePublisher usersMessagePublisher) {
this.usersMessagePublisher = usersMessagePublisher;
}
public void setUsersClientMessageSender(
UsersClientMessageSender usersClientMessageSender) {
this.usersClientMessageSender = usersClientMessageSender;
}
}

View File

@ -1,103 +0,0 @@
/**
* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
*
* Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*
*/
package org.bigbluebutton.conference;
import java.util.ArrayList;
import java.util.HashMap;
import org.bigbluebutton.conference.service.messaging.MessagingConstants;
import org.bigbluebutton.conference.service.messaging.MessagingService;
import org.red5.logging.Red5LoggerFactory;
import org.slf4j.Logger;
import com.google.gson.Gson;
public class ParticipantUpdatingRoomListener implements IRoomListener{
private static Logger log = Red5LoggerFactory.getLogger(ParticipantUpdatingRoomListener.class, "bigbluebutton");
MessagingService messagingService;
private Meeting room;
public ParticipantUpdatingRoomListener(Meeting room, MessagingService messagingService) {
this.room = room;
this.messagingService = messagingService;
}
public String getName() {
return "PARTICIPANT:UPDATE:ROOM";
}
public void participantStatusChange(User p, String status, Object value){
if (messagingService != null) {
HashMap<String,String> map= new HashMap<String, String>();
map.put("meetingId", this.room.getName());
map.put("messageId", MessagingConstants.USER_STATUS_CHANGE_EVENT);
map.put("internalUserId", p.getInternalUserID());
map.put("status", status);
map.put("value", value.toString());
Gson gson= new Gson();
messagingService.send(MessagingConstants.PARTICIPANTS_CHANNEL, gson.toJson(map));
log.debug("Publishing a status change in: " + this.room.getName());
}
}
public void participantJoined(User p) {
if (messagingService != null) {
HashMap<String,String> map= new HashMap<String, String>();
map.put("meetingId", this.room.getName());
map.put("messageId", MessagingConstants.USER_JOINED_EVENT);
map.put("internalUserId", p.getInternalUserID());
map.put("externalUserId", p.getExternalUserID());
map.put("fullname", p.getName());
map.put("role", p.getRole());
Gson gson= new Gson();
messagingService.send(MessagingConstants.PARTICIPANTS_CHANNEL, gson.toJson(map));
log.debug("Publishing message participant joined in " + this.room.getName());
}
}
public void participantLeft(User p) {
if (messagingService != null) {
HashMap<String,String> map= new HashMap<String, String>();
map.put("meetingId", this.room.getName());
map.put("messageId", MessagingConstants.USER_LEFT_EVENT);
map.put("internalUserId", p.getInternalUserID());
Gson gson= new Gson();
messagingService.send(MessagingConstants.PARTICIPANTS_CHANNEL, gson.toJson(map));
log.debug("Publishing message participant left in " + this.room.getName());
}
}
public void assignPresenter(ArrayList<String> presenter) {
// Do nothing.
}
public void endAndKickAll() {
// no-op
}
}

View File

@ -27,8 +27,10 @@ import org.slf4j.Logger;
import org.red5.logging.Red5LoggerFactory;
import org.red5.server.api.Red5; import org.bigbluebutton.conference.BigBlueButtonSession;
import org.bigbluebutton.conference.Constants;
import org.bigbluebutton.conference.meeting.messaging.red5.BroadcastClientMessage;
import org.bigbluebutton.conference.meeting.messaging.red5.ClientMessage;
import org.bigbluebutton.conference.meeting.messaging.red5.ConnectionInvokerService;
import org.bigbluebutton.conference.meeting.messaging.red5.DirectClientMessage;
import org.bigbluebutton.conference.service.chat.ChatRoomsManager;
import org.bigbluebutton.conference.service.chat.ChatRoom; import org.bigbluebutton.conference.service.chat.IChatRoomListener;
@ -78,22 +80,22 @@ public class ChatApplication {
messageToSend.put("count", new Integer(msgs.size()));
messageToSend.put("messages", msgs);
ClientMessage m = new ClientMessage(ClientMessage.DIRECT, getBbbSession().getInternalUserID(), "ChatRequestMessageHistoryReply", messageToSend);
DirectClientMessage m = new DirectClientMessage(getMeetingId(), getBbbSession().getInternalUserID(), "ChatRequestMessageHistoryReply", messageToSend);
connInvokerService.sendMessage(m);
}
public void sendPublicMessage(String room, ChatMessageVO chatobj) {
roomsManager.sendMessage(room, chatobj);
ClientMessage m = new ClientMessage(ClientMessage.BROADCAST, getMeetingId(), "ChatReceivePublicMessageCommand", chatobj.toMap());
BroadcastClientMessage m = new BroadcastClientMessage(getMeetingId(), "ChatReceivePublicMessageCommand", chatobj.toMap());
connInvokerService.sendMessage(m);
}
public void sendPrivateMessage(ChatMessageVO chatobj) {
ClientMessage m = new ClientMessage(ClientMessage.DIRECT, chatobj.toUserID, "ChatReceivePrivateMessageCommand", chatobj.toMap());
DirectClientMessage m = new DirectClientMessage(getMeetingId(), chatobj.toUserID, "ChatReceivePrivateMessageCommand", chatobj.toMap());
connInvokerService.sendMessage(m);
ClientMessage m2 = new ClientMessage(ClientMessage.DIRECT, chatobj.fromUserID, "ChatReceivePrivateMessageCommand", chatobj.toMap());
DirectClientMessage m2 = new DirectClientMessage(getMeetingId(), chatobj.fromUserID, "ChatReceivePrivateMessageCommand", chatobj.toMap());
connInvokerService.sendMessage(m2);
}

View File

@ -19,23 +19,19 @@
package org.bigbluebutton.conference.service.participants;
import org.slf4j.Logger;
import org.red5.logging.Red5LoggerFactory;
import org.red5.server.api.Red5; import java.util.ArrayList;
import org.red5.logging.Red5LoggerFactory; import java.util.ArrayList;
import java.util.Map;
import org.bigbluebutton.conference.MeetingsManager;
import org.bigbluebutton.conference.Meeting; import org.bigbluebutton.conference.User; import org.bigbluebutton.conference.IRoomListener;
import org.bigbluebutton.conference.meeting.messaging.red5.ConnectionInvokerService;
public class ParticipantsApplication {
private static Logger log = Red5LoggerFactory.getLogger( ParticipantsApplication.class, "bigbluebutton" );
private ConnectionInvokerService connInvokerService;
private MeetingsManager roomsManager;
public boolean createRoom(String name) {
if(!roomsManager.hasRoom(name)){
log.info("Creating room " + name);
roomsManager.addRoom(new Meeting(name));
public boolean createRoom(String meetingID, Boolean recorded) {
if(!roomsManager.hasRoom(meetingID)){
roomsManager.createMeeting(meetingID, recorded);
return true;
}
return false;
@ -61,7 +57,6 @@ public class ParticipantsApplication {
public boolean addRoomListener(String room, IRoomListener listener) {
if (roomsManager.hasRoom(room)){
roomsManager.addRoomListener(room, listener);
return true;
}
log.warn("Adding listener to a non-existant room " + room);
@ -116,9 +111,9 @@ public class ParticipantsApplication {
return null;
}
public void assignPresenter(String room, ArrayList presenter){
public void assignPresenter(String room, String newPresenterID, String newPresenterName, String assignedBy){
if (roomsManager.hasRoom(room)){
roomsManager.assignPresenter(room, presenter);
roomsManager.assignPresenter(room, newPresenterID, newPresenterName, assignedBy);
return;
}
log.warn("Assigning presenter on a non-existant room " + room);
@ -128,12 +123,5 @@ public class ParticipantsApplication {
log.debug("Setting room manager");
roomsManager = r;
}
private String getMeetingId(){
return Red5.getConnectionLocal().getScope().getName();
}
public void setConnInvokerService(ConnectionInvokerService connInvokerService) {
this.connInvokerService = connInvokerService;
}
}

View File

@ -56,7 +56,7 @@ public class ParticipantsService {
} else {
log.info("No current presenter. So do nothing.");
}
application.assignPresenter(scope.getName(), presenter);
application.assignPresenter(scope.getName(), userid, name, assignedBy.toString());
}
@SuppressWarnings("unchecked")

View File

@ -1,7 +1,5 @@
package org.bigbluebutton.conference.service.participants.recorder.redis;
import java.util.ArrayList;
import org.bigbluebutton.conference.User;
import org.bigbluebutton.conference.service.recorder.RecorderApplication;
import org.bigbluebutton.conference.service.recorder.participants.AssignPresenterRecordEvent;

View File

@ -1,11 +1,7 @@
package org.bigbluebutton.conference.service.participants.red5;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.bigbluebutton.conference.User;
import org.bigbluebutton.conference.meeting.messaging.red5.ClientMessage;
import org.bigbluebutton.conference.meeting.messaging.red5.ConnectionInvokerService;
import org.bigbluebutton.conference.meeting.messaging.red5.SharedObjectClientMessage;
@ -24,7 +20,12 @@ public class UsersClientMessageSender {
}
public void assignPresenter(String meetingID, ArrayList<Object> presenter) {
public void assignPresenter(String meetingID, String newPresenterID, String newPresenterName, String assignedBy) {
ArrayList<Object> presenter = new ArrayList<Object>();
presenter.add(newPresenterID);
presenter.add(newPresenterName);
presenter.add(assignedBy);
SharedObjectClientMessage m = new SharedObjectClientMessage(meetingID, USERS_SO, "assignPresenterCallback", presenter);
service.sendMessage(m);
}

View File

@ -19,6 +19,7 @@
package org.bigbluebutton.conference.service.presentation;
import org.slf4j.Logger;
import org.bigbluebutton.conference.meeting.messaging.red5.BroadcastClientMessage;
import org.bigbluebutton.conference.meeting.messaging.red5.ClientMessage;
import org.bigbluebutton.conference.meeting.messaging.red5.ConnectionInvokerService;
import org.red5.logging.Red5LoggerFactory;
@ -124,7 +125,7 @@ public class PresentationApplication {
Map<String, Object> message = new HashMap<String, Object>();
message.put("xPercent", xPercent);
message.put("yPercent", yPercent);
ClientMessage m = new ClientMessage(ClientMessage.BROADCAST, getMeetingId(), "PresentationCursorUpdateCommand", message);
BroadcastClientMessage m = new BroadcastClientMessage(getMeetingId(), "PresentationCursorUpdateCommand", message);
connInvokerService.sendMessage(m);
return;