Author: mickw
Date: 2006-05-05 10:25:20 +0200 (Fri, 05 May 2006)
New Revision: 2859

Added:
   trunk/src/java/no/schibstedsok/front/searchportal/servlet/FactoryReloads.java
   trunk/src/java/no/schibstedsok/front/searchportal/site/SiteKeyedFactory.java
   trunk/src/test/java/no/schibstedsok/front/searchportal/servlet/
   
trunk/src/test/java/no/schibstedsok/front/searchportal/servlet/FactoryReloadsTest.java
Modified:
   
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactory.java
   
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SiteConfiguration.java
   
trunk/src/java/no/schibstedsok/front/searchportal/output/VelocityResultHandler.java
   
trunk/src/java/no/schibstedsok/front/searchportal/query/analyser/AnalysisRuleFactory.java
   
trunk/src/java/no/schibstedsok/front/searchportal/query/token/RegExpEvaluatorFactory.java
   trunk/src/java/no/schibstedsok/front/searchportal/servlet/SearchServlet.java
   
trunk/src/java/no/schibstedsok/front/searchportal/velocity/VelocityEngineFactory.java
   
trunk/src/java/no/schibstedsok/front/searchportal/view/config/SearchTabFactory.java
   trunk/src/test/java/no/schibstedsok/front/searchportal/command/
   
trunk/src/test/java/no/schibstedsok/front/searchportal/command/WebSearchCommandTest.java
   
trunk/src/test/java/no/schibstedsok/front/searchportal/command/WhiteSearchCommandTest.java
   
trunk/src/test/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactoryTest.java
   
trunk/src/test/java/no/schibstedsok/front/searchportal/configuration/SearchModeTest.java
   
trunk/src/test/java/no/schibstedsok/front/searchportal/result/test/FastNavigatorsTest.java
   
trunk/src/test/java/no/schibstedsok/front/searchportal/result/test/MockupSearchCommand.java
   
trunk/src/test/java/no/schibstedsok/front/searchportal/view/config/SearchTabFactoryTest.java
Log:
reload=all|views|modes|AnalysisRules|RegularExpressionEvaluators|velocity
parameter to SearchServlet to perform cleaning of a site and all its locale 
variants to the given factories.


Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactory.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactory.java
      2006-05-05 06:53:28 UTC (rev 2858)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactory.java
      2006-05-05 08:25:20 UTC (rev 2859)
@@ -55,6 +55,7 @@
 import no.schibstedsok.front.searchportal.result.handler.WeatherDateHandler;
 import no.schibstedsok.front.searchportal.site.Site;
 import no.schibstedsok.front.searchportal.site.SiteContext;
+import no.schibstedsok.front.searchportal.site.SiteKeyedFactory;
 import no.schibstedsok.front.searchportal.util.SearchConstants;
 import no.schibstedsok.front.searchportal.util.config.AbstractDocumentFactory;
 
@@ -68,7 +69,7 @@
  * @author <a href="mailto:[EMAIL PROTECTED]>mick</a>
  * @version <tt>$Id$</tt>
  */
-public final class SearchModeFactory extends AbstractDocumentFactory{
+public final class SearchModeFactory extends AbstractDocumentFactory 
implements SiteKeyedFactory{
 
     /**
      * The context any SearchModeFactory must work against. *
@@ -109,7 +110,7 @@
 
    // Static --------------------------------------------------------
 
-    public static SearchModeFactory getModeFactory(final Context cxt) {
+    public static SearchModeFactory valueOf(final Context cxt) {
 
         final Site site = cxt.getSite();
 
@@ -127,7 +128,7 @@
         return instance;
     }
     
-    public static boolean remove(final Site site){
+    public boolean remove(final Site site){
 
         try{
             INSTANCES_LOCK.writeLock().lock();
@@ -171,7 +172,7 @@
         SearchMode mode = getModeImpl(id);
         if(mode == null && id != null && id.length() >0 && 
context.getSite().getParent() != null){
             // not found in this site's modes.xml. look in parent's site.
-            final SearchModeFactory factory = 
getModeFactory(ContextWrapper.wrap(
+            final SearchModeFactory factory = valueOf(ContextWrapper.wrap(
                     Context.class,
                     new SiteContext(){
                         public Site getSite(){

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SiteConfiguration.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SiteConfiguration.java
      2006-05-05 06:53:28 UTC (rev 2858)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SiteConfiguration.java
      2006-05-05 08:25:20 UTC (rev 2859)
@@ -12,6 +12,7 @@
 import 
no.schibstedsok.front.searchportal.configuration.loader.UrlResourceLoader;
 import no.schibstedsok.front.searchportal.site.Site;
 import no.schibstedsok.front.searchportal.site.SiteContext;
+import no.schibstedsok.front.searchportal.site.SiteKeyedFactory;
 import no.schibstedsok.front.searchportal.util.SearchConstants;
 import org.apache.log4j.Logger;
 
@@ -22,7 +23,7 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Magnus Eklund</a>
  * @version <tt>$Revision: 2720 $</tt>
  */
-public final class SiteConfiguration {
+public final class SiteConfiguration implements SiteKeyedFactory{
 
     public interface Context extends BaseContext, PropertiesContext, 
SiteContext {
     }
@@ -93,7 +94,7 @@
         return stc;
     }
 
-    public static boolean remove(final Site site){
+    public boolean remove(final Site site){
 
         try{
             INSTANCES_LOCK.writeLock().lock();

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/output/VelocityResultHandler.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/output/VelocityResultHandler.java
 2006-05-05 06:53:28 UTC (rev 2858)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/output/VelocityResultHandler.java
 2006-05-05 08:25:20 UTC (rev 2859)
@@ -61,7 +61,7 @@
                 public Site getSite() {
                     return site;
                 }
-            });
+            }).getEngine();
     }
 
     public static Template getTemplate(

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/query/analyser/AnalysisRuleFactory.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/query/analyser/AnalysisRuleFactory.java
   2006-05-05 06:53:28 UTC (rev 2858)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/query/analyser/AnalysisRuleFactory.java
   2006-05-05 08:25:20 UTC (rev 2859)
@@ -7,10 +7,12 @@
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 import javax.xml.parsers.DocumentBuilderFactory;
 import no.schibstedsok.common.ioc.BaseContext;
 import no.schibstedsok.front.searchportal.configuration.loader.DocumentLoader;
 import no.schibstedsok.front.searchportal.query.token.TokenPredicate;
+import no.schibstedsok.front.searchportal.site.SiteKeyedFactory;
 import no.schibstedsok.front.searchportal.util.SearchConstants;
 import org.apache.commons.collections.Predicate;
 import org.apache.commons.collections.PredicateUtils;
@@ -39,7 +41,7 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a>
  * @version <tt>$Revision$</tt>
  */
-public final class AnalysisRuleFactory {
+public final class AnalysisRuleFactory implements SiteKeyedFactory{
 
     /**
      * The context the AnalysisRuleFactory must work against. *
@@ -67,6 +69,7 @@
      * the resources to improve the performance. But I doubt this would gain 
much, if anything at all.
      */
     private static final Map<Site,AnalysisRuleFactory> INSTANCES = new 
HashMap<Site,AnalysisRuleFactory>();
+    private static final ReentrantReadWriteLock INSTANCES_LOCK = new 
ReentrantReadWriteLock();
 
     private final Map predicateIds = new HashMap();
 
@@ -88,7 +91,9 @@
         final DocumentBuilder builder = factory.newDocumentBuilder();
         loader = 
context.newDocumentLoader(SearchConstants.ANALYSIS_RULES_XMLFILE, builder);
 
+        INSTANCES_LOCK.writeLock().lock();
         INSTANCES.put(context.getSite(), this);
+        INSTANCES_LOCK.writeLock().unlock();
     }
 
     private void init() {
@@ -305,8 +310,12 @@
      * @return AnalysisRuleFactory for this site.
      */
     public static AnalysisRuleFactory valueOf(final Context cxt) {
+        
         final Site site = cxt.getSite();
+        INSTANCES_LOCK.readLock().lock();
         AnalysisRuleFactory instance = INSTANCES.get(site);
+        INSTANCES_LOCK.readLock().unlock();
+        
         if (instance == null) {
             try {
                 instance = new AnalysisRuleFactory(cxt);
@@ -343,5 +352,15 @@
         });
         return instance;
     }
+    
+    public boolean remove(final Site site){
 
+        try{
+            INSTANCES_LOCK.writeLock().lock();
+            return null != INSTANCES.remove(site);
+        }finally{
+            INSTANCES_LOCK.writeLock().unlock();
+        }
+    }
+
 }

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/query/token/RegExpEvaluatorFactory.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/query/token/RegExpEvaluatorFactory.java
   2006-05-05 06:53:28 UTC (rev 2858)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/query/token/RegExpEvaluatorFactory.java
   2006-05-05 08:25:20 UTC (rev 2859)
@@ -1,6 +1,7 @@
 // Copyright (2005-2006) Schibsted Søk AS
 package no.schibstedsok.front.searchportal.query.token;
 
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import no.schibstedsok.common.ioc.BaseContext;
@@ -8,6 +9,7 @@
 import no.schibstedsok.front.searchportal.configuration.loader.ResourceContext;
 import no.schibstedsok.front.searchportal.site.Site;
 import no.schibstedsok.front.searchportal.site.SiteContext;
+import no.schibstedsok.front.searchportal.site.SiteKeyedFactory;
 import no.schibstedsok.front.searchportal.util.SearchConstants;
 
 import java.util.ArrayList;
@@ -31,7 +33,7 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a>
  * @version <tt>$Revision$</tt>
  */
-public final class RegExpEvaluatorFactory {
+public final class RegExpEvaluatorFactory implements SiteKeyedFactory{
 
     /**
      * The context the RegExpEvaluatorFactory must work against.
@@ -54,6 +56,7 @@
      * the resources to improve the performance. But I doubt this would gain 
much, if anything at all.
      */
     private static final Map<Site,RegExpEvaluatorFactory> INSTANCES = new 
HashMap<Site,RegExpEvaluatorFactory>();
+    private static final ReentrantReadWriteLock INSTANCES_LOCK = new 
ReentrantReadWriteLock();
 
     private final Context context;
     private final DocumentLoader loader;
@@ -78,7 +81,9 @@
         final DocumentBuilder builder = factory.newDocumentBuilder();
         loader = 
context.newDocumentLoader(SearchConstants.REGEXP_EVALUATOR_XMLFILE, builder);
 
+        INSTANCES_LOCK.writeLock().lock();
         INSTANCES.put(context.getSite(), this);
+        INSTANCES_LOCK.writeLock().unlock();
     }
 
     /** Loads the resource SearchConstants.REGEXP_EVALUATOR_XMLFILE containing 
all regular expression patterns
@@ -140,8 +145,12 @@
      * @return RegExpEvaluatorFactory for this site.
      */
     public static RegExpEvaluatorFactory valueOf(final Context cxt) {
+        
         final Site site = cxt.getSite();
+        INSTANCES_LOCK.readLock().lock();
         RegExpEvaluatorFactory instance = INSTANCES.get(site);
+        INSTANCES_LOCK.readLock().unlock();
+        
         if (instance == null) {
             try {
                 instance = new RegExpEvaluatorFactory(cxt);
@@ -188,4 +197,14 @@
         return regExpEvaluators.get(token);
     }
 
+    public boolean remove(final Site site) {
+        
+        try{
+            INSTANCES_LOCK.writeLock().lock();
+            return null != INSTANCES.remove(site);
+        }finally{
+            INSTANCES_LOCK.writeLock().unlock();
+        }
+    }
+
 }

Added: 
trunk/src/java/no/schibstedsok/front/searchportal/servlet/FactoryReloads.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/servlet/FactoryReloads.java   
                            (rev 0)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/servlet/FactoryReloads.java   
    2006-05-05 08:25:20 UTC (rev 2859)
@@ -0,0 +1,115 @@
+/*
+ * FactoryReloads.java
+ *
+ * Created on 5 May 2006, 07:58
+ *
+ */
+
+package no.schibstedsok.front.searchportal.servlet;
+
+import java.util.Locale;
+import no.schibstedsok.common.ioc.ContextWrapper;
+import no.schibstedsok.front.searchportal.configuration.SearchModeFactory;
+import no.schibstedsok.front.searchportal.configuration.SiteConfiguration;
+import no.schibstedsok.front.searchportal.query.analyser.AnalysisRuleFactory;
+import no.schibstedsok.front.searchportal.query.token.RegExpEvaluatorFactory;
+import no.schibstedsok.front.searchportal.site.Site;
+import no.schibstedsok.front.searchportal.site.SiteContext;
+import no.schibstedsok.front.searchportal.site.SiteKeyedFactory;
+import no.schibstedsok.front.searchportal.velocity.VelocityEngineFactory;
+import no.schibstedsok.front.searchportal.view.config.SearchTabFactory;
+import org.apache.log4j.Logger;
+
+/**
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a>
+ * @version $Id$
+ */
+public final class FactoryReloads {
+    
+    
+    // Constants -----------------------------------------------------
+    
+    private static final Logger LOG = Logger.getLogger(FactoryReloads.class);
+    
+    private static final String WARN_TABS_CLEANED = " on cleaning tabs 
(against all locales) for ";
+    private static final String WARN_CONFIG_CLEANED = " on cleaning 
configuration (against all locales) for ";
+    private static final String WARN_MODES_CLEANED = " on cleaning modes 
(against all locales) for ";
+    private static final String WARN_ANALYSIS_CLEANED = " on cleaning 
AnalysisRules (against all locales) for ";
+    private static final String WARN_REGEXP_CLEANED = " on cleaning 
RegularExpressionEvaluators (against all locales) for ";
+    private static final String WARN_VELOCITY_CLEANED = " on cleaning 
VelocityEngines (against all locales) for ";
+    
+    // Attributes ----------------------------------------------------
+    
+    // Static --------------------------------------------------------
+    
+    public static void performReloads(
+            final SiteContext genericCxt,
+            final String reload){
+        
+        final Site site = genericCxt.getSite();
+        
+        if( "all".equalsIgnoreCase(reload) ){
+            LOG.warn( removeAllLocalesFromSiteKeyedFactory(site, 
+                    
SiteConfiguration.valueOf(ContextWrapper.wrap(SiteConfiguration.Context.class, 
genericCxt)))
+                    + WARN_CONFIG_CLEANED + site);
+        } 
+        if( "all".equalsIgnoreCase(reload) || "views".equalsIgnoreCase(reload) 
){
+            LOG.warn( removeAllLocalesFromSiteKeyedFactory(site, 
+                    
SearchTabFactory.valueOf(ContextWrapper.wrap(SearchTabFactory.Context.class, 
genericCxt))) 
+                     + WARN_TABS_CLEANED + site);
+        }
+        if( "all".equalsIgnoreCase(reload) || "modes".equalsIgnoreCase(reload) 
){
+            LOG.warn( removeAllLocalesFromSiteKeyedFactory(site, 
+                    
SearchModeFactory.valueOf(ContextWrapper.wrap(SearchModeFactory.Context.class, 
genericCxt))) 
+                     + WARN_MODES_CLEANED + site);
+        }
+        if( "all".equalsIgnoreCase(reload) || 
"AnalysisRules".equalsIgnoreCase(reload) ){
+            LOG.warn( removeAllLocalesFromSiteKeyedFactory(site, 
+                    
AnalysisRuleFactory.valueOf(ContextWrapper.wrap(AnalysisRuleFactory.Context.class,
 genericCxt))) 
+                     + WARN_ANALYSIS_CLEANED + site);
+        }
+        if( "all".equalsIgnoreCase(reload) || 
"RegularExpressionEvaluators".equalsIgnoreCase(reload) ){
+            LOG.warn( removeAllLocalesFromSiteKeyedFactory(site, 
+                    
RegExpEvaluatorFactory.valueOf(ContextWrapper.wrap(RegExpEvaluatorFactory.Context.class,
 genericCxt))) 
+                     + WARN_REGEXP_CLEANED + site);
+        }
+        if( "all".equalsIgnoreCase(reload) || 
"velocity".equalsIgnoreCase(reload) ){
+            LOG.warn( removeAllLocalesFromSiteKeyedFactory(site, 
+                    
VelocityEngineFactory.valueOf(ContextWrapper.wrap(VelocityEngineFactory.Context.class,
 genericCxt))) 
+                     + WARN_VELOCITY_CLEANED + site);
+        }
+    }
+    
+    private static int removeAllLocalesFromSiteKeyedFactory(
+            final Site site,
+            final SiteKeyedFactory factory){
+        
+        int cleaned = 0;
+        for( Locale l : Locale.getAvailableLocales() ){
+            if( factory.remove(Site.valueOf(site.getName(),l)) ){
+                ++cleaned;
+            }
+        }
+        return cleaned;
+    }
+    
+    // Constructors --------------------------------------------------
+    
+    private FactoryReloads(){}
+    
+    
+    // Public --------------------------------------------------------
+    
+    // Z implementation ----------------------------------------------
+    
+    // Y overrides ---------------------------------------------------
+    
+    // Package protected ---------------------------------------------
+    
+    // Protected -----------------------------------------------------
+    
+    // Private -------------------------------------------------------
+    
+    // Inner classes -------------------------------------------------
+}

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/servlet/SearchServlet.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/servlet/SearchServlet.java    
    2006-05-05 06:53:28 UTC (rev 2858)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/servlet/SearchServlet.java    
    2006-05-05 08:25:20 UTC (rev 2859)
@@ -2,6 +2,7 @@
 package no.schibstedsok.front.searchportal.servlet;
 
 
+import java.util.Locale;
 import java.util.Properties;
 import javax.xml.parsers.DocumentBuilder;
 import no.schibstedsok.common.ioc.BaseContext;
@@ -9,8 +10,11 @@
 import no.schibstedsok.front.searchportal.configuration.SearchMode;
 import no.schibstedsok.front.searchportal.configuration.SearchModeFactory;
 import no.schibstedsok.front.searchportal.configuration.loader.DocumentLoader;
+import no.schibstedsok.front.searchportal.query.analyser.AnalysisRuleFactory;
+import no.schibstedsok.front.searchportal.query.token.RegExpEvaluatorFactory;
 import no.schibstedsok.front.searchportal.site.Site;
 import no.schibstedsok.front.searchportal.site.SiteContext;
+import no.schibstedsok.front.searchportal.site.SiteKeyedFactory;
 import no.schibstedsok.front.searchportal.util.QueryStringHelper;
 import no.schibstedsok.front.searchportal.configuration.SiteConfiguration;
 import 
no.schibstedsok.front.searchportal.configuration.loader.PropertiesLoader;
@@ -43,9 +47,6 @@
     private static final Logger LOG = Logger.getLogger(SearchServlet.class);
     private static final String ERR_MISSING_TAB = "No existing implementation 
for tab ";
     private static final String ERR_MISSING_MODE = "No existing implementation 
for mode ";
-    private static final String WARN_TABS_CLEANED = " status on cleaning site 
for ";
-    private static final String WARN_CONFIG_CLEANED = " status on cleaning 
configuration for ";
-    private static final String WARN_MODES_CLEANED = " status on cleaning 
modes for ";
 
     //private SearchTabs tabs;
 
@@ -79,17 +80,6 @@
         }
 
         final Site site = (Site) request.getAttribute(Site.NAME_KEY);
-        
-        performReloads(site, request.getParameter("reload"));
-
-        updateContentType(site, response);
-
-        String searchTabKey = request.getParameter("c");
-
-        if (searchTabKey == null) {
-            searchTabKey = "d";
-        }
-
         // BaseContext providing SiteContext and ResourceContext.
         //  We need it casted as a SiteContext for the ResourceContext code to 
be happy.
         final SiteContext genericCxt = new SiteContext(){// <editor-fold 
defaultstate="collapsed" desc=" genericCxt ">
@@ -104,7 +94,18 @@
             }
         };//</editor-fold>
 
-        final SearchTab searchTab = SearchTabFactory.getTabFactory(
+        
+        FactoryReloads.performReloads(genericCxt, 
request.getParameter("reload"));
+
+        updateContentType(site, response);
+
+        String searchTabKey = request.getParameter("c");
+
+        if (searchTabKey == null) {
+            searchTabKey = "d";
+        }
+
+        final SearchTab searchTab = SearchTabFactory.valueOf(
                 ContextWrapper.wrap(SearchTabFactory.Context.class, 
genericCxt))
                 .getTabByKey(searchTabKey);
         
@@ -113,7 +114,7 @@
             throw new UnsupportedOperationException(ERR_MISSING_TAB + 
searchTabKey);
         }
         
-        final SearchMode mode = SearchModeFactory.getModeFactory(
+        final SearchMode mode = SearchModeFactory.valueOf(
                 ContextWrapper.wrap(SearchModeFactory.Context.class, 
genericCxt))
                 .getMode(searchTab.getMode());
         
@@ -170,23 +171,6 @@
         }
     }
     
-    private void performReloads(
-            final Site site,
-            final String reload){
-        
-        if( "all".equalsIgnoreCase(reload) ){
-            final boolean cleaned = SiteConfiguration.remove(site);
-            LOG.warn(cleaned + WARN_CONFIG_CLEANED + site);
-        } 
-        if( "all".equalsIgnoreCase(reload) || "tabs".equalsIgnoreCase(reload) 
){
-            final boolean cleaned = SearchTabFactory.remove(site);
-            LOG.warn(cleaned + WARN_TABS_CLEANED + site);
-        }
-        if( "all".equalsIgnoreCase(reload) || "modes".equalsIgnoreCase(reload) 
){
-            final boolean cleaned = SearchModeFactory.remove(site);
-            LOG.warn(cleaned + WARN_MODES_CLEANED + site);
-        }
-    }
     
     private boolean isEmptyQuery(
             final HttpServletRequest request,

Added: 
trunk/src/java/no/schibstedsok/front/searchportal/site/SiteKeyedFactory.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/site/SiteKeyedFactory.java    
                            (rev 0)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/site/SiteKeyedFactory.java    
    2006-05-05 08:25:20 UTC (rev 2859)
@@ -0,0 +1,22 @@
+/*
+ * SiteKeyedFactory.java
+ *
+ * Created on 5 May 2006, 07:27
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package no.schibstedsok.front.searchportal.site;
+
+/** Factories that have Site->Factory mappings should implement this interface
+ * to ensure general behaviours.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a>
+ */
+public interface SiteKeyedFactory {
+    
+    /** Remove the factory the maps to the given site. **/
+    boolean remove(Site site);
+    
+}

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/velocity/VelocityEngineFactory.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/velocity/VelocityEngineFactory.java
       2006-05-05 06:53:28 UTC (rev 2858)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/velocity/VelocityEngineFactory.java
       2006-05-05 08:25:20 UTC (rev 2859)
@@ -10,10 +10,12 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 import no.schibstedsok.front.searchportal.InfrastructureException;
 import no.schibstedsok.front.searchportal.configuration.SiteConfiguration;
 import no.schibstedsok.front.searchportal.site.Site;
 import no.schibstedsok.front.searchportal.site.SiteContext;
+import no.schibstedsok.front.searchportal.site.SiteKeyedFactory;
 import no.schibstedsok.front.searchportal.util.SearchConstants;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
@@ -28,17 +30,14 @@
  * @version $Id$
  * @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a>
  */
-public final class VelocityEngineFactory {
+public final class VelocityEngineFactory implements SiteKeyedFactory{
 
     private static final Logger LOG = 
Logger.getLogger(VelocityEngineFactory.class);
     private static final String VELOCITY_LOGGER = "org.apache.velocity";
 
-    /**
-     * Synchronisation occurs through method signature to "VelocityEngine 
valueOf(Context)".
-     *  While synchronsation is not ciritical without it in this case we were 
getting 10+ identical
-     *   velocityEngines being created one the first request.
-     */
     private static final Map<Site,VelocityEngineFactory> INSTANCES = new 
HashMap<Site,VelocityEngineFactory>();
+    
+    private static final ReentrantReadWriteLock INSTANCES_LOCK = new 
ReentrantReadWriteLock();
 
     private final VelocityEngine engine;
 
@@ -97,10 +96,12 @@
             throw new InfrastructureException(e);
         }
 
+        INSTANCES_LOCK.writeLock().lock();
         INSTANCES.put(site, this);
+        INSTANCES_LOCK.writeLock().unlock();
     }
 
-    public VelocityEngine getVelocityEngine() {
+    public VelocityEngine getEngine() {
         return engine;
     }
 
@@ -109,14 +110,18 @@
      * @param cxt the contextual needs the VelocityEngine must use to operate.
      * @return VelocityEngine for this site.
      */
-    public synchronized static VelocityEngine valueOf(final Context cxt) {
+    public static VelocityEngineFactory valueOf(final Context cxt) {
+        
         final Site site = cxt.getSite();
+        INSTANCES_LOCK.readLock().lock();
         VelocityEngineFactory instance = INSTANCES.get(site);
+        INSTANCES_LOCK.readLock().unlock();
+        
         if (instance == null) {
             instance = new VelocityEngineFactory(cxt);
 
         }
-        return instance.getVelocityEngine();
+        return instance;
     }
 
     /**
@@ -125,10 +130,10 @@
      * @param site the site the VelocityEngine will work for.
      * @return VelocityEngine for this site.
      */
-    public static VelocityEngine valueOf(final Site site) {
+    public static VelocityEngineFactory valueOf(final Site site) {
 
         // RegExpEvaluatorFactory.Context for this site & UrlResourceLoader.
-        final VelocityEngine instance = VelocityEngineFactory.valueOf(new 
VelocityEngineFactory.Context() {
+        final VelocityEngineFactory instance = 
VelocityEngineFactory.valueOf(new VelocityEngineFactory.Context() {
             public Site getSite() {
                 return site;
             }
@@ -136,4 +141,14 @@
         return instance;
     }
 
+    public boolean remove(Site site) {
+        
+        try{
+            INSTANCES_LOCK.writeLock().lock();
+            return null != INSTANCES.remove(site);
+        }finally{
+            INSTANCES_LOCK.writeLock().unlock();
+        }
+    }
+
 }

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/view/config/SearchTabFactory.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/view/config/SearchTabFactory.java
 2006-05-05 06:53:28 UTC (rev 2858)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/view/config/SearchTabFactory.java
 2006-05-05 08:25:20 UTC (rev 2859)
@@ -25,6 +25,7 @@
 import 
no.schibstedsok.front.searchportal.configuration.loader.UrlResourceLoader;
 import no.schibstedsok.front.searchportal.site.Site;
 import no.schibstedsok.front.searchportal.site.SiteContext;
+import no.schibstedsok.front.searchportal.site.SiteKeyedFactory;
 import no.schibstedsok.front.searchportal.util.SearchConstants;
 import no.schibstedsok.front.searchportal.util.config.AbstractDocumentFactory;
 import org.apache.log4j.Logger;
@@ -36,7 +37,7 @@
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a>
  */
-public final class SearchTabFactory extends AbstractDocumentFactory{
+public final class SearchTabFactory extends AbstractDocumentFactory implements 
SiteKeyedFactory{
 
     /**
      * The context any SearchTabFactory must work against. *
@@ -65,7 +66,7 @@
 
     // Static --------------------------------------------------------
 
-    public static SearchTabFactory getTabFactory(final Context cxt) {
+    public static SearchTabFactory valueOf(final Context cxt) {
 
         final Site site = cxt.getSite();
 
@@ -83,7 +84,7 @@
         return instance;
     }
 
-    public static boolean remove(final Site site){
+    public boolean remove(final Site site){
 
         try{
             INSTANCES_LOCK.writeLock().lock();
@@ -126,7 +127,7 @@
         SearchTab tab = getTabImpl(id);
         if(tab == null && context.getSite().getParent() != null){
             // not found in this site's views.xml. look in parent's site.
-            final SearchTabFactory factory = getTabFactory(ContextWrapper.wrap(
+            final SearchTabFactory factory = valueOf(ContextWrapper.wrap(
                     Context.class,
                     new SiteContext(){
                         public Site getSite(){
@@ -173,7 +174,7 @@
 
         loader.abut();
         LOG.debug("Parsing " + SearchConstants.VIEWS_XMLFILE + " started");
-        final SearchModeFactory modeFactory = SearchModeFactory.getModeFactory(
+        final SearchModeFactory modeFactory = SearchModeFactory.valueOf(
                 ContextWrapper.wrap(SearchModeFactory.Context.class, context));
         final Document doc = loader.getDocument();
         final Element root = doc.getDocumentElement();


Property changes on: 
trunk/src/test/java/no/schibstedsok/front/searchportal/command
___________________________________________________________________
Name: svn:ignore
   + .LCKWebSearchCommandTest.java~


Modified: 
trunk/src/test/java/no/schibstedsok/front/searchportal/command/WebSearchCommandTest.java
===================================================================
--- 
trunk/src/test/java/no/schibstedsok/front/searchportal/command/WebSearchCommandTest.java
    2006-05-05 06:53:28 UTC (rev 2858)
+++ 
trunk/src/test/java/no/schibstedsok/front/searchportal/command/WebSearchCommandTest.java
    2006-05-05 08:25:20 UTC (rev 2859)
@@ -145,12 +145,12 @@
             private final SearchMode mode = new SearchMode();
 
             public SearchMode getSearchMode() {
-                return SearchModeFactory.getModeFactory(
+                return SearchModeFactory.valueOf(
                         ContextWrapper.wrap(SearchModeFactory.Context.class, 
this))
                         .getMode("norsk-magic");
             }
             public SearchTab getSearchTab(){
-                return SearchTabFactory.getTabFactory(
+                return SearchTabFactory.valueOf(
                     ContextWrapper.wrap(SearchTabFactory.Context.class, this))
                     .getTabByKey("d");
             }

Modified: 
trunk/src/test/java/no/schibstedsok/front/searchportal/command/WhiteSearchCommandTest.java
===================================================================
--- 
trunk/src/test/java/no/schibstedsok/front/searchportal/command/WhiteSearchCommandTest.java
  2006-05-05 06:53:28 UTC (rev 2858)
+++ 
trunk/src/test/java/no/schibstedsok/front/searchportal/command/WhiteSearchCommandTest.java
  2006-05-05 08:25:20 UTC (rev 2859)
@@ -96,7 +96,7 @@
                 return mode;
             }
             public SearchTab getSearchTab(){
-                return SearchTabFactory.getTabFactory(
+                return SearchTabFactory.valueOf(
                     ContextWrapper.wrap(SearchTabFactory.Context.class, this))
                     .getTabByKey("w");
             }

Modified: 
trunk/src/test/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactoryTest.java
===================================================================
--- 
trunk/src/test/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactoryTest.java
     2006-05-05 06:53:28 UTC (rev 2858)
+++ 
trunk/src/test/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactoryTest.java
     2006-05-05 08:25:20 UTC (rev 2859)
@@ -35,7 +35,7 @@
     }
 
     /**
-     * Test of getModeFactory method, of class 
no.schibstedsok.front.searchportal.configuration.SearchModeFactory.
+     * Test of valueOf method, of class 
no.schibstedsok.front.searchportal.configuration.SearchModeFactory.
      */
     public void testGetModeFactory(){
 
@@ -54,7 +54,7 @@
             }
         };
 
-        final SearchModeFactory result = SearchModeFactory.getModeFactory(cxt);
+        final SearchModeFactory result = SearchModeFactory.valueOf(cxt);
         assertNotNull(result);
 
         return result;

Modified: 
trunk/src/test/java/no/schibstedsok/front/searchportal/configuration/SearchModeTest.java
===================================================================
--- 
trunk/src/test/java/no/schibstedsok/front/searchportal/configuration/SearchModeTest.java
    2006-05-05 06:53:28 UTC (rev 2858)
+++ 
trunk/src/test/java/no/schibstedsok/front/searchportal/configuration/SearchModeTest.java
    2006-05-05 08:25:20 UTC (rev 2859)
@@ -51,7 +51,7 @@
                 return mode;
             }
             public SearchTab getSearchTab(){
-                return SearchTabFactory.getTabFactory(
+                return SearchTabFactory.valueOf(
                     ContextWrapper.wrap(SearchTabFactory.Context.class, this))
                     .getTabByKey("d");
             }
@@ -94,7 +94,7 @@
                 return mode;
             }
             public SearchTab getSearchTab(){
-                return SearchTabFactory.getTabFactory(
+                return SearchTabFactory.valueOf(
                     ContextWrapper.wrap(SearchTabFactory.Context.class, this))
                     .getTabByKey("d");
             }

Modified: 
trunk/src/test/java/no/schibstedsok/front/searchportal/result/test/FastNavigatorsTest.java
===================================================================
--- 
trunk/src/test/java/no/schibstedsok/front/searchportal/result/test/FastNavigatorsTest.java
  2006-05-05 06:53:28 UTC (rev 2858)
+++ 
trunk/src/test/java/no/schibstedsok/front/searchportal/result/test/FastNavigatorsTest.java
  2006-05-05 08:25:20 UTC (rev 2859)
@@ -530,7 +530,7 @@
                 return mode;
             }
             public SearchTab getSearchTab(){
-                return SearchTabFactory.getTabFactory(
+                return SearchTabFactory.valueOf(
                     ContextWrapper.wrap(SearchTabFactory.Context.class, this))
                     .getTabByKey("d");
             }

Modified: 
trunk/src/test/java/no/schibstedsok/front/searchportal/result/test/MockupSearchCommand.java
===================================================================
--- 
trunk/src/test/java/no/schibstedsok/front/searchportal/result/test/MockupSearchCommand.java
 2006-05-05 06:53:28 UTC (rev 2858)
+++ 
trunk/src/test/java/no/schibstedsok/front/searchportal/result/test/MockupSearchCommand.java
 2006-05-05 08:25:20 UTC (rev 2859)
@@ -34,7 +34,7 @@
             return mode;
         }
         public SearchTab getSearchTab(){
-                return SearchTabFactory.getTabFactory(
+                return SearchTabFactory.valueOf(
                     ContextWrapper.wrap(SearchTabFactory.Context.class, this))
                     .getTabByKey("d");
             }

Added: 
trunk/src/test/java/no/schibstedsok/front/searchportal/servlet/FactoryReloadsTest.java
===================================================================
--- 
trunk/src/test/java/no/schibstedsok/front/searchportal/servlet/FactoryReloadsTest.java
                              (rev 0)
+++ 
trunk/src/test/java/no/schibstedsok/front/searchportal/servlet/FactoryReloadsTest.java
      2006-05-05 08:25:20 UTC (rev 2859)
@@ -0,0 +1,69 @@
+/*
+ * FactoryReloadsTest.java
+ * JUnit based test
+ *
+ * Created on 5 May 2006, 07:50
+ */
+
+package no.schibstedsok.front.searchportal.servlet;
+
+import java.util.Locale;
+import java.util.Properties;
+import javax.xml.parsers.DocumentBuilder;
+import junit.framework.TestCase;
+import no.schibstedsok.common.ioc.ContextWrapper;
+import no.schibstedsok.front.searchportal.configuration.SearchModeFactory;
+import no.schibstedsok.front.searchportal.configuration.SiteConfiguration;
+import no.schibstedsok.front.searchportal.configuration.loader.DocumentLoader;
+import 
no.schibstedsok.front.searchportal.configuration.loader.FileResourceLoader;
+import 
no.schibstedsok.front.searchportal.configuration.loader.PropertiesLoader;
+import no.schibstedsok.front.searchportal.query.analyser.AnalysisRuleFactory;
+import no.schibstedsok.front.searchportal.query.token.RegExpEvaluatorFactory;
+import no.schibstedsok.front.searchportal.site.*;
+import no.schibstedsok.front.searchportal.view.config.SearchTabFactory;
+import org.apache.log4j.Logger;
+
+/**
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a>
+ */
+public class FactoryReloadsTest extends TestCase {
+    
+    private static final Logger LOG = 
Logger.getLogger(FactoryReloadsTest.class);
+    
+    public FactoryReloadsTest(String testName) {
+        super(testName);
+    }
+
+    protected void setUp() throws Exception {
+    }
+
+    protected void tearDown() throws Exception {
+    }
+
+    /**
+     * Test of remove method, of class 
no.schibstedsok.front.searchportal.servlet.FactoryReloads.
+     */
+    public void testRemoveAll() {
+        
+        FactoryReloads.performReloads(genericContext(), "all"); 
+        
+    }
+
+    private SiteContext genericContext(){
+        
+        // BaseContext providing SiteContext and ResourceContext.
+        //  We need it casted as a SiteContext for the ResourceContext code to 
be happy.
+        return new SiteContext(){// <editor-fold defaultstate="collapsed" 
desc=" genericCxt ">
+            public PropertiesLoader newPropertiesLoader(final String resource, 
final Properties properties) {
+                return FileResourceLoader.newPropertiesLoader(this, resource, 
properties);
+            }
+            public DocumentLoader newDocumentLoader(final String resource, 
final DocumentBuilder builder) {
+                return FileResourceLoader.newDocumentLoader(this, resource, 
builder);
+            }
+            public Site getSite() {
+                return Site.DEFAULT;
+            }
+        };
+    }
+}

Modified: 
trunk/src/test/java/no/schibstedsok/front/searchportal/view/config/SearchTabFactoryTest.java
===================================================================
--- 
trunk/src/test/java/no/schibstedsok/front/searchportal/view/config/SearchTabFactoryTest.java
        2006-05-05 06:53:28 UTC (rev 2858)
+++ 
trunk/src/test/java/no/schibstedsok/front/searchportal/view/config/SearchTabFactoryTest.java
        2006-05-05 08:25:20 UTC (rev 2859)
@@ -108,7 +108,7 @@
             }
         };
 
-        final SearchTabFactory result = SearchTabFactory.getTabFactory(cxt);
+        final SearchTabFactory result = SearchTabFactory.valueOf(cxt);
         assertNotNull(result);
 
         return result;

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

Reply via email to