Author: ssmaeklu
Date: 2007-06-01 12:08:03 +0200 (Fri, 01 Jun 2007)
New Revision: 5245

Modified:
   
branches/2.13/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/AbstractSimpleFastSearchCommand.java
Log:
SEARCH-2643. HashMap replaced with concurrent version

Modified: 
branches/2.13/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/AbstractSimpleFastSearchCommand.java
===================================================================
--- 
branches/2.13/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/AbstractSimpleFastSearchCommand.java
 2007-06-01 08:19:28 UTC (rev 5244)
+++ 
branches/2.13/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/AbstractSimpleFastSearchCommand.java
 2007-06-01 10:08:03 UTC (rev 5245)
@@ -60,6 +60,8 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
 import no.schibstedsok.searchportal.result.ResultItem;
 import no.schibstedsok.searchportal.result.ResultList;
 import no.schibstedsok.searchportal.result.WeightedSuggestion;
@@ -90,7 +92,7 @@
     private final String queryServerUrl;
 
     // Static --------------------------------------------------------
-    private static final Map<String, IFastSearchEngine> SEARCH_ENGINES = new 
HashMap<String, IFastSearchEngine>();
+    private static final Map<String, IFastSearchEngine> SEARCH_ENGINES = new 
ConcurrentHashMap<String, IFastSearchEngine>();
     private static transient IFastSearchEngineFactory engineFactory;
 
     static {
@@ -565,18 +567,18 @@
      * TODO comment me. *
      */
     protected IFastSearchEngine getSearchEngine() throws 
ConfigurationException, MalformedURLException {
+        try {
+            if (!SEARCH_ENGINES.containsKey(queryServerUrl)) {
+                LOG.debug(DEBUG_FAST_SEARCH_ENGINE + 
getSearchConfiguration().getQueryServerUrl() + "-->" + queryServerUrl);
 
-        // XXX There is no synchronisation around this static map.
-        //   Not critical as any clashing threads will just override the 
values,
-        //    and the cost of the occasional double-up creation probably 
doesn't compare
-        //    to the synchronisation overhead.
-        if (!SEARCH_ENGINES.containsKey(queryServerUrl)) {
-            LOG.debug(DEBUG_FAST_SEARCH_ENGINE + 
getSearchConfiguration().getQueryServerUrl() + "-->" + queryServerUrl);
-
-            final IFastSearchEngine engine = 
engineFactory.createSearchEngine(queryServerUrl);
-            SEARCH_ENGINES.put(queryServerUrl, engine);
+                final IFastSearchEngine engine = 
engineFactory.createSearchEngine(queryServerUrl);
+                SEARCH_ENGINES.put(queryServerUrl, engine);
+            }
+            return SEARCH_ENGINES.get(queryServerUrl);
+        } catch (MalformedURLException e) {
+            LOG.error("Malformed URL is: " + queryServerUrl);
+            throw(e);
         }
-        return (IFastSearchEngine) SEARCH_ENGINES.get(queryServerUrl);
     }
 
     protected String getSortBy() {

_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits

Reply via email to