[Red5commits] [2447] simplified code a bit

jbauch luke at codegent.com
Tue Oct 30 23:51:30 PDT 2007


simplified code a bit


Timestamp: 10/25/07 18:30:09 EST (5 days ago) 
Change: 2447 
Author: jbauch

Files (see diff or trac for details): 
java/server/trunk/src/org/red5/server/Server.java


Trac: http://mirror1.cvsdude.com/trac/osflash/red5/changeset/2447

Index: /java/server/trunk/src/org/red5/server/Server.java
===================================================================
--- /java/server/trunk/src/org/red5/server/Server.java (revision 2414)
+++ /java/server/trunk/src/org/red5/server/Server.java (revision 2447)
@@ -24,4 +24,5 @@
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.CopyOnWriteArraySet;
 
@@ -49,10 +50,10 @@
 	 * List of global scopes
 	 */
-	protected ConcurrentHashMap<String, IGlobalScope> globals = new ConcurrentHashMap<String, IGlobalScope>();
+	protected ConcurrentMap<String, IGlobalScope> globals = new ConcurrentHashMap<String, IGlobalScope>();
 
 	/**
 	 * Mappings
 	 */
-	protected ConcurrentHashMap<String, String> mapping = new ConcurrentHashMap<String, String>();
+	protected ConcurrentMap<String, String> mapping = new ConcurrentHashMap<String, String>();
 
 	/**
@@ -126,6 +127,7 @@
 				log.debug("Check: " + key);
 			}
-			if (mapping.containsKey(key)) {
-				return getGlobal(mapping.get(key));
+			String globalName = mapping.get(key);
+			if (globalName != null) {
+				return getGlobal(globalName);
 			}
 			final int slashIndex = contextPath.lastIndexOf(SLASH);
@@ -141,6 +143,7 @@
 		}
 		// Look up for global scope switching keys if still not found
-		if (mapping.containsKey(key)) {
-			return getGlobal(mapping.get(key));
+		String globalName = mapping.get(key);
+		if (globalName != null) {
+			return getGlobal(globalName);
 		}
 		key = getKey(EMPTY, contextPath);
@@ -148,6 +151,7 @@
 			log.debug("Check wildcard host with path: " + key);
 		}
-		if (mapping.containsKey(key)) {
-			return getGlobal(mapping.get(key));
+		globalName = mapping.get(key);
+		if (globalName != null) {
+			return getGlobal(globalName);
 		}
 		key = getKey(hostName, EMPTY);
@@ -155,6 +159,7 @@
 			log.debug("Check host with no path: " + key);
 		}
-		if (mapping.containsKey(key)) {
-			return getGlobal(mapping.get(key));
+		globalName = mapping.get(key);
+		if (globalName != null) {
+			return getGlobal(globalName);
 		}
 		key = getKey(EMPTY, EMPTY);
@@ -209,9 +214,5 @@
 			log.debug("Add mapping: " + key + " => " + globalName);
 		}
-		if (mapping.containsKey(key)) {
-			return false;
-		}
-		mapping.put(key, globalName);
-		return true;
+		return (mapping.putIfAbsent(key, globalName) == null);
 	}
 
@@ -232,9 +233,5 @@
 			log.debug("Remove mapping: " + key);
 		}
-		if (!mapping.containsKey(key)) {
-			return false;
-		}
-		mapping.remove(key);
-		return true;
+		return (mapping.remove(key) != null);
 	}
 


Note:
Diffs are chopped if more than 25k.
This is to get past the limit on the mailing list.



More information about the Red5commits mailing list