openmeetings-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebawag...@apache.org
Subject svn commit: r1441303 - in /openmeetings/trunk/singlewebapp/src/org/apache/openmeetings: data/beans/basic/ remote/ session/ session/store/ test/session/
Date Fri, 01 Feb 2013 03:30:52 GMT
Author: sebawagner
Date: Fri Feb  1 03:30:52 2013
New Revision: 1441303

URL: http://svn.apache.org/viewvc?rev=1441303&view=rev
Log:
OPENMEETINGS-460 Fixing some issues in the memory based session by reverting it to a single
map

Added:
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/session/TestHashMapSession.java
Modified:
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/beans/basic/SearchResult.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/remote/ConferenceService.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/ISessionManager.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/SessionManager.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/store/DatabaseStore.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/store/HashMapStore.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/store/IClientPersistenceStore.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/session/TestDbSession.java

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/beans/basic/SearchResult.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/beans/basic/SearchResult.java?rev=1441303&r1=1441302&r2=1441303&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/beans/basic/SearchResult.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/beans/basic/SearchResult.java
Fri Feb  1 03:30:52 2013
@@ -18,12 +18,13 @@
  */
 package org.apache.openmeetings.data.beans.basic;
 
-import java.util.List;
+import java.util.Collection;
+
 
 public class SearchResult<T> {
 	private String objectName;
 	private Long records;
-	private List<T> result;
+	private Collection<T> result;
 	private Long errorId;
 	
 	public String getObjectName() {
@@ -38,10 +39,10 @@ public class SearchResult<T> {
 	public void setRecords(Long records) {
 		this.records = records;
 	}
-	public List<T> getResult() {
+	public Collection<T> getResult() {
 		return result;
 	}
-	public void setResult(List<T> result) {
+	public void setResult(Collection<T> result) {
 		this.result = result;
 	}
 	public Long getErrorId() {

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/remote/ConferenceService.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/remote/ConferenceService.java?rev=1441303&r1=1441302&r2=1441303&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/remote/ConferenceService.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/remote/ConferenceService.java
Fri Feb  1 03:30:52 2013
@@ -51,7 +51,6 @@ import org.apache.openmeetings.persisten
 import org.apache.openmeetings.persistence.beans.rooms.Rooms_Organisation;
 import org.apache.openmeetings.persistence.beans.user.Users;
 import org.apache.openmeetings.session.ISessionManager;
-import org.apache.openmeetings.session.ServerSession;
 import org.apache.openmeetings.utils.math.CalendarPatterns;
 import org.apache.openmeetings.utils.math.TimezoneUtil;
 import org.red5.logging.Red5LoggerFactory;
@@ -696,7 +695,7 @@ public class ConferenceService {
 	 * @param asc
 	 * @return - list of the connections currently open
 	 */
-	public SearchResult<ServerSession> getRoomClientsMap(String SID, int start, int max,
+	public SearchResult<Client> getRoomClientsMap(String SID, int start, int max,
 			String orderby, boolean asc) {
 		try {
 			Long users_id = sessionManagement.checkSession(SID);

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/ISessionManager.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/ISessionManager.java?rev=1441303&r1=1441302&r2=1441303&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/ISessionManager.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/ISessionManager.java
Fri Feb  1 03:30:52 2013
@@ -35,6 +35,12 @@ import org.apache.openmeetings.remote.re
  *
  */
 public interface ISessionManager {
+	
+	/**
+	 * Notified on server start, when the session manager should be started and
+	 * eventually caches cleared/setup
+	 */
+	public abstract void sessionStart();
 
 	/**
 	 * Get current clients and extends the room client with its potential
@@ -175,7 +181,7 @@ public interface ISessionManager {
 	 * @param asc
 	 * @return
 	 */
-	public abstract SearchResult<ServerSession> getListByStartAndMax(int start,
+	public abstract SearchResult<Client> getListByStartAndMax(int start,
 			int max, String orderby, boolean asc);
 
 	/**

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/SessionManager.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/SessionManager.java?rev=1441303&r1=1441302&r2=1441303&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/SessionManager.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/SessionManager.java
Fri Feb  1 03:30:52 2013
@@ -25,7 +25,6 @@ import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map.Entry;
@@ -94,6 +93,7 @@ public class SessionManager implements I
 				rcm.setPublicSID(manageCryptStyle.getInstanceOfCrypt()
 						.createPassPhrase(String.valueOf(random).toString()));
 
+				//rcm.setServer(server);
 				rcm.setUserport(remotePort);
 				rcm.setUserip(remoteAddress);
 				rcm.setSwfurl(swfUrl);
@@ -321,21 +321,12 @@ public class SessionManager implements I
 		}
 
 		// FIXME not sorted
-		public synchronized SearchResult<ServerSession> getListByStartAndMax(
+		public synchronized SearchResult<Client> getListByStartAndMax(
 				int start, int max, String orderby, boolean asc) {
-			SearchResult<ServerSession> sResult = new SearchResult<ServerSession>();
+			SearchResult<Client> sResult = new SearchResult<Client>();
 			sResult.setObjectName(Client.class.getName());
 			sResult.setRecords(Long.valueOf(cache.size()).longValue());
-			ArrayList<ServerSession> myList = new ArrayList<ServerSession>(cache.size());
-			
-			//FIXME: Improve the handling of the Arrays/Map/List so that this re-parsing is not needed
-			for (Entry<Long, LinkedHashMap<String, Client>> entry : cache.values().entrySet())
{
-				for (Client rcl : entry.getValue().values()) {
-					myList.add(new ServerSession(entry.getKey(), rcl));
-				}
-			}
-			
-			sResult.setResult(myList);
+			sResult.setResult(cache.values());
 			return sResult;
 		}
 
@@ -370,11 +361,12 @@ public class SessionManager implements I
 		
 		
 		public String getSessionStatistics() {
-			return cache.getDebugInformation(Arrays.asList(IClientPersistenceStore.DEBUG_DETAILS.SIZE,
-							IClientPersistenceStore.DEBUG_DETAILS.CLIENT_BY_STREAMID,
-							IClientPersistenceStore.DEBUG_DETAILS.CLIENT_BY_PUBLICSID,
-							IClientPersistenceStore.DEBUG_DETAILS.CLIENT_BY_USERID,
-							IClientPersistenceStore.DEBUG_DETAILS.CLIENT_BY_ROOMID));
+			return cache.getDebugInformation(Arrays.asList(IClientPersistenceStore.DEBUG_DETAILS.SIZE));
+		}
+
+		public void sessionStart() {
+			// TODO Auto-generated method stub
+			
 		}
 		
 	};
@@ -449,7 +441,7 @@ public class SessionManager implements I
 		return sessionManager.getCurrentModeratorByRoom(room_id);
 	}
 
-	public SearchResult<ServerSession> getListByStartAndMax(int start, int max,
+	public SearchResult<Client> getListByStartAndMax(int start, int max,
 			String orderby, boolean asc) {
 		return sessionManager.getListByStartAndMax(start, max, orderby, asc);
 	}
@@ -473,4 +465,8 @@ public class SessionManager implements I
 		return sessionManager.getSessionStatistics();
 	}
 
+	public void sessionStart() {
+		sessionManager.sessionStart();
+	}
+
 }

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/store/DatabaseStore.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/store/DatabaseStore.java?rev=1441303&r1=1441302&r2=1441303&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/store/DatabaseStore.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/store/DatabaseStore.java
Fri Feb  1 03:30:52 2013
@@ -19,11 +19,13 @@
 package org.apache.openmeetings.session.store;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.openmeetings.data.basic.dao.ServerDao;
 import org.apache.openmeetings.data.conference.dao.ClientDao;
 import org.apache.openmeetings.persistence.beans.basic.Server;
 import org.apache.openmeetings.persistence.beans.rooms.Client;
@@ -34,6 +36,16 @@ public class DatabaseStore implements IC
 	@Autowired
 	private ClientDao clientDao;
 	
+	@Autowired
+	private ServerDao serverDao;
+	
+	public void clearCache() {
+		
+		List<Server> serverList = serverDao.getActiveServers();
+		
+		//clientDao.cleanUpClientsWithoutReference();
+	}
+	
 	public void put(String streamId, Client rcl) {
 		clientDao.add(rcl);
 	}
@@ -106,13 +118,13 @@ public class DatabaseStore implements IC
 		return 0;
 	}
 
-	public LinkedHashMap<Long, LinkedHashMap<String, Client>> getClientsByServerAndRoom(
+	public LinkedHashMap<Long, Collection<Client>> getClientsByServerAndRoom(
 			Server server) {
 		// TODO Auto-generated method stub
 		return null;
 	}
 
-	public LinkedHashMap<Long, LinkedHashMap<String, Client>> values() {
+	public Collection<Client> values() {
 		// TODO Auto-generated method stub
 		return null;
 	}

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/store/HashMapStore.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/store/HashMapStore.java?rev=1441303&r1=1441302&r2=1441303&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/store/HashMapStore.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/store/HashMapStore.java
Fri Feb  1 03:30:52 2013
@@ -19,11 +19,11 @@
 package org.apache.openmeetings.session.store;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 
 import org.apache.openmeetings.OpenmeetingsVariables;
 import org.apache.openmeetings.persistence.beans.basic.Server;
@@ -35,12 +35,6 @@ import org.slf4j.Logger;
  * Stores the session in the memory.
  * Is NOT designed to be clustered across multiple servers.
  * 
- * This is actually some maps, a single map is not enough, cause we have
- * multiple keys and multiple views on that list.
- * 
- * There are multiple ways to organize a Map by multiple keys, one is to have 
- * multiple lists, for every key needed, there is a separated list.
- * 
  * <ul>
  * <li>client by streamid</li>
  * <li>client by publicSID</li>
@@ -57,45 +51,12 @@ public class HashMapStore implements ICl
 	protected static final Logger log = Red5LoggerFactory.getLogger(
 			HashMapStore.class, OpenmeetingsVariables.webAppRootKey);
 	
-	/**
-	 * global client list by serverId and streamid
-	 */
-	private LinkedHashMap<Long, LinkedHashMap<String, Client>> clientsByServer =
new LinkedHashMap<Long, LinkedHashMap<String, Client>>();
-
-	/**
-	 * global client list by serverId and publicSID, there can be multiple
-	 * RoomClients with the same publicSID, the ScreenSharing client has the
-	 * same publicSID as the normal client
-	 */
-	private LinkedHashMap<Long, LinkedHashMap<String, List<Client>>> clientsByServerAndPublicSID
= new LinkedHashMap<Long, LinkedHashMap<String, List<Client>>>();
-
-	/**
-	 * global client list by serverId and userId, there can be multiple
-	 * RoomClients with the same userId, the ScreenSharing client has the
-	 * same userId as the normal client
-	 */
-	private LinkedHashMap<Long, LinkedHashMap<Long, List<Client>>> clientsByServerAndUserId
= new LinkedHashMap<Long, LinkedHashMap<Long, List<Client>>>();
-
-	/**
-	 * global client list by serverId and roomId
-	 * 
-	 * It is internally a HashMap, not a simple list to make sure the order does not change
-	 */
-	private LinkedHashMap<Long, LinkedHashMap<Long, LinkedHashMap<String, Client>>>
clientsByServerAndRoomId = new LinkedHashMap<Long, LinkedHashMap<Long, LinkedHashMap<String,
Client>>>();
-
-	/**
-	 * global client list by server and roomId
-	 */
 	
-	/**
-	 * An empty Map to be returned instead of null
-	 */
-	private LinkedHashMap<String, Client> EMPTY_MAP = new LinkedHashMap<String, Client>(0);
-	
-	/**
-	 * An empty List to be returned instead of null
-	 */
-	private List<Client> EMPTY_LIST = new ArrayList<Client>(0);
+	private LinkedHashMap<String, Client> clientsByStreamId = new LinkedHashMap<String,
Client>();
+
+	public void clearCache() {
+		// Nothing todo here
+	}
 	
 	/**
 	 * null means its locally
@@ -111,302 +72,89 @@ public class HashMapStore implements ICl
 	}
 
 	public void put(String streamId, Client rcl) {
-
-		// By server and streamid
-		Server server = rcl.getServer();
 		
-		//Server and streamId are always given, if server is null, it means the user is locally
-		//and not on any slave host
-		LinkedHashMap<String, Client> clientList = clientsByServer.get(getIdByServer(server));
-		if (clientList == null) {
-			clientList = new LinkedHashMap<String, Client>();
-		}
-		clientList.put(streamId, rcl);
-		clientsByServer.put(getIdByServer(server), clientList);
+		clientsByStreamId.put(rcl.getStreamid(), rcl);
 
-		// By publicSID
-		
-		//publicSID id might be null and then change to something, 
-		//but we will not want to search for a user with the publicSID == null
-		//so as long as publicSID is null, we don't organize the session on a special list
-		if (rcl.getPublicSID() != null) {
-			LinkedHashMap<String, List<Client>> clientListPublicSID = clientsByServerAndPublicSID
-					.get(getIdByServer(server));
-			if (clientListPublicSID == null) {
-				clientListPublicSID = new LinkedHashMap<String, List<Client>>();
-			}
-			List<Client> clientsByPublicSIDList = clientListPublicSID.get(rcl
-					.getPublicSID());
-			if (clientsByPublicSIDList == null) {
-				clientsByPublicSIDList = new ArrayList<Client>();
-			}
-			if (!clientsByPublicSIDList.contains(rcl)) {
-				clientsByPublicSIDList.add(rcl);
-				clientListPublicSID.put(rcl.getPublicSID(), clientsByPublicSIDList);
-				clientsByServerAndPublicSID.put(getIdByServer(server), clientListPublicSID);
-			}
-		}
-		
-		// By userId
-		
-		//user id might be null and then change to something, 
-		//but we will not want to search for a user with the userId == null
-		//so as long as userId is null, we don't organize the session on a special list
-		if (rcl.getUser_id() != null) {
-			LinkedHashMap<Long, List<Client>> clientListUserId = clientsByServerAndUserId
-					.get(getIdByServer(server));
-			if (clientListUserId == null) {
-				clientListUserId = new LinkedHashMap<Long, List<Client>>();
-			}
-			List<Client> clientListUserIdList = clientListUserId.get(rcl
-					.getPublicSID());
-			if (clientListUserIdList == null) {
-				clientListUserIdList = new ArrayList<Client>();
-			}
-			if (!clientListUserIdList.contains(rcl)) {
-				clientListUserIdList.add(rcl);
-				clientListUserId.put(rcl.getUser_id(), clientListUserIdList);
-				clientsByServerAndUserId.put(getIdByServer(server), clientListUserId);
-			}
-		}
-
-		// By roomId
-		
-		//room id might be null and then change to something, 
-		//but we will not want to search for a user with the roomId == null
-		//so as long as roomId is null, we don't organize the session on a special list
-		if (rcl.getRoom_id() != null) {
-			LinkedHashMap<Long, LinkedHashMap<String, Client>> clientsByRoomId = clientsByServerAndRoomId.get(getIdByServer(server));
-			if (clientsByRoomId == null) {
-				clientsByRoomId = new LinkedHashMap<Long, LinkedHashMap<String, Client>>();
-			}
-			LinkedHashMap<String, Client> clientRoomList = clientsByRoomId.get(rcl
-					.getRoom_id());
-			if (clientRoomList == null) {
-				clientRoomList = new LinkedHashMap<String, Client>();
-			}
-			if (!clientRoomList.containsKey((streamId))) {
-				clientRoomList.put(streamId, rcl);
-				clientsByRoomId.put(rcl.getRoom_id(), clientRoomList);
-			}
-			clientsByServerAndRoomId.put(getIdByServer(server), clientsByRoomId);
-		}
 	}
 
 	public boolean containsKey(Server server, String streamId) {
-		if (clientsByServer.containsKey(getIdByServer(server))) {
-			return clientsByServer.get(getIdByServer(server)).containsKey(streamId);
-		}
-		return false;
+		return clientsByStreamId.containsKey(streamId);
 	}
 
 	public Client get(Server server, String streamId) {
-		LinkedHashMap<String, Client> listMap = clientsByServer.get(getIdByServer(server));
-		if (listMap != null) {
-			return listMap.get(streamId);
-		}
-		return null;
+		return clientsByStreamId.get(streamId);
 	}
 	
 	public List<Client> getClientsByPublicSID(Server server, String publicSID) {
-		LinkedHashMap<String, List<Client>> clientListPublicSID = clientsByServerAndPublicSID.get(getIdByServer(server));
-		if (clientListPublicSID == null) {
-			return EMPTY_LIST;
-		}
-		List<Client> clientList = clientListPublicSID.get(publicSID);
-		if (clientList == null) {
-			return EMPTY_LIST;
+		List<Client> clientList = new ArrayList<Client>();
+		for (Client cl : clientsByStreamId.values()) {
+			if (cl.getPublicSID().equals(publicSID)) {
+				clientList.add(cl);
+			}
 		}
 		return clientList;
 	}
 	
 	public Map<Long,List<Client>> getClientsByPublicSID(String publicSID) {
-		Map<Long,List<Client>> clientList = new HashMap<Long,List<Client>>();
-		for (Entry<Long, LinkedHashMap<String, List<Client>>> entry : clientsByServerAndPublicSID.entrySet())
{
-			List<Client> clientListAtThisServer = entry.getValue().get(publicSID);
-			if (clientListAtThisServer != null) {
-				clientList.put(entry.getKey(), clientListAtThisServer);
+		Map<Long,List<Client>> clientMapList = new HashMap<Long,List<Client>>();
+		List<Client> clientList = new ArrayList<Client>();
+		for (Client cl : clientsByStreamId.values()) {
+			if (cl.getPublicSID().equals(publicSID)) {
+				clientList.add(cl);
 			}
 		}
-		return clientList;
+		clientMapList.put(null, clientList);
+		return clientMapList;
 	}
 	
 	public LinkedHashMap<String, Client> getClientsByServer(Server server) {
-		LinkedHashMap<String, Client> listMap = clientsByServer.get(getIdByServer(server));
-		if (listMap == null) {
-			return EMPTY_MAP;
-		}
-		return listMap;
+		return clientsByStreamId;
 	}
 	
 	public List<Client> getClientsByUserId(Server server, Long userId) {
-		LinkedHashMap<Long, List<Client>> clientListUserId = clientsByServerAndUserId.get(getIdByServer(server));
-		if (clientListUserId == null) {
-			return EMPTY_LIST;
-		}
-		List<Client> clientList = clientListUserId.get(userId);
-		if (clientList == null) {
-			return EMPTY_LIST;
+		List<Client> clientList = new ArrayList<Client>();
+		for (Client cl : clientsByStreamId.values()) {
+			if (cl.getUser_id().equals(userId)) {
+				clientList.add(cl);
+			}
 		}
 		return clientList;
 	}
 	
 	public  LinkedHashMap<String, Client> getClientsByRoomId(Long roomId) {
-		
-		for (Entry<Long, LinkedHashMap<Long, LinkedHashMap<String, Client>>>
entry : clientsByServerAndRoomId.entrySet()) {
-			LinkedHashMap<String, Client> roomClients = entry.getValue().get(roomId);
-			if (roomClients != null) {
-				return roomClients;
+		LinkedHashMap<String,Client> clientList = new LinkedHashMap<String, Client>();
+		for (Client cl : clientsByStreamId.values()) {
+			if (cl.getRoom_id().equals(roomId)) {
+				clientList.put(cl.getStreamid(), cl);
 			}
 		}
-		
-		return EMPTY_MAP;
+		return clientList;
 	}
 
 	public void remove(Server server, String streamId) {
-		
-		// By server and streamid
-		
-		//Server and streamId are always given, if server is null, it means the user is locally
-		//and not on any slave host
-		LinkedHashMap<String, Client> clientList = clientsByServer.get(getIdByServer(server));
-		if (clientList == null) {
-			clientList = new LinkedHashMap<String, Client>();
-		}
-		Client rcl = clientList.get(streamId);
-		
-		if (rcl == null) {
-			throw new NullPointerException("Could not find RoomClient with that streamId: "+streamId);
-		}
-		
-		clientList.remove(streamId);
-		if (clientList.size() == 0) {
-			clientsByServer.remove(getIdByServer(server));
-		} else {
-			clientsByServer.put(getIdByServer(server), clientList);
-		}
-
-		// By publicSID
-		
-		//publicSID id might be null and then change to something, 
-		//but we will not want to search for a user with the publicSID == null
-		//so as long as publicSID is null, we don't organize the session on a special list
-		if (rcl.getPublicSID() != null) {
-			LinkedHashMap<String, List<Client>> clientListPublicSID = clientsByServerAndPublicSID
-					.get(getIdByServer(server));
-			if (clientListPublicSID == null) {
-				clientListPublicSID = new LinkedHashMap<String, List<Client>>();
-			}
-			List<Client> clientsByPublicSIDList = clientListPublicSID.get(rcl
-					.getPublicSID());
-			if (clientsByPublicSIDList == null) {
-				clientsByPublicSIDList = new ArrayList<Client>();
-			}
-			clientsByPublicSIDList.remove(rcl);
-			if (clientsByPublicSIDList.size() == 0) {
-				clientListPublicSID.remove(rcl.getPublicSID());
-			} else {
-				clientListPublicSID.put(rcl.getPublicSID(), clientsByPublicSIDList);
-			}
-			if (clientListPublicSID.size() == 0) {
-				clientsByServerAndPublicSID.remove(getIdByServer(server));
-			} else {
-				clientsByServerAndPublicSID.put(getIdByServer(server), clientListPublicSID);
-			}
-		}
-		
-		// By userId
-		
-		//user id might be null and then change to something, 
-		//but we will not want to search for a user with the userId == null
-		//so as long as userId is null, we don't organize the session on a special list
-		if (rcl.getUser_id() != null) {
-			LinkedHashMap<Long, List<Client>> clientListUserId = clientsByServerAndUserId
-					.get(getIdByServer(server));
-			if (clientListUserId == null) {
-				clientListUserId = new LinkedHashMap<Long, List<Client>>();
-			}
-			List<Client> clientListUserIdList = clientListUserId.get(rcl
-					.getPublicSID());
-			if (clientListUserIdList == null) {
-				clientListUserIdList = new ArrayList<Client>();
-			}
-			clientListUserIdList.remove(rcl);
-			if (clientListUserIdList.size() == 0) {
-				clientListUserId.remove(rcl.getUser_id());
-			} else {
-				clientListUserId.put(rcl.getUser_id(), clientListUserIdList);
-			}
-			if (clientListUserId.size() == 0) {
-				clientsByServerAndUserId.remove(getIdByServer(server));
-			} else {
-				clientsByServerAndUserId.put(getIdByServer(server), clientListUserId);
-			}
-		}
-
-		// By roomId
-		
-		//room id might be null and then change to something, 
-		//but we will not want to search for a user with the roomId == null
-		//so as long as roomId is null, we don't organize the session on a special list
-		if (rcl.getRoom_id() != null) {
-			LinkedHashMap<Long, LinkedHashMap<String, Client>> clientsByRoomId = clientsByServerAndRoomId.get(getIdByServer(server));
-			if (clientsByRoomId == null) {
-				clientsByRoomId = new LinkedHashMap<Long, LinkedHashMap<String, Client>>();
-			}
-			LinkedHashMap<String, Client> clientRoomList = clientsByRoomId.get(rcl
-					.getRoom_id());
-			if (clientRoomList == null) {
-				clientRoomList = new LinkedHashMap<String, Client>();
-			}
-			clientRoomList.remove(streamId);
-			if (clientRoomList.size() == 0) {
-				clientsByRoomId.remove(rcl.getRoom_id());
-			} else {
-				clientsByRoomId.put(rcl.getRoom_id(), clientRoomList);
-			}
-			if (clientsByRoomId.size() == 0) {
-				clientsByServerAndRoomId.remove(getIdByServer(server));
-			} else {
-				clientsByServerAndRoomId.put(getIdByServer(server), clientsByRoomId);
-			}
-		}
-		
+		clientsByStreamId.remove(streamId);
 	}
 
 	public int size() {
-		int size = 0;
-		for (Entry<Long, LinkedHashMap<String, Client>> entry : clientsByServer.entrySet())
{
-			size += entry.getValue().size();
-		}
-		return size;
+		return clientsByStreamId.size();
 	}
 	
 	public int sizeByServer(Server server) {
-		if (clientsByServer.get(getIdByServer(server)) == null) {
-			return 0;
-		}
-		return clientsByServer.get(getIdByServer(server)).size();
+		return clientsByStreamId.size();
 	}
 
-	public LinkedHashMap<Long, LinkedHashMap<String, Client>> values() {
-		return clientsByServer;
+	public Collection<Client> values() {
+		return clientsByStreamId.values();
 	}
 	
-	public LinkedHashMap<Long,LinkedHashMap<String,Client>> getClientsByServerAndRoom(Server
server) {
-		return clientsByServerAndRoomId.get(getIdByServer(server));
+	public LinkedHashMap<Long,Collection<Client>> getClientsByServerAndRoom(Server
server) {
+		LinkedHashMap<Long,Collection<Client>> clientsByServer = new LinkedHashMap<Long,Collection<Client>>();
+		clientsByServer.put(null, clientsByStreamId.values());
+		return clientsByServer;
 	}
 	
-//	public Set<Long> getRoomIdsByServer(Server server) {
-//		return clientsByServerAndRoomId.get(getIdByServer(server)).keySet();
-//	}
-	
 	public int getTotalNumberOfSessions() {
-		int t = 0;
-		for (Entry<Long, LinkedHashMap<String, Client>> entry : values().entrySet())
{
-			t += entry.getValue().values().size();
-		}
-		return t;
+		return clientsByStreamId.size();
 	}
 	
 	
@@ -428,99 +176,6 @@ public class HashMapStore implements ICl
 		if (detailLevel.contains(DEBUG_DETAILS.SIZE)) {
 			addNewLine(statistics, "Number of sessions Total "
 					+ getTotalNumberOfSessions());
-			addNewLine(statistics,
-					" clientsByServer SIZE " + clientsByServer.size());
-			addNewLine(statistics, " clientsByServerAndPublicSID SIZE "
-					+ clientsByServerAndPublicSID.size());
-			addNewLine(statistics, " clientsByServerAndUserId SIZE "
-					+ clientsByServerAndUserId.size());
-			addNewLine(statistics, " clientsByRoomId SIZE "
-					+ clientsByServerAndRoomId.size());
-		}
-
-		if (detailLevel.contains(DEBUG_DETAILS.CLIENT_BY_STREAMID)) {
-
-			for (Entry<Long, LinkedHashMap<String, Client>> entry : clientsByServer
-					.entrySet()) {
-				addNewLine(statistics,
-						"clientsByServer Server " + entry.getKey()
-								+ " Number of Clients: "
-								+ entry.getValue().size());
-			}
-
-		}
-
-		if (detailLevel.contains(DEBUG_DETAILS.CLIENT_BY_PUBLICSID)) {
-			for (Entry<Long, LinkedHashMap<String, List<Client>>> entry : clientsByServerAndPublicSID
-					.entrySet()) {
-				addNewLine(statistics, "clientsByServerAndPublicSID Server "
-						+ entry.getKey() + " Number of PublicSIDs: "
-						+ entry.getValue().size());
-
-				if (detailLevel.contains(DEBUG_DETAILS.PUBLICSID_LIST_ALL)) {
-					for (Entry<String, List<Client>> innerEntry : entry
-							.getValue().entrySet()) {
-						addNewLine(statistics,
-								"clientsByServerAndPublicSID publicSID "
-										+ innerEntry.getKey()
-										+ " Number of clients "
-										+ innerEntry.getValue().size());
-					}
-				}
-			}
-		}
-
-		if (detailLevel.contains(DEBUG_DETAILS.CLIENT_BY_USERID)) {
-			for (Entry<Long, LinkedHashMap<Long, List<Client>>> entry : clientsByServerAndUserId
-					.entrySet()) {
-				addNewLine(statistics, "clientsByServerAndUserId Server "
-						+ entry.getKey() + " Number of UserIds: "
-						+ entry.getValue().size());
-
-				if (detailLevel.contains(DEBUG_DETAILS.USERID_LIST_ALL)) {
-					for (Entry<Long, List<Client>> innerEntry : entry
-							.getValue().entrySet()) {
-						addNewLine(
-								statistics,
-								"clientsByServerAndUserId userId "
-										+ innerEntry.getKey()
-										+ " Number of clients "
-										+ innerEntry.getValue().size());
-					}
-				}
-			}
-		}
-
-		if (detailLevel.contains(DEBUG_DETAILS.CLIENT_BY_ROOMID)) {
-
-			for (Entry<Long, LinkedHashMap<Long, LinkedHashMap<String, Client>>>
serverEntry : clientsByServerAndRoomId
-					.entrySet()) {
-
-				LinkedHashMap<Long, LinkedHashMap<String, Client>> clientsByRoomId = serverEntry
-						.getValue();
-				addNewLine(statistics, "clientsByRoomId ServerId "
-						+ serverEntry.getKey() + " Number of Rooms: "
-						+ serverEntry.getValue().size() + " roomIds "
-						+ serverEntry.getValue().keySet());
-
-				for (Entry<Long, LinkedHashMap<String, Client>> entry : clientsByRoomId
-						.entrySet()) {
-					addNewLine(statistics,
-							"clientsByRoomId RoomId " + entry.getKey()
-									+ " Number of Clients: "
-									+ entry.getValue().size());
-
-					if (detailLevel.contains(DEBUG_DETAILS.ROOMID_LIST_ALL)) {
-						for (Entry<String, Client> innerEntry : entry
-								.getValue().entrySet()) {
-							addNewLine(statistics, "clientsByRoomId streamId "
-									+ innerEntry.getKey() + " client "
-									+ innerEntry.getValue());
-						}
-					}
-				}
-
-			}
 		}
 
 		return statistics.toString();

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/store/IClientPersistenceStore.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/store/IClientPersistenceStore.java?rev=1441303&r1=1441302&r2=1441303&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/store/IClientPersistenceStore.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/session/store/IClientPersistenceStore.java
Fri Feb  1 03:30:52 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.openmeetings.session.store;
 
+import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -28,12 +29,13 @@ import org.apache.openmeetings.persisten
 public interface IClientPersistenceStore {
 
 	public enum DEBUG_DETAILS {
-		SIZE,
-		CLIENT_BY_STREAMID, STREAMID_LIST_ALL,
-		CLIENT_BY_PUBLICSID, PUBLICSID_LIST_ALL, 
-		CLIENT_BY_USERID, USERID_LIST_ALL,
-		CLIENT_BY_ROOMID, ROOMID_LIST_ALL
+		SIZE
 	}
+	
+	/**
+	 * called upon start of the session cache
+	 */
+	public abstract void clearCache();
 
 	/**
 	 * 
@@ -112,10 +114,10 @@ public interface IClientPersistenceStore
 
 	public abstract int sizeByServer(Server server);
 
-	public abstract LinkedHashMap<Long, LinkedHashMap<String, Client>> getClientsByServerAndRoom(
+	public abstract LinkedHashMap<Long, Collection<Client>> getClientsByServerAndRoom(
 			Server server);
 	
-	public LinkedHashMap<Long, LinkedHashMap<String, Client>> values();
+	public abstract Collection<Client> values();
 	
 	/**
 	 * Get some session statistics
@@ -123,6 +125,6 @@ public interface IClientPersistenceStore
 	 * @param detailLevel
 	 * @return
 	 */
-	public String getDebugInformation(List<DEBUG_DETAILS> detailLevel);
+	public abstract String getDebugInformation(List<DEBUG_DETAILS> detailLevel);
 
 }
\ No newline at end of file

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/session/TestDbSession.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/session/TestDbSession.java?rev=1441303&r1=1441302&r2=1441303&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/session/TestDbSession.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/session/TestDbSession.java
Fri Feb  1 03:30:52 2013
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.openmeetings.test.session;
 
 import static org.junit.Assert.assertEquals;

Added: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/session/TestHashMapSession.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/session/TestHashMapSession.java?rev=1441303&view=auto
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/session/TestHashMapSession.java
(added)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/session/TestHashMapSession.java
Fri Feb  1 03:30:52 2013
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.test.session;
+
+import static org.junit.Assert.assertEquals;
+
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Random;
+
+import org.apache.openmeetings.OpenmeetingsVariables;
+import org.apache.openmeetings.persistence.beans.rooms.Client;
+import org.apache.openmeetings.session.store.HashMapStore;
+import org.apache.openmeetings.session.store.IClientPersistenceStore;
+import org.apache.openmeetings.test.AbstractOpenmeetingsSpringTest;
+import org.apache.openmeetings.utils.crypt.ManageCryptStyle;
+import org.junit.Test;
+import org.red5.logging.Red5LoggerFactory;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class TestHashMapSession extends AbstractOpenmeetingsSpringTest {
+	
+	protected static final Logger log = Red5LoggerFactory.getLogger(
+			TestHashMapSession.class, OpenmeetingsVariables.webAppRootKey);
+	
+	@Autowired
+	private HashMapStore cache;
+	
+	@Autowired
+	private ManageCryptStyle manageCryptStyle;
+	
+	@Test
+	public void testHashMapSession() {
+		
+		for (int i=0;i<20;i++) {
+			
+			String streamId = ""+i;
+			
+			Client rcm = new Client();
+			rcm.setConnectedSince(new Date());
+			rcm.setStreamid(streamId);
+			rcm.setScope("scopeName");
+			long random = System.currentTimeMillis() + new BigInteger(256, new Random()).longValue();
+			
+			rcm.setPublicSID(manageCryptStyle.getInstanceOfCrypt()
+					.createPassPhrase(String.valueOf(random).toString()));
+
+			rcm.setUserport(0);
+			rcm.setUserip("remoteAddress");
+			rcm.setSwfurl("swfUrl");
+			rcm.setIsMod(new Boolean(false));
+			rcm.setCanDraw(new Boolean(false));
+			rcm.setIsAVClient(false);
+
+			if (cache.containsKey(null, streamId)) {
+				log.error("Tried to add an existing Client " + streamId);
+				break;
+			}
+
+			cache.put(rcm.getStreamid(), rcm);
+			
+			cache.remove(null, streamId);
+		
+		}
+		
+		String logString = cache.getDebugInformation(Arrays.asList(IClientPersistenceStore.DEBUG_DETAILS.SIZE));
+		
+		
+		log.debug("######## \n\r "+ logString + " \n\r ########");
+		
+		assertEquals(0, cache.size());
+		
+	}
+
+}



Mime
View raw message