Author: solomax
Date: Tue Dec  9 19:22:29 2014
New Revision: 1644160

URL: http://svn.apache.org/r1644160
Log:
[OPENMEETINGS-954] Mobile service is updated to work with mobile client; number 
of blocked operations reduced; code clean-up

Modified:
    
openmeetings/branches/3.0.x/src/main/java/org/apache/openmeetings/remote/MainService.java
    
openmeetings/branches/3.0.x/src/main/java/org/apache/openmeetings/remote/MobileService.java
    
openmeetings/branches/3.0.x/src/main/java/org/apache/openmeetings/remote/red5/ScopeApplicationAdapter.java
    
openmeetings/branches/3.0.x/src/test/java/org/apache/openmeetings/test/rtmp/LoadTestRtmpClient.java
    
openmeetings/trunk/singlewebapp/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MainService.java
    
openmeetings/trunk/singlewebapp/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java
    
openmeetings/trunk/singlewebapp/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/red5/ScopeApplicationAdapter.java

Modified: 
openmeetings/branches/3.0.x/src/main/java/org/apache/openmeetings/remote/MainService.java
URL: 
http://svn.apache.org/viewvc/openmeetings/branches/3.0.x/src/main/java/org/apache/openmeetings/remote/MainService.java?rev=1644160&r1=1644159&r2=1644160&view=diff
==============================================================================
--- 
openmeetings/branches/3.0.x/src/main/java/org/apache/openmeetings/remote/MainService.java
 (original)
+++ 
openmeetings/branches/3.0.x/src/main/java/org/apache/openmeetings/remote/MainService.java
 Tue Dec  9 19:22:29 2014
@@ -133,7 +133,7 @@ public class MainService implements IPen
                Long users_id = sessiondataDao.checkSession(SID);
                Set<Right> rights = userDao.getRights(users_id);
                if (AuthLevelUtil.hasAdminLevel(rights) || 
AuthLevelUtil.hasWebServiceLevel(rights)) {
-                       users = userDao.get(new Long(USER_ID));
+                       users = userDao.get(USER_ID);
                } else {
                        users.setFirstname("No rights to do this");
                }
@@ -148,8 +148,7 @@ public class MainService implements IPen
                        log.debug("getCurrentRoomClient -1- " + SID);
                        log.debug("getCurrentRoomClient -2- " + streamid);
 
-                       Client currentClient = this.sessionManager
-                                       .getClientByStreamId(streamid, null);
+                       Client currentClient = 
sessionManager.getClientByStreamId(streamid, null);
                        return currentClient;
                } catch (Exception err) {
                        log.error("[getCurrentRoomClient]", err);
@@ -566,8 +565,7 @@ public class MainService implements IPen
                                if (status) {
                                        Map<String, String> message = new 
HashMap<String, String>();
                                        message.put("message", "roomClosed");
-                                       
this.scopeApplicationAdapter.sendMessageByRoomAndDomain(
-                                                       room_id, message);
+                                       
scopeApplicationAdapter.sendMessageByRoomAndDomain(room_id, message);
                                }
 
                                return 1;

Modified: 
openmeetings/branches/3.0.x/src/main/java/org/apache/openmeetings/remote/MobileService.java
URL: 
http://svn.apache.org/viewvc/openmeetings/branches/3.0.x/src/main/java/org/apache/openmeetings/remote/MobileService.java?rev=1644160&r1=1644159&r2=1644160&view=diff
==============================================================================
--- 
openmeetings/branches/3.0.x/src/main/java/org/apache/openmeetings/remote/MobileService.java
 (original)
+++ 
openmeetings/branches/3.0.x/src/main/java/org/apache/openmeetings/remote/MobileService.java
 Tue Dec  9 19:22:29 2014
@@ -42,16 +42,13 @@ import org.apache.openmeetings.db.entity
 import org.apache.openmeetings.remote.red5.ScopeApplicationAdapter;
 import org.apache.openmeetings.remote.util.SessionVariablesUtil;
 import org.red5.logging.Red5LoggerFactory;
-import org.red5.server.api.IClient;
 import org.red5.server.api.IConnection;
 import org.red5.server.api.Red5;
-import org.red5.server.api.service.IPendingServiceCall;
-import org.red5.server.api.service.IPendingServiceCallback;
 import org.red5.server.api.service.IServiceCapableConnection;
 import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 
-public class MobileService implements IPendingServiceCallback {
+public class MobileService {
        private static final Logger log = 
Red5LoggerFactory.getLogger(MainService.class, webAppRootKey);
        @Autowired
        private UserDao userDao;
@@ -68,10 +65,6 @@ public class MobileService implements IP
        @Autowired
        private ScopeApplicationAdapter scopeAdapter;
 
-       @Override
-       public void resultReceived(IPendingServiceCall call) {
-       }
-
        public Map<String, Object> loginUser(String login, String password) {
                Map<String, Object> result = new Hashtable<String, Object>();
                try {
@@ -123,22 +116,20 @@ public class MobileService implements IP
                // Notify all clients of the same scope (room)
                IConnection current = Red5.getConnectionLocal();
                for (IConnection conn : 
current.getScope().getClientConnections()) {
-                       if (conn != null) {
-                               if (conn instanceof IServiceCapableConnection) {
-                                       Client c = 
sessionManager.getClientByStreamId(conn.getClient().getId(), null);
-                                       if (c.getIsAVClient()) {
-                                               Map<String, Object> map = new 
Hashtable<String, Object>();
-                                               map.put("streamId", 
c.getStreamid());
-                                               map.put("broadCastId", 
c.getBroadCastID());
-                                               map.put("userId", 
c.getUser_id() == null ? "" : c.getUser_id());
-                                               map.put("firstname", 
c.getFirstname());
-                                               map.put("lastname", 
c.getLastname());
-                                               map.put("publicSid", 
c.getPublicSID());
-                                               map.put("login", 
c.getUsername());
-                                               map.put("email", c.getEmail() 
== null ? "" : c.getEmail());
-                                               map.put("avsettings", 
c.getAvsettings());
-                                               result.add(map);
-                                       }
+                       if (conn != null && conn instanceof 
IServiceCapableConnection) {
+                               Client c = 
sessionManager.getClientByStreamId(conn.getClient().getId(), null);
+                               if (c.getIsAVClient()) {
+                                       Map<String, Object> map = new 
Hashtable<String, Object>();
+                                       map.put("streamId", c.getStreamid());
+                                       map.put("broadCastId", 
c.getBroadCastID());
+                                       map.put("userId", c.getUser_id() == 
null ? "" : c.getUser_id());
+                                       map.put("firstname", c.getFirstname());
+                                       map.put("lastname", c.getLastname());
+                                       map.put("publicSid", c.getPublicSID());
+                                       map.put("login", c.getUsername());
+                                       map.put("email", c.getEmail() == null ? 
"" : c.getEmail());
+                                       map.put("avsettings", 
c.getAvsettings());
+                                       result.add(map);
                                }
                        }
                }
@@ -205,33 +196,11 @@ public class MobileService implements IP
                sessionManager.updateClientByStreamId(c.getStreamid(), c, 
false, null);
                result.put("broadcastId", broadcastId);
 
-               //FIXME make it async + copy/paste
-               IConnection current = Red5.getConnectionLocal();
-               for (IConnection conn : 
current.getScope().getClientConnections()) {
-                       if (conn != null) {
-                               IClient client = conn.getClient();
-                               if 
(SessionVariablesUtil.isScreenClient(client)) {
-                                       // screen sharing clients do not 
receive events
-                                       continue;
-                               } else if 
(SessionVariablesUtil.isAVClient(client)) {
-                                       // AVClients or potential AVClients do 
not receive events
-                                       continue;
-                               }
-
-                               if 
(!client.getId().equals(current.getClient().getId())) {
-                                       // It is not needed to send back that 
event to the actual Moderator
-                                       // as it will be already triggered in 
the result of this Function in the Client
-                                       if (conn instanceof 
IServiceCapableConnection) {
-                                               ((IServiceCapableConnection) 
conn).invoke("addNewUser", new Object[] { c }, this);
-                                               log.debug("sending Mobile 
client to " + conn);
-                                       }
-                               }
-                       }
-               }
+               scopeAdapter.syncMessageToCurrentScope("addNewUser", c, false, 
false);
                return result;
        }
 
-       public void updateAvMode(String avMode, String width, String height) {
+       public Map<String, Object> updateAvMode(String avMode, String width, 
String height) {
                IConnection current = Red5.getConnectionLocal();
                Client c = 
sessionManager.getClientByStreamId(current.getClient().getId(), null);
                c.setAvsettings(avMode);
@@ -241,22 +210,12 @@ public class MobileService implements IP
                HashMap<String, Object> hsm = new HashMap<String, Object>();
                hsm.put("client", c);
                hsm.put("message", new String[]{"avsettings", "0", avMode});
-
-               //FIXME should be handled async + copy/paste
-               for (IConnection conn : 
current.getScope().getClientConnections()) {
-                       if (conn != null) {
-                               if (conn instanceof IServiceCapableConnection) {
-                                       IClient client = conn.getClient();
-                                       if 
(SessionVariablesUtil.isScreenClient(client)) {
-                                               // screen sharing clients do 
not receive events
-                                               continue;
-                                       } else if 
(SessionVariablesUtil.isAVClient(client)) {
-                                               // AVClients or potential 
AVClients do not receive events
-                                               continue;
-                                       }
-                                       
((IServiceCapableConnection)conn).invoke("sendVarsToMessageWithClient", new 
Object[] { hsm }, this);
-                               }
-                       }
+               Map<String, Object> result = new Hashtable<String, Object>();
+               if (!"n".equals(avMode)) {
+                       result.put("broadcastId", 
scopeAdapter.getBroadCastId());
                }
+
+               
scopeAdapter.syncMessageToCurrentScope("sendVarsToMessageWithClient", hsm, 
true, false);
+               return result;
        }
 }

Modified: 
openmeetings/branches/3.0.x/src/main/java/org/apache/openmeetings/remote/red5/ScopeApplicationAdapter.java
URL: 
http://svn.apache.org/viewvc/openmeetings/branches/3.0.x/src/main/java/org/apache/openmeetings/remote/red5/ScopeApplicationAdapter.java?rev=1644160&r1=1644159&r2=1644160&view=diff
==============================================================================
--- 
openmeetings/branches/3.0.x/src/main/java/org/apache/openmeetings/remote/red5/ScopeApplicationAdapter.java
 (original)
+++ 
openmeetings/branches/3.0.x/src/main/java/org/apache/openmeetings/remote/red5/ScopeApplicationAdapter.java
 Tue Dec  9 19:22:29 2014
@@ -30,6 +30,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.openmeetings.data.calendar.management.AppointmentLogic;
 import org.apache.openmeetings.data.conference.RoomManager;
@@ -111,7 +112,7 @@ public class ScopeApplicationAdapter ext
        @Autowired
        private ServerDao serverDao;
 
-       private static long broadCastCounter = 0;
+       private static AtomicLong broadCastCounter = new AtomicLong(0);
 
        public synchronized void resultReceived(IPendingServiceCall arg0) {
                // TODO Auto-generated method stub
@@ -162,7 +163,7 @@ public class ScopeApplicationAdapter ext
                        }
 
                        log.debug("### Client connected to OpenMeetings, 
register Client StreamId: " + streamId + " scope "
-                                       + conn.getScope().getName() + " 
isAVClient " + isAVClient + " params " + params);
+                                       + conn.getScope().getName() + " 
isAVClient " + isAVClient);
 
                        // Set StreamId in Client
                        service.invoke("setId", new Object[] { streamId }, 
this);
@@ -254,8 +255,7 @@ public class ScopeApplicationAdapter ext
 
                        List<Client> screenSharerList = new 
LinkedList<Client>();
 
-                       Client currentClient = this.sessionManager
-                                       .getClientByStreamId(streamid, null);
+                       Client currentClient = 
sessionManager.getClientByStreamId(streamid, null);
 
                        for (Client rcl : 
sessionManager.getClientListByRoomAll(currentClient.getRoom_id())) {
                                if (rcl.isStartStreaming()) {
@@ -394,13 +394,10 @@ public class ScopeApplicationAdapter ext
         String streamid = current.getClient().getId();
         for (IConnection conn : current.getScope().getClientConnections()) {
             if (conn != null) {
-                Client rcl = this.sessionManager
-                        .getClientByStreamId(conn
-                                .getClient().getId(), null);
+                Client rcl = 
sessionManager.getClientByStreamId(conn.getClient().getId(), null);
                 if (rcl == null) {
                     // continue;
-                } else if (rcl.getIsScreenClient() != null
-                        && rcl.getIsScreenClient()) {
+                } else if (rcl.getIsScreenClient() != null && 
rcl.getIsScreenClient()) {
                     // continue;
                 } else {
                     if (!streamid.equals(rcl.getStreamid())) {
@@ -410,9 +407,9 @@ public class ScopeApplicationAdapter ext
                         // as it will be already triggered
                         // in the result of this Function
                         // in the Client
-                       Long id = Long.valueOf(rcl.getBroadCastID());
-                       if (id != null && !broadcastList.contains(id)) {
-                               broadcastList.add(id.intValue());
+                       int id = (int)rcl.getBroadCastID();
+                       if (!broadcastList.contains(id)) {
+                               broadcastList.add(id);
                        }
                     }
                 }
@@ -869,8 +866,7 @@ public class ScopeApplicationAdapter ext
                                                } else if 
(SessionVariablesUtil.isAVClient(client)) {
                                                        // AVClients or 
potential AVClients do not receive events
                                                        continue;
-                                               } if (client.getId().equals(
-                                                                       
current.getClient().getId())) {
+                                               } if 
(client.getId().equals(current.getClient().getId())) {
                                                        // don't send back to 
same user
                                                        continue;
                                                }
@@ -925,8 +921,7 @@ public class ScopeApplicationAdapter ext
                return -1L;
        }
 
-       public synchronized Long setBroadCastingFlag(String publicSID,
-                       boolean value, Integer interviewPodId) {
+       public synchronized Long setBroadCastingFlag(String publicSID, boolean 
value, Integer interviewPodId) {
                try {
                        log.debug("-----------  setBroadCastingFlag: " + 
publicSID);
 
@@ -1091,13 +1086,13 @@ public class ScopeApplicationAdapter ext
         * 
         * @return long broadCastId
         */
-       public synchronized long getBroadCastId() {
+       public long getBroadCastId() {
                try {
                        log.debug("-----------  getBroadCastId");
                        IConnection current = Red5.getConnectionLocal();
                        String streamid = current.getClient().getId();
                        Client client = 
sessionManager.getClientByStreamId(streamid, null);
-                       client.setBroadCastID(broadCastCounter++);
+                       
client.setBroadCastID(broadCastCounter.getAndIncrement());
                        sessionManager.updateClientByStreamId(streamid, client, 
false, null);
                        return client.getBroadCastID();
                } catch (Exception err) {
@@ -1183,7 +1178,6 @@ public class ScopeApplicationAdapter ext
                        // not really - default logic
                        if (room.getAppointment() == null || 
room.getAppointment() == false) {
                                if (room.getIsModeratedRoom()) {
-
                                        // if this is a Moderated Room then the 
Room can be only
                                        // locked off by the Moderator Bit
                                        List<Client> clientModeratorListRoom = 
sessionManager.getCurrentModeratorByRoom(room_id);
@@ -1784,7 +1778,7 @@ public class ScopeApplicationAdapter ext
                return -1;
        }
 
-       public synchronized int sendMessage(Object newMessage) {
+       public int sendMessage(Object newMessage) {
                try {
                        
                        syncMessageToCurrentScope("sendVarsToMessage", 
newMessage, false);
@@ -1795,7 +1789,7 @@ public class ScopeApplicationAdapter ext
                return 1;
        }
        
-       public synchronized int sendMessageAll(Object newMessage) {
+       public int sendMessageAll(Object newMessage) {
                try {
                        
                        syncMessageToCurrentScope("sendVarsToMessage", 
newMessage, true);
@@ -1820,8 +1814,7 @@ public class ScopeApplicationAdapter ext
 
                        String action = newMessageList.get(0).toString();
 
-                       BrowserStatus browserStatus = (BrowserStatus) 
current.getScope()
-                                       .getAttribute("browserStatus");
+                       BrowserStatus browserStatus = (BrowserStatus) 
current.getScope().getAttribute("browserStatus");
 
                        if (browserStatus == null) {
                                browserStatus = new BrowserStatus();
@@ -1848,7 +1841,7 @@ public class ScopeApplicationAdapter ext
         * wrapper method
         * @param newMessage
         */
-       public synchronized void sendMessageToMembers(Object newMessage) {
+       public void sendMessageToMembers(Object newMessage) {
                //Sync to all users of current scope
                syncMessageToCurrentScope("sendVarsToMessage", newMessage, 
false);
        }
@@ -1867,7 +1860,7 @@ public class ScopeApplicationAdapter ext
         * @param newMessage parameters
         * @param sendSelf send to the current client as well
         */
-       public synchronized void syncMessageToCurrentScope(String 
remoteMethodName, Object newMessage, boolean sendSelf) {
+       public void syncMessageToCurrentScope(String remoteMethodName, Object 
newMessage, boolean sendSelf) {
                syncMessageToCurrentScope(remoteMethodName, newMessage, 
sendSelf, false);
        }
        
@@ -1880,7 +1873,7 @@ public class ScopeApplicationAdapter ext
         * @return true
         */
        @Deprecated
-       public synchronized boolean loadTestSyncMessage(String 
remoteMethodName, Object newMessage, boolean sendSelf) {
+       public boolean loadTestSyncMessage(String remoteMethodName, Object 
newMessage, boolean sendSelf) {
                syncMessageToCurrentScope(remoteMethodName, newMessage, 
sendSelf, false);
                return true;
        }
@@ -1901,32 +1894,31 @@ public class ScopeApplicationAdapter ext
         * @param sendSelf send to the current client as well
         * @param sendScreen send to the current client as well
         */
-       public synchronized void syncMessageToCurrentScope(String 
remoteMethodName, Object newMessage, boolean sendSelf, boolean sendScreen) {
+       public void syncMessageToCurrentScope(final String remoteMethodName, 
final Object newMessage, final boolean sendSelf, final boolean sendScreen) {
                try {
-                       IConnection current = Red5.getConnectionLocal();
+                       final IConnection current = Red5.getConnectionLocal();
 
-                       // Send to all Clients of that Scope(Room)
-                       for (IConnection conn : 
current.getScope().getClientConnections()) {
-                               if (conn != null) {
-                                       if (conn instanceof 
IServiceCapableConnection) {
-                                               IClient client = 
conn.getClient();
-                                               if (!sendScreen && 
SessionVariablesUtil.isScreenClient(client)) {
-                                                       // screen sharing 
clients do not receive events
-                                                       continue;
-                                               } else if 
(SessionVariablesUtil.isAVClient(client)) {
-                                                       // AVClients or 
potential AVClients do not receive events
-                                                       continue;
-                                               } else if (!sendSelf && 
client.getId().equals(
-                                                               
current.getClient().getId())) {
-                                                       //Do not send back to 
self
-                                                       continue;
+                       new Thread(new Runnable() {
+                           public void run() {
+                                       for (IConnection conn : 
current.getScope().getClientConnections()) {
+                                               if (conn != null && conn 
instanceof IServiceCapableConnection) {
+                                                       IClient client = 
conn.getClient();
+                                                       if (!sendScreen && 
SessionVariablesUtil.isScreenClient(client)) {
+                                                               // screen 
sharing clients do not receive events
+                                                               continue;
+                                                       } else if 
(SessionVariablesUtil.isAVClient(client)) {
+                                                               // AVClients or 
potential AVClients do not receive events
+                                                               continue;
+                                                       } else if (!sendSelf && 
client.getId().equals(current.getClient().getId())) {
+                                                               //Do not send 
back to self
+                                                               continue;
+                                                       }
+                                                       
((IServiceCapableConnection) conn).invoke(remoteMethodName, new Object[] { 
newMessage }, ScopeApplicationAdapter.this);
                                                }
-                                               ((IServiceCapableConnection) 
conn).invoke(
-                                                               
remoteMethodName, new Object[] { newMessage }, this);
-                                               
                                        }
-                               }
-                       }
+                           }
+                       }).start();
+                       // Send to all Clients of that Scope(Room)
                } catch (Exception err) {
                        log.error("[syncMessageToCurrentScope]", err);
                }
@@ -1937,7 +1929,7 @@ public class ScopeApplicationAdapter ext
         * @param newMessage
         * @return 1 in case of success, -1 otherwise
         */
-       public synchronized int sendMessageWithClient(Object newMessage) {
+       public int sendMessageWithClient(Object newMessage) {
                try {
                        sendMessageWithClientWithSyncObject(newMessage, true);
 
@@ -1957,8 +1949,7 @@ public class ScopeApplicationAdapter ext
        public synchronized int sendMessageWithClientWithSyncObject(Object 
newMessage, boolean sync) {
                try {
                        IConnection current = Red5.getConnectionLocal();
-                       Client currentClient = this.sessionManager
-                                       
.getClientByStreamId(current.getClient().getId(), null);
+                       Client currentClient = 
sessionManager.getClientByStreamId(current.getClient().getId(), null);
 
                        HashMap<String, Object> hsm = new HashMap<String, 
Object>();
                        hsm.put("client", currentClient);
@@ -1982,8 +1973,7 @@ public class ScopeApplicationAdapter ext
         * @param clientId
         * @return 1 in case of success, -1 otherwise
         */
-       public synchronized int sendMessageById(Object newMessage, String 
clientId,
-                       IScope scope) {
+       public synchronized int sendMessageById(Object newMessage, String 
clientId, IScope scope) {
                try {
                        log.debug("### sendMessageById ###" + clientId);
 
@@ -1995,9 +1985,7 @@ public class ScopeApplicationAdapter ext
                                if (conn != null) {
                                        if (conn instanceof 
IServiceCapableConnection) {
                                                if 
(conn.getClient().getId().equals(clientId)) {
-                                                       
((IServiceCapableConnection) conn).invoke(
-                                                                       
"sendVarsToMessageWithClient",
-                                                                       new 
Object[] { hsm }, this);
+                                                       
((IServiceCapableConnection) conn).invoke("sendVarsToMessageWithClient", new 
Object[] { hsm }, this);
                                                }
                                        }
                                }
@@ -2019,8 +2007,7 @@ public class ScopeApplicationAdapter ext
        public synchronized int sendMessageWithClientById(Object newMessage, 
String clientId) {
                try {
                        IConnection current = Red5.getConnectionLocal();
-                       Client currentClient = this.sessionManager
-                                       
.getClientByStreamId(current.getClient().getId(), null);
+                       Client currentClient = 
sessionManager.getClientByStreamId(current.getClient().getId(), null);
 
                        HashMap<String, Object> hsm = new HashMap<String, 
Object>();
                        hsm.put("client", currentClient);
@@ -2029,9 +2016,7 @@ public class ScopeApplicationAdapter ext
                        // broadcast Message to specific user with id inside 
the same Scope
                        for (IConnection conn : 
current.getScope().getClientConnections()) {
                                if (conn.getClient().getId().equals(clientId)) {
-                                       ((IServiceCapableConnection) 
conn).invoke(
-                                                       
"sendVarsToMessageWithClient",
-                                                       new Object[] { hsm }, 
this);
+                                       ((IServiceCapableConnection) 
conn).invoke("sendVarsToMessageWithClient", new Object[] { hsm }, this);
                                }
                        }
                } catch (Exception err) {
@@ -2045,14 +2030,12 @@ public class ScopeApplicationAdapter ext
                try {
                        //if the upload is locally, just proceed to the normal 
function
                        //Search for RoomClient on current server (serverId == 
null means it will look on the master for the RoomClient)
-                       Client currentClient = this.sessionManager
-                                                               
.getClientByPublicSID(publicSID, false, null);
+                       Client currentClient = 
sessionManager.getClientByPublicSID(publicSID, false, null);
                        
                        if (currentClient != null) {
                                sendMessageWithClientByPublicSID(message, 
publicSID);
                        } else {
-                               throw new Exception(
-                                               "Could not Find RoomClient on 
List publicSID: "+ publicSID);
+                               throw new Exception("Could not Find RoomClient 
on List publicSID: "+ publicSID);
                        }
                        
                } catch (Exception err) {
@@ -2061,25 +2044,20 @@ public class ScopeApplicationAdapter ext
        }
        
 
-       public synchronized void sendMessageWithClientByPublicSID(Object 
message,
-                       String publicSID) {
+       public synchronized void sendMessageWithClientByPublicSID(Object 
message, String publicSID) {
                try {
                        // ApplicationContext appCtx = 
getContext().getApplicationContext();
                        IScope globalScope = getContext().getGlobalScope();
 
-                       IScope webAppKeyScope = globalScope
-                                       
.getScope(OpenmeetingsVariables.webAppRootKey);
+                       IScope webAppKeyScope = 
globalScope.getScope(OpenmeetingsVariables.webAppRootKey);
 
                        // log.debug("webAppKeyScope "+webAppKeyScope);
 
                        // Get Room Id to send it to the correct Scope
-                       Client currentClient = this.sessionManager
-                                       .getClientByPublicSID(publicSID, false, 
null);
+                       Client currentClient = 
sessionManager.getClientByPublicSID(publicSID, false, null);
 
                        if (currentClient == null) {
-                               throw new Exception(
-                                               "Could not Find RoomClient on 
List publicSID: "
-                                                               + publicSID);
+                               throw new Exception("Could not Find RoomClient 
on List publicSID: " + publicSID);
                        }
                        // default Scope Name
                        String scopeName = "hibernate";
@@ -2465,11 +2443,8 @@ public class ScopeApplicationAdapter ext
                Client currentClient = 
sessionManager.getClientByStreamId(streamid, null);
                try {
                        String sipNumber = 
getSipNumber(currentClient.getRoom_id());
-                       log.debug("asterisk -rx \"originate Local/" + number + 
"@rooms-out extension " + sipNumber
-                                       + "@rooms-originate\"");
-                       Runtime.getRuntime().exec(
-                                       new String[] { "asterisk", "-rx",
-                                                       "originate Local/" + 
number + "@rooms-out extension " + sipNumber + "@rooms-originate" });
+                       log.debug("asterisk -rx \"originate Local/" + number + 
"@rooms-out extension " + sipNumber + "@rooms-originate\"");
+                       Runtime.getRuntime().exec(new String[] { "asterisk", 
"-rx", "originate Local/" + number + "@rooms-out extension " + sipNumber + 
"@rooms-originate" });
                } catch (IOException e) {
                        log.error("Executing asterisk originate error: ", e);
                }

Modified: 
openmeetings/branches/3.0.x/src/test/java/org/apache/openmeetings/test/rtmp/LoadTestRtmpClient.java
URL: 
http://svn.apache.org/viewvc/openmeetings/branches/3.0.x/src/test/java/org/apache/openmeetings/test/rtmp/LoadTestRtmpClient.java?rev=1644160&r1=1644159&r2=1644160&view=diff
==============================================================================
--- 
openmeetings/branches/3.0.x/src/test/java/org/apache/openmeetings/test/rtmp/LoadTestRtmpClient.java
 (original)
+++ 
openmeetings/branches/3.0.x/src/test/java/org/apache/openmeetings/test/rtmp/LoadTestRtmpClient.java
 Tue Dec  9 19:22:29 2014
@@ -86,8 +86,7 @@ public class LoadTestRtmpClient extends
                        map.put("instanceId", instanceId);
                        map.put("count", counterCalls);
                        calls.put(counterCalls, new CallObject(new Date()));
-                       invoke("loadTestSyncMessage", new Object[] {
-                                       "syncMessageToCurrentScopeResult", map, 
true }, this);
+                       invoke("loadTestSyncMessage", new Object[] 
{"syncMessageToCurrentScopeResult", map, true }, this);
 
                } else {
                        System.err.println("Call running " + counterCalls);
@@ -134,8 +133,7 @@ public class LoadTestRtmpClient extends
                        CallObject tCallObject = calls.get(counterCalls);
                        if (tCallObject == null) {
 
-                               for (Entry<Integer, CallObject> 
tCallObjectEntry : calls
-                                               .entrySet()) {
+                               for (Entry<Integer, CallObject> 
tCallObjectEntry : calls.entrySet()) {
 
                                        System.err.println("Key " + 
tCallObjectEntry.getKey()
                                                        + "tCallObjectEntry "

Modified: 
openmeetings/trunk/singlewebapp/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MainService.java
URL: 
http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MainService.java?rev=1644160&r1=1644159&r2=1644160&view=diff
==============================================================================
--- 
openmeetings/trunk/singlewebapp/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MainService.java
 (original)
+++ 
openmeetings/trunk/singlewebapp/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MainService.java
 Tue Dec  9 19:22:29 2014
@@ -134,8 +134,7 @@ public class MainService implements IPen
                        log.debug("getCurrentRoomClient -1- " + SID);
                        log.debug("getCurrentRoomClient -2- " + streamid);
 
-                       Client currentClient = this.sessionManager
-                                       .getClientByStreamId(streamid, null);
+                       Client currentClient = 
sessionManager.getClientByStreamId(streamid, null);
                        return currentClient;
                } catch (Exception err) {
                        log.error("[getCurrentRoomClient]", err);
@@ -468,8 +467,7 @@ public class MainService implements IPen
                                if (status) {
                                        Map<String, String> message = new 
HashMap<String, String>();
                                        message.put("message", "roomClosed");
-                                       
this.scopeApplicationAdapter.sendMessageByRoomAndDomain(
-                                                       room_id, message);
+                                       
scopeApplicationAdapter.sendMessageByRoomAndDomain(room_id, message);
                                }
 
                                return 1;

Modified: 
openmeetings/trunk/singlewebapp/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java
URL: 
http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java?rev=1644160&r1=1644159&r2=1644160&view=diff
==============================================================================
--- 
openmeetings/trunk/singlewebapp/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java
 (original)
+++ 
openmeetings/trunk/singlewebapp/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java
 Tue Dec  9 19:22:29 2014
@@ -27,6 +27,8 @@ import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.openmeetings.core.remote.red5.ScopeApplicationAdapter;
+import org.apache.openmeetings.core.remote.util.SessionVariablesUtil;
 import org.apache.openmeetings.db.dao.label.FieldLanguagesValuesDao;
 import org.apache.openmeetings.db.dao.room.IRoomManager;
 import org.apache.openmeetings.db.dao.room.RoomDao;
@@ -39,19 +41,14 @@ import org.apache.openmeetings.db.entity
 import org.apache.openmeetings.db.entity.user.Organisation;
 import org.apache.openmeetings.db.entity.user.OrganisationUser;
 import org.apache.openmeetings.db.entity.user.User;
-import org.apache.openmeetings.core.remote.red5.ScopeApplicationAdapter;
-import org.apache.openmeetings.core.remote.util.SessionVariablesUtil;
 import org.red5.logging.Red5LoggerFactory;
-import org.red5.server.api.IClient;
 import org.red5.server.api.IConnection;
 import org.red5.server.api.Red5;
-import org.red5.server.api.service.IPendingServiceCall;
-import org.red5.server.api.service.IPendingServiceCallback;
 import org.red5.server.api.service.IServiceCapableConnection;
 import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 
-public class MobileService implements IPendingServiceCallback {
+public class MobileService {
        private static final Logger log = 
Red5LoggerFactory.getLogger(MainService.class, webAppRootKey);
        @Autowired
        private UserDao userDao;
@@ -68,10 +65,6 @@ public class MobileService implements IP
        @Autowired
        private ScopeApplicationAdapter scopeAdapter;
 
-       @Override
-       public void resultReceived(IPendingServiceCall call) {
-       }
-
        public Map<String, Object> loginUser(String login, String password) {
                Map<String, Object> result = new Hashtable<String, Object>();
                try {
@@ -123,22 +116,20 @@ public class MobileService implements IP
                // Notify all clients of the same scope (room)
                IConnection current = Red5.getConnectionLocal();
                for (IConnection conn : 
current.getScope().getClientConnections()) {
-                       if (conn != null) {
-                               if (conn instanceof IServiceCapableConnection) {
-                                       Client c = 
sessionManager.getClientByStreamId(conn.getClient().getId(), null);
-                                       if (c.getIsAVClient()) {
-                                               Map<String, Object> map = new 
Hashtable<String, Object>();
-                                               map.put("streamId", 
c.getStreamid());
-                                               map.put("broadCastId", 
c.getBroadCastID());
-                                               map.put("userId", 
c.getUser_id() == null ? "" : c.getUser_id());
-                                               map.put("firstname", 
c.getFirstname());
-                                               map.put("lastname", 
c.getLastname());
-                                               map.put("publicSid", 
c.getPublicSID());
-                                               map.put("login", 
c.getUsername());
-                                               map.put("email", c.getEmail() 
== null ? "" : c.getEmail());
-                                               map.put("avsettings", 
c.getAvsettings());
-                                               result.add(map);
-                                       }
+                       if (conn != null && conn instanceof 
IServiceCapableConnection) {
+                               Client c = 
sessionManager.getClientByStreamId(conn.getClient().getId(), null);
+                               if (c.getIsAVClient()) {
+                                       Map<String, Object> map = new 
Hashtable<String, Object>();
+                                       map.put("streamId", c.getStreamid());
+                                       map.put("broadCastId", 
c.getBroadCastID());
+                                       map.put("userId", c.getUser_id() == 
null ? "" : c.getUser_id());
+                                       map.put("firstname", c.getFirstname());
+                                       map.put("lastname", c.getLastname());
+                                       map.put("publicSid", c.getPublicSID());
+                                       map.put("login", c.getUsername());
+                                       map.put("email", c.getEmail() == null ? 
"" : c.getEmail());
+                                       map.put("avsettings", 
c.getAvsettings());
+                                       result.add(map);
                                }
                        }
                }
@@ -205,33 +196,11 @@ public class MobileService implements IP
                sessionManager.updateClientByStreamId(c.getStreamid(), c, 
false, null);
                result.put("broadcastId", broadcastId);
 
-               //FIXME make it async + copy/paste
-               IConnection current = Red5.getConnectionLocal();
-               for (IConnection conn : 
current.getScope().getClientConnections()) {
-                       if (conn != null) {
-                               IClient client = conn.getClient();
-                               if 
(SessionVariablesUtil.isScreenClient(client)) {
-                                       // screen sharing clients do not 
receive events
-                                       continue;
-                               } else if 
(SessionVariablesUtil.isAVClient(client)) {
-                                       // AVClients or potential AVClients do 
not receive events
-                                       continue;
-                               }
-
-                               if 
(!client.getId().equals(current.getClient().getId())) {
-                                       // It is not needed to send back that 
event to the actual Moderator
-                                       // as it will be already triggered in 
the result of this Function in the Client
-                                       if (conn instanceof 
IServiceCapableConnection) {
-                                               ((IServiceCapableConnection) 
conn).invoke("addNewUser", new Object[] { c }, this);
-                                               log.debug("sending Mobile 
client to " + conn);
-                                       }
-                               }
-                       }
-               }
+               scopeAdapter.syncMessageToCurrentScope("addNewUser", c, false, 
false);
                return result;
        }
 
-       public void updateAvMode(String avMode, String width, String height) {
+       public Map<String, Object> updateAvMode(String avMode, String width, 
String height) {
                IConnection current = Red5.getConnectionLocal();
                Client c = 
sessionManager.getClientByStreamId(current.getClient().getId(), null);
                c.setAvsettings(avMode);
@@ -241,22 +210,12 @@ public class MobileService implements IP
                HashMap<String, Object> hsm = new HashMap<String, Object>();
                hsm.put("client", c);
                hsm.put("message", new String[]{"avsettings", "0", avMode});
-
-               //FIXME should be handled async + copy/paste
-               for (IConnection conn : 
current.getScope().getClientConnections()) {
-                       if (conn != null) {
-                               if (conn instanceof IServiceCapableConnection) {
-                                       IClient client = conn.getClient();
-                                       if 
(SessionVariablesUtil.isScreenClient(client)) {
-                                               // screen sharing clients do 
not receive events
-                                               continue;
-                                       } else if 
(SessionVariablesUtil.isAVClient(client)) {
-                                               // AVClients or potential 
AVClients do not receive events
-                                               continue;
-                                       }
-                                       
((IServiceCapableConnection)conn).invoke("sendVarsToMessageWithClient", new 
Object[] { hsm }, this);
-                               }
-                       }
+               Map<String, Object> result = new Hashtable<String, Object>();
+               if (!"n".equals(avMode)) {
+                       result.put("broadcastId", 
scopeAdapter.getBroadCastId());
                }
+
+               
scopeAdapter.syncMessageToCurrentScope("sendVarsToMessageWithClient", hsm, 
true, false);
+               return result;
        }
 }

Modified: 
openmeetings/trunk/singlewebapp/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/red5/ScopeApplicationAdapter.java
URL: 
http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/red5/ScopeApplicationAdapter.java?rev=1644160&r1=1644159&r2=1644160&view=diff
==============================================================================
--- 
openmeetings/trunk/singlewebapp/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/red5/ScopeApplicationAdapter.java
 (original)
+++ 
openmeetings/trunk/singlewebapp/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/red5/ScopeApplicationAdapter.java
 Tue Dec  9 19:22:29 2014
@@ -30,6 +30,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.openmeetings.core.data.calendar.management.AppointmentLogic;
 import org.apache.openmeetings.core.data.conference.RoomManager;
@@ -108,9 +109,7 @@ public class ScopeApplicationAdapter ext
        @Autowired
        private ServerDao serverDao;
 
-       public static String lineSeperator = 
System.getProperty("line.separator");
-
-       private static long broadCastCounter = 0;
+       private static AtomicLong broadCastCounter = new AtomicLong(0);
 
        public synchronized void resultReceived(IPendingServiceCall arg0) {
                // TODO Auto-generated method stub
@@ -247,8 +246,7 @@ public class ScopeApplicationAdapter ext
 
                        List<Client> screenSharerList = new 
LinkedList<Client>();
 
-                       Client currentClient = this.sessionManager
-                                       .getClientByStreamId(streamid, null);
+                       Client currentClient = 
sessionManager.getClientByStreamId(streamid, null);
 
                        for (Client rcl : 
sessionManager.getClientListByRoomAll(currentClient.getRoom_id())) {
                                if (rcl.isStartStreaming()) {
@@ -387,13 +385,10 @@ public class ScopeApplicationAdapter ext
         String streamid = current.getClient().getId();
         for (IConnection conn : current.getScope().getClientConnections()) {
             if (conn != null) {
-                Client rcl = this.sessionManager
-                        .getClientByStreamId(conn
-                                .getClient().getId(), null);
+                Client rcl = 
sessionManager.getClientByStreamId(conn.getClient().getId(), null);
                 if (rcl == null) {
                     // continue;
-                } else if (rcl.getIsScreenClient() != null
-                        && rcl.getIsScreenClient()) {
+                } else if (rcl.getIsScreenClient() != null && 
rcl.getIsScreenClient()) {
                     // continue;
                 } else {
                     if (!streamid.equals(rcl.getStreamid())) {
@@ -563,20 +558,13 @@ public class ScopeApplicationAdapter ext
 
                                                Client rcl = 
sessionManager.getClientByStreamId(cons.getClient().getId(), null);
 
-                                               /*
-                                                * Check if the Client does 
still exist on the
-                                                * list
-                                                */
+                                               // Check if the Client does 
still exist on the list
                                                if (rcl == null) {
                                                        log.debug("For this 
StreamId: " + cons.getClient().getId() + " There is no Client in the List 
anymore");
                                                        continue;
                                                }
                                                
-                                               /*
-                                                * Do not send back to sender, 
but actually
-                                                * all other clients should 
receive this
-                                                * message swagner 01.10.2009
-                                                */
+                                               //Do not send back to sender, 
but actually all other clients should receive this message swagner 01.10.2009
                                                if 
(!currentClient.getStreamid().equals(rcl.getStreamid())) {
                                                        // add Notification if 
another user isrecording
                                                        
log.debug("###########[roomLeave]");
@@ -612,7 +600,7 @@ public class ScopeApplicationAdapter ext
                        }
 
                        if (removeUserFromSessionList) {
-                               
this.sessionManager.removeClient(currentClient.getStreamid(), null);
+                               
sessionManager.removeClient(currentClient.getStreamid(), null);
                        }
                } catch (Exception err) {
                        log.error("[roomLeaveByScope]", err);
@@ -647,7 +635,7 @@ public class ScopeApplicationAdapter ext
 
                                currentClient.setScreenPublishStarted(true);
 
-                               
sessionManager.updateClientByStreamId(current.getClient().getId(), 
currentClient, false, null);
+                               sessionManager.updateClientByStreamId(streamid, 
currentClient, false, null);
                        }
                        //If its an audio/video client then send the session 
object with the full data to everybody
                        else if (currentClient.getIsAVClient()) {
@@ -824,8 +812,7 @@ public class ScopeApplicationAdapter ext
                try {
                        log.debug("-----------  addModerator: " + publicSID);
 
-                       Client currentClient = this.sessionManager
-                                       .getClientByPublicSID(publicSID, false, 
null);
+                       Client currentClient = 
sessionManager.getClientByPublicSID(publicSID, false, null);
 
                        if (currentClient == null) {
                                return -1L;
@@ -834,11 +821,9 @@ public class ScopeApplicationAdapter ext
 
                        currentClient.setIsMod(true);
                        // Put the mod-flag to true for this client
-                       this.sessionManager.updateClientByStreamId(
-                                       currentClient.getStreamid(), 
currentClient, false, null);
+                       
sessionManager.updateClientByStreamId(currentClient.getStreamid(), 
currentClient, false, null);
 
-                       List<Client> currentMods = this.sessionManager
-                                       .getCurrentModeratorByRoom(room_id);
+                       List<Client> currentMods = 
sessionManager.getCurrentModeratorByRoom(room_id);
                        
                        //Send message to all users
                        syncMessageToCurrentScope("setNewModeratorByList", 
currentMods, true);
@@ -855,13 +840,11 @@ public class ScopeApplicationAdapter ext
 
                        IConnection current = Red5.getConnectionLocal();
                        String streamid = current.getClient().getId();
-                       Client currentClient = this.sessionManager
-                                       .getClientByStreamId(streamid, null);
+                       Client currentClient = 
sessionManager.getClientByStreamId(streamid, null);
 
                        @SuppressWarnings("rawtypes")
                        Map cursor = (Map) item;
-                       cursor.put("streamPublishName",
-                                       currentClient.getStreamPublishName());
+                       cursor.put("streamPublishName", 
currentClient.getStreamPublishName());
 
                        // Notify all users of the same Scope
                        for (IConnection conn : 
current.getScope().getClientConnections()) {
@@ -874,8 +857,7 @@ public class ScopeApplicationAdapter ext
                                                } else if 
(SessionVariablesUtil.isAVClient(client)) {
                                                        // AVClients or 
potential AVClients do not receive events
                                                        continue;
-                                               } if (client.getId().equals(
-                                                                       
current.getClient().getId())) {
+                                               } if 
(client.getId().equals(current.getClient().getId())) {
                                                        // don't send back to 
same user
                                                        continue;
                                                }
@@ -895,8 +877,7 @@ public class ScopeApplicationAdapter ext
                        IConnection current = Red5.getConnectionLocal();
                        // String streamid = current.getClient().getId();
 
-                       Client currentClient = this.sessionManager
-                                       .getClientByPublicSID(publicSID, false, 
null);
+                       Client currentClient = 
sessionManager.getClientByPublicSID(publicSID, false, null);
 
                        if (currentClient == null) {
                                return -1L;
@@ -905,11 +886,9 @@ public class ScopeApplicationAdapter ext
 
                        currentClient.setIsMod(false);
                        // Put the mod-flag to true for this client
-                       this.sessionManager.updateClientByStreamId(
-                                       currentClient.getStreamid(), 
currentClient, false, null);
+                       
sessionManager.updateClientByStreamId(currentClient.getStreamid(), 
currentClient, false, null);
 
-                       List<Client> currentMods = this.sessionManager
-                                       .getCurrentModeratorByRoom(room_id);
+                       List<Client> currentMods = 
sessionManager.getCurrentModeratorByRoom(room_id);
 
                        // Notify all clients of the same scope (room)
                        for (IConnection conn : 
current.getScope().getClientConnections()) {
@@ -923,9 +902,7 @@ public class ScopeApplicationAdapter ext
                                                        // AVClients or 
potential AVClients do not receive events
                                                        continue;
                                                }
-                                               ((IServiceCapableConnection) 
conn).invoke(
-                                                       "setNewModeratorByList",
-                                                               new Object[] { 
currentMods }, this);
+                                               ((IServiceCapableConnection) 
conn).invoke("setNewModeratorByList", new Object[] { currentMods }, this);
                                        }
                                }
                        }
@@ -935,8 +912,7 @@ public class ScopeApplicationAdapter ext
                return -1L;
        }
 
-       public synchronized Long setBroadCastingFlag(String publicSID,
-                       boolean value, Integer interviewPodId) {
+       public synchronized Long setBroadCastingFlag(String publicSID, boolean 
value, Integer interviewPodId) {
                try {
                        log.debug("-----------  setBroadCastingFlag: " + 
publicSID);
 
@@ -968,9 +944,7 @@ public class ScopeApplicationAdapter ext
                                                        continue;
                                                }
                                        
-                                               ((IServiceCapableConnection) 
conn).invoke(
-                                                       
"setNewBroadCastingFlag",
-                                                               new Object[] { 
currentClient }, this);
+                                               ((IServiceCapableConnection) 
conn).invoke("setNewBroadCastingFlag", new Object[] { currentClient }, this);
                                        }
                                }
                        }
@@ -987,8 +961,7 @@ public class ScopeApplicationAdapter ext
                        IConnection current = Red5.getConnectionLocal();
                        // String streamid = current.getClient().getId();
 
-                       Client currentClient = this.sessionManager
-                                       .getClientByPublicSID(publicSID, false, 
null);
+                       Client currentClient = 
sessionManager.getClientByPublicSID(publicSID, false, null);
 
                        if (currentClient == null) {
                                return -1L;
@@ -996,33 +969,25 @@ public class ScopeApplicationAdapter ext
 
                        // Put the mod-flag to true for this client
                        currentClient.setMicMuted(false);
-                       this.sessionManager.updateClientByStreamId(
-                                       currentClient.getStreamid(), 
currentClient, false, null);
+                       
sessionManager.updateClientByStreamId(currentClient.getStreamid(), 
currentClient, false, null);
 
                        // Notify all clients of the same scope (room)
                        for (IConnection conn : 
current.getScope().getClientConnections()) {
                                if (conn != null) {
-                                       Client rcl = this.sessionManager
-                                                       
.getClientByStreamId(conn.getClient().getId(), null);
+                                       Client rcl = 
sessionManager.getClientByStreamId(conn.getClient().getId(), null);
                                        if (rcl == null) {
                                                // continue;
-                                       } else if (rcl.getIsScreenClient() != 
null
-                                                       && 
rcl.getIsScreenClient()) {
+                                       } else if (rcl.getIsScreenClient() != 
null && rcl.getIsScreenClient()) {
                                                // continue;
                                        } else {
                                                if (rcl != currentClient) {
                                                        rcl.setMicMuted(true);
-                                                       
this.sessionManager.updateClientByStreamId(
-                                                                       
rcl.getStreamid(), rcl, false, null);
+                                                       
sessionManager.updateClientByStreamId(rcl.getStreamid(), rcl, false, null);
                                                }
-                                               log.debug("Send Flag to Client: 
"
-                                                               + 
rcl.getUsername());
+                                               log.debug("Send Flag to Client: 
" + rcl.getUsername());
                                                if (conn instanceof 
IServiceCapableConnection) {
-                                                       
((IServiceCapableConnection) conn).invoke(
-                                                                       
"receiveExclusiveAudioFlag",
-                                                                       new 
Object[] { currentClient }, this);
-                                                       log.debug("sending 
receiveExclusiveAudioFlag to "
-                                                                       + conn);
+                                                       
((IServiceCapableConnection) conn).invoke("receiveExclusiveAudioFlag", new 
Object[] { currentClient }, this);
+                                                       log.debug("sending 
receiveExclusiveAudioFlag to " + conn);
                                                }
                                        }
                                }
@@ -1112,13 +1077,13 @@ public class ScopeApplicationAdapter ext
         * 
         * @return long broadCastId
         */
-       public synchronized long getBroadCastId() {
+       public long getBroadCastId() {
                try {
                        log.debug("-----------  getBroadCastId");
                        IConnection current = Red5.getConnectionLocal();
                        String streamid = current.getClient().getId();
                        Client client = 
sessionManager.getClientByStreamId(streamid, null);
-                       client.setBroadCastID(broadCastCounter++);
+                       
client.setBroadCastID(broadCastCounter.getAndIncrement());
                        sessionManager.updateClientByStreamId(streamid, client, 
false, null);
                        return client.getBroadCastID();
                } catch (Exception err) {
@@ -1205,18 +1170,13 @@ public class ScopeApplicationAdapter ext
                        if (!room.isAppointment() && room.isModerated()) {
                                // if this is a Moderated Room then the Room 
can be only
                                // locked off by the Moderator Bit
-                               List<Client> clientModeratorListRoom = 
this.sessionManager
-                                               
.getCurrentModeratorByRoom(room_id);
+                               List<Client> clientModeratorListRoom = 
sessionManager.getCurrentModeratorByRoom(room_id);
 
                                // If there is no Moderator yet and we are 
asking for it
                                // then deny it
                                // cause at this moment, the user should wait 
untill a
                                // Moderator enters the Room
-                               if (clientModeratorListRoom.size() == 0) {
-                                       return false;
-                               } else {
-                                       return true;
-                               }
+                               return clientModeratorListRoom.size() != 0;
                        } else {
                                // FIXME: TODO: For Rooms that are created as 
Appointment we
                                // have to check that too
@@ -1804,7 +1764,7 @@ public class ScopeApplicationAdapter ext
                return -1;
        }
 
-       public synchronized int sendMessage(Object newMessage) {
+       public int sendMessage(Object newMessage) {
                try {
                        
                        syncMessageToCurrentScope("sendVarsToMessage", 
newMessage, false);
@@ -1815,7 +1775,7 @@ public class ScopeApplicationAdapter ext
                return 1;
        }
        
-       public synchronized int sendMessageAll(Object newMessage) {
+       public int sendMessageAll(Object newMessage) {
                try {
                        
                        syncMessageToCurrentScope("sendVarsToMessage", 
newMessage, true);
@@ -1840,8 +1800,7 @@ public class ScopeApplicationAdapter ext
 
                        String action = newMessageList.get(0).toString();
 
-                       BrowserStatus browserStatus = (BrowserStatus) 
current.getScope()
-                                       .getAttribute("browserStatus");
+                       BrowserStatus browserStatus = (BrowserStatus) 
current.getScope().getAttribute("browserStatus");
 
                        if (browserStatus == null) {
                                browserStatus = new BrowserStatus();
@@ -1868,7 +1827,7 @@ public class ScopeApplicationAdapter ext
         * wrapper method
         * @param newMessage
         */
-       public synchronized void sendMessageToMembers(Object newMessage) {
+       public void sendMessageToMembers(Object newMessage) {
                //Sync to all users of current scope
                syncMessageToCurrentScope("sendVarsToMessage", newMessage, 
false);
        }
@@ -1887,7 +1846,7 @@ public class ScopeApplicationAdapter ext
         * @param newMessage parameters
         * @param sendSelf send to the current client as well
         */
-       public synchronized void syncMessageToCurrentScope(String 
remoteMethodName, Object newMessage, boolean sendSelf) {
+       public void syncMessageToCurrentScope(String remoteMethodName, Object 
newMessage, boolean sendSelf) {
                syncMessageToCurrentScope(remoteMethodName, newMessage, 
sendSelf, false);
        }
        
@@ -1900,7 +1859,7 @@ public class ScopeApplicationAdapter ext
         * @return true
         */
        @Deprecated
-       public synchronized boolean loadTestSyncMessage(String 
remoteMethodName, Object newMessage, boolean sendSelf) {
+       public boolean loadTestSyncMessage(String remoteMethodName, Object 
newMessage, boolean sendSelf) {
                syncMessageToCurrentScope(remoteMethodName, newMessage, 
sendSelf, false);
                return true;
        }
@@ -1921,32 +1880,31 @@ public class ScopeApplicationAdapter ext
         * @param sendSelf send to the current client as well
         * @param sendScreen send to the current client as well
         */
-       public synchronized void syncMessageToCurrentScope(String 
remoteMethodName, Object newMessage, boolean sendSelf, boolean sendScreen) {
+       public void syncMessageToCurrentScope(final String remoteMethodName, 
final Object newMessage, final boolean sendSelf, final boolean sendScreen) {
                try {
-                       IConnection current = Red5.getConnectionLocal();
+                       final IConnection current = Red5.getConnectionLocal();
 
-                       // Send to all Clients of that Scope(Room)
-                       for (IConnection conn : 
current.getScope().getClientConnections()) {
-                               if (conn != null) {
-                                       if (conn instanceof 
IServiceCapableConnection) {
-                                               IClient client = 
conn.getClient();
-                                               if (!sendScreen && 
SessionVariablesUtil.isScreenClient(client)) {
-                                                       // screen sharing 
clients do not receive events
-                                                       continue;
-                                               } else if 
(SessionVariablesUtil.isAVClient(client)) {
-                                                       // AVClients or 
potential AVClients do not receive events
-                                                       continue;
-                                               } else if (!sendSelf && 
client.getId().equals(
-                                                               
current.getClient().getId())) {
-                                                       //Do not send back to 
self
-                                                       continue;
+                       new Thread(new Runnable() {
+                           public void run() {
+                                       for (IConnection conn : 
current.getScope().getClientConnections()) {
+                                               if (conn != null && conn 
instanceof IServiceCapableConnection) {
+                                                       IClient client = 
conn.getClient();
+                                                       if (!sendScreen && 
SessionVariablesUtil.isScreenClient(client)) {
+                                                               // screen 
sharing clients do not receive events
+                                                               continue;
+                                                       } else if 
(SessionVariablesUtil.isAVClient(client)) {
+                                                               // AVClients or 
potential AVClients do not receive events
+                                                               continue;
+                                                       } else if (!sendSelf && 
client.getId().equals(current.getClient().getId())) {
+                                                               //Do not send 
back to self
+                                                               continue;
+                                                       }
+                                                       
((IServiceCapableConnection) conn).invoke(remoteMethodName, new Object[] { 
newMessage }, ScopeApplicationAdapter.this);
                                                }
-                                               ((IServiceCapableConnection) 
conn).invoke(
-                                                               
remoteMethodName, new Object[] { newMessage }, this);
-                                               
                                        }
-                               }
-                       }
+                           }
+                       }).start();
+                       // Send to all Clients of that Scope(Room)
                } catch (Exception err) {
                        log.error("[syncMessageToCurrentScope]", err);
                }
@@ -1957,7 +1915,7 @@ public class ScopeApplicationAdapter ext
         * @param newMessage
         * @return 1 in case of success, -1 otherwise
         */
-       public synchronized int sendMessageWithClient(Object newMessage) {
+       public int sendMessageWithClient(Object newMessage) {
                try {
                        sendMessageWithClientWithSyncObject(newMessage, true);
 
@@ -1977,8 +1935,7 @@ public class ScopeApplicationAdapter ext
        public synchronized int sendMessageWithClientWithSyncObject(Object 
newMessage, boolean sync) {
                try {
                        IConnection current = Red5.getConnectionLocal();
-                       Client currentClient = this.sessionManager
-                                       
.getClientByStreamId(current.getClient().getId(), null);
+                       Client currentClient = 
sessionManager.getClientByStreamId(current.getClient().getId(), null);
 
                        HashMap<String, Object> hsm = new HashMap<String, 
Object>();
                        hsm.put("client", currentClient);
@@ -2002,8 +1959,7 @@ public class ScopeApplicationAdapter ext
         * @param clientId
         * @return 1 in case of success, -1 otherwise
         */
-       public synchronized int sendMessageById(Object newMessage, String 
clientId,
-                       IScope scope) {
+       public synchronized int sendMessageById(Object newMessage, String 
clientId, IScope scope) {
                try {
                        log.debug("### sendMessageById ###" + clientId);
 
@@ -2015,9 +1971,7 @@ public class ScopeApplicationAdapter ext
                                if (conn != null) {
                                        if (conn instanceof 
IServiceCapableConnection) {
                                                if 
(conn.getClient().getId().equals(clientId)) {
-                                                       
((IServiceCapableConnection) conn).invoke(
-                                                                       
"sendVarsToMessageWithClient",
-                                                                       new 
Object[] { hsm }, this);
+                                                       
((IServiceCapableConnection) conn).invoke("sendVarsToMessageWithClient", new 
Object[] { hsm }, this);
                                                }
                                        }
                                }
@@ -2039,8 +1993,7 @@ public class ScopeApplicationAdapter ext
        public synchronized int sendMessageWithClientById(Object newMessage, 
String clientId) {
                try {
                        IConnection current = Red5.getConnectionLocal();
-                       Client currentClient = this.sessionManager
-                                       
.getClientByStreamId(current.getClient().getId(), null);
+                       Client currentClient = 
sessionManager.getClientByStreamId(current.getClient().getId(), null);
 
                        HashMap<String, Object> hsm = new HashMap<String, 
Object>();
                        hsm.put("client", currentClient);
@@ -2049,9 +2002,7 @@ public class ScopeApplicationAdapter ext
                        // broadcast Message to specific user with id inside 
the same Scope
                        for (IConnection conn : 
current.getScope().getClientConnections()) {
                                if (conn.getClient().getId().equals(clientId)) {
-                                       ((IServiceCapableConnection) 
conn).invoke(
-                                                       
"sendVarsToMessageWithClient",
-                                                       new Object[] { hsm }, 
this);
+                                       ((IServiceCapableConnection) 
conn).invoke("sendVarsToMessageWithClient", new Object[] { hsm }, this);
                                }
                        }
                } catch (Exception err) {
@@ -2065,14 +2016,12 @@ public class ScopeApplicationAdapter ext
                try {
                        //if the upload is locally, just proceed to the normal 
function
                        //Search for RoomClient on current server (serverId == 
null means it will look on the master for the RoomClient)
-                       Client currentClient = this.sessionManager
-                                                               
.getClientByPublicSID(publicSID, false, null);
+                       Client currentClient = 
sessionManager.getClientByPublicSID(publicSID, false, null);
                        
                        if (currentClient != null) {
                                sendMessageWithClientByPublicSID(message, 
publicSID);
                        } else {
-                               throw new Exception(
-                                               "Could not Find RoomClient on 
List publicSID: "+ publicSID);
+                               throw new Exception("Could not Find RoomClient 
on List publicSID: "+ publicSID);
                        }
                        
                } catch (Exception err) {
@@ -2081,25 +2030,20 @@ public class ScopeApplicationAdapter ext
        }
        
 
-       public synchronized void sendMessageWithClientByPublicSID(Object 
message,
-                       String publicSID) {
+       public synchronized void sendMessageWithClientByPublicSID(Object 
message, String publicSID) {
                try {
                        // ApplicationContext appCtx = 
getContext().getApplicationContext();
                        IScope globalScope = getContext().getGlobalScope();
 
-                       IScope webAppKeyScope = globalScope
-                                       
.getScope(OpenmeetingsVariables.webAppRootKey);
+                       IScope webAppKeyScope = 
globalScope.getScope(OpenmeetingsVariables.webAppRootKey);
 
                        // log.debug("webAppKeyScope "+webAppKeyScope);
 
                        // Get Room Id to send it to the correct Scope
-                       Client currentClient = this.sessionManager
-                                       .getClientByPublicSID(publicSID, false, 
null);
+                       Client currentClient = 
sessionManager.getClientByPublicSID(publicSID, false, null);
 
                        if (currentClient == null) {
-                               throw new Exception(
-                                               "Could not Find RoomClient on 
List publicSID: "
-                                                               + publicSID);
+                               throw new Exception("Could not Find RoomClient 
on List publicSID: " + publicSID);
                        }
                        // default Scope Name
                        String scopeName = "hibernate";
@@ -2136,21 +2080,10 @@ public class ScopeApplicationAdapter ext
                }
        }
 
-       public synchronized void sendMessageWithClientByPublicSIDOrUser(
-                       Object message, String publicSID, Long user_id) {
+       public synchronized void sendMessageWithClientByPublicSIDOrUser(Object 
message, String publicSID, Long user_id) {
                try {
-                       // ApplicationContext appCtx = 
getContext().getApplicationContext();
-
-                       IScope globalScope = getContext().getGlobalScope();
-
-                       IScope webAppKeyScope = globalScope
-                                       
.getScope(OpenmeetingsVariables.webAppRootKey);
-
-                       // log.debug("webAppKeyScope "+webAppKeyScope);
-
                        // Get Room Id to send it to the correct Scope
-                       Client currentClient = this.sessionManager
-                                       .getClientByPublicSID(publicSID, false, 
null);
+                       Client currentClient = 
sessionManager.getClientByPublicSID(publicSID, false, null);
 
                        if (currentClient == null) {
                                currentClient = 
sessionManager.getClientByUserId(user_id);
@@ -2159,8 +2092,7 @@ public class ScopeApplicationAdapter ext
                        Set<IConnection> conset = null;
 
                        if (currentClient == null) {
-                               // Must be from a previous session, search for 
user in current
-                               // scope
+                               // Must be from a previous session, search for 
user in current scope
                                IConnection current = Red5.getConnectionLocal();
                                // Notify all Clients of that Scope (Room)
                                conset = 
current.getScope().getClientConnections();
@@ -2171,17 +2103,16 @@ public class ScopeApplicationAdapter ext
                                        scopeName = 
currentClient.getRoom_id().toString();
                                }
 
+                               IScope globalScope = 
getContext().getGlobalScope();
+                               IScope webAppKeyScope = 
globalScope.getScope(OpenmeetingsVariables.webAppRootKey);
                                IScope scopeHibernate = 
webAppKeyScope.getScope(scopeName);
 
                                if (scopeHibernate != null) {
-                                       conset = 
webAppKeyScope.getScope(scopeName).getClientConnections();
+                                       conset = 
scopeHibernate.getClientConnections();
                                }
                        }
 
-                       // log.debug("scopeHibernate "+scopeHibernate);
-
                        // Notify the clients of the same scope (room) with 
user_id
-
                        for (IConnection conn : conset) {
                                if (conn != null) {
                                        
@@ -2196,18 +2127,11 @@ public class ScopeApplicationAdapter ext
                                        
                                        if 
(SessionVariablesUtil.getPublicSID(client).equals(publicSID)) {
                                                // log.debug("IS EQUAL ");
-                                               ((IServiceCapableConnection) 
conn).invoke(
-                                                               
"newMessageByRoomAndDomain",
-                                                               new Object[] { 
message }, this);
-                                               
log.debug("sendMessageWithClientByPublicSID RPC:newMessageByRoomAndDomain"
-                                                               + message);
-                                       } else if (user_id != 0
-                                                       && 
SessionVariablesUtil.getUserId(client).equals(user_id)) {
-                                               ((IServiceCapableConnection) 
conn).invoke(
-                                                               
"newMessageByRoomAndDomain",
-                                                               new Object[] { 
message }, this);
-                                               
log.debug("sendMessageWithClientByPublicSID RPC:newMessageByRoomAndDomain"
-                                                               + message);
+                                               ((IServiceCapableConnection) 
conn).invoke("newMessageByRoomAndDomain", new Object[] { message }, this);
+                                               
log.debug("sendMessageWithClientByPublicSID RPC:newMessageByRoomAndDomain" + 
message);
+                                       } else if (user_id != 0 && 
SessionVariablesUtil.getUserId(client).equals(user_id)) {
+                                               ((IServiceCapableConnection) 
conn).invoke("newMessageByRoomAndDomain", new Object[] { message }, this);
+                                               
log.debug("sendMessageWithClientByPublicSID RPC:newMessageByRoomAndDomain" + 
message);
                                        }
                                }
                        }
@@ -2282,9 +2206,7 @@ public class ScopeApplicationAdapter ext
                                                continue;
                                        }
 
-                                       ((IServiceCapableConnection) 
conn).invoke(
-                                                       "interviewStatus",
-                                                       new Object[] { 
interviewStatus }, this);
+                                       ((IServiceCapableConnection) 
conn).invoke("interviewStatus", new Object[] { interviewStatus }, this);
                                        log.debug("-- startInterviewRecording " 
+ interviewStatus);
                                }
                        }
@@ -2300,8 +2222,7 @@ public class ScopeApplicationAdapter ext
        }
 
        @SuppressWarnings({ "rawtypes" })
-       public synchronized Boolean sendRemoteCursorEvent(String streamid,
-                       Map messageObj) {
+       public synchronized Boolean sendRemoteCursorEvent(String streamid, Map 
messageObj) {
                try {
 
                        IConnection current = Red5.getConnectionLocal();
@@ -2311,9 +2232,7 @@ public class ScopeApplicationAdapter ext
                                        IClient client = conn.getClient();
                                        if 
(SessionVariablesUtil.isScreenClient(client)) {
                                                if 
(conn.getClient().getId().equals(streamid)) {
-                                                       
((IServiceCapableConnection) conn).invoke(
-                                                                       
"sendRemoteCursorEvent",
-                                                                       new 
Object[] { messageObj }, this);
+                                                       
((IServiceCapableConnection) conn).invoke("sendRemoteCursorEvent", new Object[] 
{ messageObj }, this);
                                                }
                                        }
                                }
@@ -2431,8 +2350,7 @@ public class ScopeApplicationAdapter ext
                try {
 
                        IScope globalScope = getContext().getGlobalScope();
-                       IScope webAppKeyScope = globalScope
-                                       
.getScope(OpenmeetingsVariables.webAppRootKey);
+                       IScope webAppKeyScope = 
globalScope.getScope(OpenmeetingsVariables.webAppRootKey);
 
                        String scopeName = "hibernate";
                        // If set then its a NON default Scope
@@ -2511,11 +2429,8 @@ public class ScopeApplicationAdapter ext
                Client currentClient = 
sessionManager.getClientByStreamId(streamid, null);
                try {
                        String sipNumber = 
getSipNumber(currentClient.getRoom_id());
-                       log.debug("asterisk -rx \"originate Local/" + number + 
"@rooms-out extension " + sipNumber
-                                       + "@rooms-originate\"");
-                       Runtime.getRuntime().exec(
-                                       new String[] { "asterisk", "-rx",
-                                                       "originate Local/" + 
number + "@rooms-out extension " + sipNumber + "@rooms-originate" });
+                       log.debug("asterisk -rx \"originate Local/" + number + 
"@rooms-out extension " + sipNumber + "@rooms-originate\"");
+                       Runtime.getRuntime().exec(new String[] { "asterisk", 
"-rx", "originate Local/" + number + "@rooms-out extension " + sipNumber + 
"@rooms-originate" });
                } catch (IOException e) {
                        log.error("Executing asterisk originate error: ", e);
                }
@@ -2562,7 +2477,7 @@ public class ScopeApplicationAdapter ext
                                        continue;
                                }
 
-                               if 
(!client.getId().equals(current.getClient().getId())) {
+                               if (!client.getId().equals(streamid)) {
                                        // It is not needed to send back that 
event to the actual Moderator
                                        // as it will be already triggered in 
the result of this Function in the Client
                                        if (conn instanceof 
IServiceCapableConnection) {


Reply via email to