Skip to content
Snippets Groups Projects
Commit d09adf83 authored by Shudong Zhou's avatar Shudong Zhou
Browse files

Make registerApp() thread safe

parent 888f3937
No related branches found
No related tags found
No related merge requests found
...@@ -17,8 +17,7 @@ ...@@ -17,8 +17,7 @@
package net.floodlightcontroller.core.util; package net.floodlightcontroller.core.util;
import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.Map;
/*** /***
* FIXME Need a system for registering/binding applications to a unique ID * FIXME Need a system for registering/binding applications to a unique ID
...@@ -34,8 +33,8 @@ public class AppCookie { ...@@ -34,8 +33,8 @@ public class AppCookie {
static final int USER_BITS = 32; static final int USER_BITS = 32;
static final int USER_SHIFT = 0; static final int USER_SHIFT = 0;
private static Map<Integer, String> appIdMap = private static ConcurrentHashMap<Integer, String> appIdMap =
new HashMap<Integer, String>(); new ConcurrentHashMap<Integer, String>();
/** /**
* Encapsulate an application ID and a user block of stuff into a cookie * Encapsulate an application ID and a user block of stuff into a cookie
...@@ -69,9 +68,9 @@ public class AppCookie { ...@@ -69,9 +68,9 @@ public class AppCookie {
static public void registerApp(int application, String appName) static public void registerApp(int application, String appName)
throws AppIDInUseException throws AppIDInUseException
{ {
if (appIdMap.get(application) != null) { String oldApp = appIdMap.putIfAbsent(application, appName);
throw new AppIDInUseException(application, appIdMap.get(application)); if (oldApp != null) {
throw new AppIDInUseException(application, oldApp);
} }
appIdMap.put(application, appName);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment