Author: ssmiweve
Date: 2008-12-02 18:25:36 +0100 (Tue, 02 Dec 2008)
New Revision: 7011
Modified:
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/SolrEvaluatorFactory.java
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/VeryFastTokenEvaluator.java
branches/2.18/generic.sesam/search-command-control/fast/src/main/java/no/sesat/search/mode/command/NavigatableESPFastCommand.java
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/AbstractSearchCommand.java
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/BaseSearchCommandParameter.java
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/NavigationSearchCommandParameter.java
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/AbstractQueryBuilder.java
branches/2.18/site-spi/src/main/java/no/sesat/search/site/Site.java
Log:
performance improvements in anticipation of 2.18 release
- avoid calls to context (related to the IoC pattern). cache commonly used
references within class OR avoid ContextWrapper.wrap(..) on really hammered
contexts.
Method.invoke(..) contains a synchronised block in it where it checks an
internal cache. this jams if reflection is loaded too hard.
- do the same for calls to datamodel (as they also use reflection)
- cache calls to Locale.getDisplayName(). it uses MessageFormat everytime.
Modified:
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/SolrEvaluatorFactory.java
===================================================================
---
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/SolrEvaluatorFactory.java
2008-12-02 13:22:38 UTC (rev 7010)
+++
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/SolrEvaluatorFactory.java
2008-12-02 17:25:36 UTC (rev 7011)
@@ -71,6 +71,7 @@
private final Future solrEvaluatorCreator;
private SolrTokenEvaluator solrEvaluator;
private SolrServer server;
+ private final Site site;
// TODO this will leak when sites are redeploy without Sesat being
restarted.
private static final Map<Site,Map<TokenPredicate,String[]>> LIST_NAMES
@@ -83,6 +84,8 @@
super(cxt);
+ this.site = cxt.getSite();
+
try{
final Properties props = SiteConfiguration.instanceOf(
ContextWrapper.wrap(SiteConfiguration.Context.class, cxt)).getProperties();
@@ -113,11 +116,11 @@
final Context cxt = getContext();
TokenEvaluator result = isResponsibleFor(token) ? getSolrEvaluator() :
null;
- if(result == null && null != cxt.getSite().getParent()){
+ if(result == null && null != site.getParent()){
result = instanceOf(ContextWrapper.wrap(
Context.class,
- cxt.getSite().getParent().getSiteContext(),
+ site.getParent().getSiteContext(),
cxt
)).getEvaluator(token);
@@ -148,7 +151,7 @@
boolean uses = false;
try{
LIST_NAMES_LOCK.readLock().lock();
- Site site = getContext().getSite();
+ Site site = this.site;
while(!uses && null != site){
@@ -175,7 +178,7 @@
String[] listNames = null;
try{
LIST_NAMES_LOCK.readLock().lock();
- Site site = getContext().getSite();
+ Site site = this.site;
while(null == listNames && null != site){
Modified:
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/VeryFastTokenEvaluator.java
===================================================================
---
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/VeryFastTokenEvaluator.java
2008-12-02 13:22:38 UTC (rev 7010)
+++
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/VeryFastTokenEvaluator.java
2008-12-02 17:25:36 UTC (rev 7011)
@@ -481,7 +481,7 @@
boolean uses = false;
try{
LIST_NAMES_LOCK.readLock().lock();
- Site site = context.getSite();
+ Site site = this.site;
while(!uses && null != site){
Modified:
branches/2.18/generic.sesam/search-command-control/fast/src/main/java/no/sesat/search/mode/command/NavigatableESPFastCommand.java
===================================================================
---
branches/2.18/generic.sesam/search-command-control/fast/src/main/java/no/sesat/search/mode/command/NavigatableESPFastCommand.java
2008-12-02 13:22:38 UTC (rev 7010)
+++
branches/2.18/generic.sesam/search-command-control/fast/src/main/java/no/sesat/search/mode/command/NavigatableESPFastCommand.java
2008-12-02 17:25:36 UTC (rev 7011)
@@ -85,7 +85,7 @@
// }
for (final Navigator navigator :
getSearchConfiguration().getNavigators().values()) {
- final StringDataObject navigatedValue =
datamodel.getParameters().getValue(navigator.getId());
+ final StringDataObject navigatedValue =
datamodelParameters.get(navigator.getId());
if (navigatedValue != null) {
Modified:
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/AbstractSearchCommand.java
===================================================================
---
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/AbstractSearchCommand.java
2008-12-02 13:22:38 UTC (rev 7010)
+++
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/AbstractSearchCommand.java
2008-12-02 17:25:36 UTC (rev 7011)
@@ -18,6 +18,8 @@
package no.sesat.search.mode.command;
+import java.util.Properties;
+import javax.xml.parsers.DocumentBuilder;
import no.sesat.search.mode.command.querybuilder.BaseFilterBuilder;
import java.io.Serializable;
import java.lang.reflect.Constructor;
@@ -36,7 +38,6 @@
import no.sesat.commons.visitor.Visitor;
import no.sesat.search.query.XorClause;
import no.sesat.search.query.parser.AbstractQueryParserContext;
-import no.sesat.commons.visitor.AbstractReflectionVisitor;
import no.sesat.search.query.parser.QueryParser;
import no.sesat.search.query.parser.QueryParserImpl;
import no.sesat.search.query.parser.TokenMgrError;
@@ -56,8 +57,9 @@
import no.sesat.search.site.Site;
import no.sesat.search.site.SiteContext;
import no.sesat.search.site.config.BytecodeLoader;
+import no.sesat.search.site.config.DocumentLoader;
+import no.sesat.search.site.config.PropertiesLoader;
import no.sesat.search.view.config.SearchTab;
-import static no.sesat.search.view.navigation.NavigationConfig.USER_SORT_KEY;
import org.apache.commons.lang.time.StopWatch;
import org.apache.log4j.Logger;
import org.apache.log4j.MDC;
@@ -74,7 +76,6 @@
import no.sesat.search.query.token.TokenPredicateUtility;
import no.sesat.search.site.config.SiteClassLoaderFactory;
import no.sesat.search.site.config.Spi;
-import no.sesat.search.view.navigation.NavigationConfig.Nav;
/** The base abstraction for Search Commands providing a large framework for
commands to run against.
*
<br/><br/>
@@ -127,8 +128,12 @@
private transient final QueryBuilder queryBuilder;
private transient final SesamSyntaxQueryBuilder displayableQueryBuilder;
private transient final FilterBuilder filterBuilder;
+ private transient final BaseSearchConfiguration baseSearchConfiguration;
protected final String untransformedQuery;
+ protected transient final DataModel datamodel;
+ protected transient final Map<String,StringDataObject> datamodelParameters;
+
private final Map<Clause, String> transformedTerms = new
LinkedHashMap<Clause, String>();
private String transformedQuery;
private String transformedQuerySesamSyntax;
@@ -136,9 +141,9 @@
private final SearchCommandParameter offsetParameter;
private final SearchCommandParameter userSortByParameter;
- protected transient final DataModel datamodel;
-
+ // thread execution handling
protected volatile boolean completed = false;
+ // thread execution handling
private volatile Thread thread = null;
// Static --------------------------------------------------------
@@ -158,6 +163,8 @@
this.context = cxt;
this.datamodel = cxt.getDataModel();
+ this.baseSearchConfiguration = (BaseSearchConfiguration)
cxt.getSearchConfiguration();
+ this.datamodelParameters =
Collections.unmodifiableMap(datamodel.getParameters().getValues());
// do not use this.getSearchConfiguration() in constructor -- it's a
overridable method.
final BaseSearchConfiguration bsc = (BaseSearchConfiguration)
context.getSearchConfiguration();
@@ -177,59 +184,60 @@
};
// Little more complicated context for QueryBuilder.Context (can be
used for QueryTransformer.Context too)
- queryBuilderContext = ContextWrapper.wrap(
- QueryBuilder.Context.class,
- new BaseContext(){
- public Site getSite() {
- return datamodel.getSite().getSite();
- }
+ // dont use ContextWrapper.wrap(..) here as this context really gets
hammered and we want to avoid reflection
+ queryBuilderContext = new QueryBuilder.Context(){
+ public Site getSite() {
+ return datamodel.getSite().getSite();
+ }
+ /** @deprecated [EMAIL PROTECTED] **/
+ public String getTransformedQuery() {
+ return transformedQuery;
+ }
+ public Query getQuery() {
+ // Important that initialiseQuery() has been called first
+ return getSearchCommandsQuery();
+ }
+ public TokenEvaluationEngine getTokenEvaluationEngine() {
+ return engine;
+ }
+ public void visitXorClause(final Visitor visitor, final
XorClause clause) {
+ searchCommandsVisitXorClause(visitor, clause);
+ }
+ public String getFieldFilter(final LeafClause clause) {
+ return getSearchCommandsFieldFilter(clause);
+ }
+ public String getTransformedTerm(final Clause clause) {
- public String getTransformedQuery() {
- return transformedQuery;
- }
+ // unable to delegate to getTransformedTerm as it escapes
reserved words
+ // and we're not allowed to here
+ final String transformedTerm =
transformedTerms.get(clause);
+ return null != transformedTerm ? transformedTerm :
clause.getTerm();
+ }
+ public Collection<String> getReservedWords() {
- public Query getQuery() {
- // Important that initialiseQuery() has been called
first
- return getSearchCommandsQuery();
- }
+ return getSearchCommandsReservedWords();
+ }
+ public String escape(final String word) {
- public TokenEvaluationEngine getTokenEvaluationEngine() {
- return engine;
- }
+ return searchCommandsEscape(word);
+ }
+ public Map<Clause, String> getTransformedTerms() {
+ return getSearchCommandsTransformedTerms();
+ }
+ public DocumentLoader newDocumentLoader(SiteContext siteCxt,
String resource, DocumentBuilder builder) {
+ return cxt.newDocumentLoader(siteCxt, resource, builder);
+ }
+ public PropertiesLoader newPropertiesLoader(SiteContext
siteCxt, String resource, Properties properties) {
+ return cxt.newPropertiesLoader(siteCxt, resource,
properties);
+ }
+ public BytecodeLoader newBytecodeLoader(SiteContext
siteContext, String className, String jarFileName) {
+ return cxt.newBytecodeLoader(siteContext, className,
jarFileName);
+ }
+ public DataModel getDataModel() {
+ return cxt.getDataModel();
+ }
+ };
- public void visitXorClause(final Visitor visitor, final
XorClause clause) {
- searchCommandsVisitXorClause(visitor, clause);
- }
-
- public String getFieldFilter(final LeafClause clause) {
- return getSearchCommandsFieldFilter(clause);
- }
-
- public String getTransformedTerm(final Clause clause) {
-
- // unable to delegate to getTransformedTerm as it
escapes reserved words
- // and we're not allowed to here
- final String transformedTerm =
transformedTerms.get(clause);
- return null != transformedTerm ? transformedTerm :
clause.getTerm();
- }
-
- public Collection<String> getReservedWords() {
-
- return getSearchCommandsReservedWords();
- }
-
- public String escape(final String word) {
-
- return searchCommandsEscape(word);
- }
-
- public Map<Clause, String> getTransformedTerms() {
- return getSearchCommandsTransformedTerms();
- }
- },
- cxt
- );
-
// initialise the transformed terms
initialQueryTransformer = new QueryTransformerFactory(qtfContext)
.getController(bsc.getInitialQueryTransformer());
@@ -242,7 +250,7 @@
// construct the sesamSyntaxQueryBuilder
displayableQueryBuilder = new
SesamSyntaxQueryBuilder(queryBuilderContext, bsc);
- // FIXME implement configuration lookup
+ // FIXME (in 2.18) implement configuration lookup
filterBuilder = new BaseFilterBuilder(queryBuilderContext, null);
// run an initial queryBuilder run and store the untransformed
resulting queryString.
@@ -305,7 +313,7 @@
// SearchCommand overrides
---------------------------------------------------
public BaseSearchConfiguration getSearchConfiguration() {
- return (BaseSearchConfiguration) context.getSearchConfiguration();
+ return baseSearchConfiguration;
}
/**
@@ -624,8 +632,7 @@
*/
protected String getParameter(final String paramName) {
- final Map<String, StringDataObject> parameters =
datamodel.getParameters().getValues();
- return parameters.containsKey(paramName) ?
parameters.get(paramName).getString() : null;
+ return datamodelParameters.containsKey(paramName) ?
datamodelParameters.get(paramName).getString() : null;
}
// <-- Query Representation state methods (useful while the inbuilt
visitor is in operation)
@@ -662,6 +669,8 @@
*
* @param paramName parameter name
* @return null when array is null
+ *
+ * @deprecated use getParameter(string) instead
*/
protected final String getSingleParameter(final String paramName) {
@@ -839,7 +848,7 @@
if (queryParameter != null && queryParameter.length() > 0) {
// It's not the query we are looking for but a string held in a
different parameter.
- final StringDataObject queryToUse =
datamodel.getParameters().getValue(queryParameter);
+ final StringDataObject queryToUse =
datamodelParameters.get(queryParameter);
if (queryToUse != null) {
final ReconstructedQuery recon =
createQuery(queryToUse.getString());
query = recon.getQuery();
@@ -860,6 +869,8 @@
final QueryTransformerFactory queryTransformerFactory = new
QueryTransformerFactory(qtfContext);
+ final Map<String,Object> junkYard =
datamodel.getJunkYard().getValues();
+
for (QueryTransformerConfig transformerConfig : transformers) {
final QueryTransformer transformer =
queryTransformerFactory.getController(transformerConfig);
@@ -891,7 +902,7 @@
transformedQuery = getQueryRepresentation();
}
-
addFilterString(transformer.getFilter(datamodel.getJunkYard().getValues()));
+ addFilterString(transformer.getFilter(junkYard));
addFilterString(transformer.getFilter());
Modified:
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/BaseSearchCommandParameter.java
===================================================================
---
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/BaseSearchCommandParameter.java
2008-12-02 13:22:38 UTC (rev 7010)
+++
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/BaseSearchCommandParameter.java
2008-12-02 17:25:36 UTC (rev 7011)
@@ -22,7 +22,9 @@
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
+import no.sesat.search.datamodel.DataModel;
import no.sesat.search.datamodel.generic.StringDataObject;
+import no.sesat.search.mode.config.SearchConfiguration;
import org.apache.log4j.Logger;
/** A base implementation that provides looking up the value in order from a
number of sources.
@@ -38,6 +40,8 @@
*/
class BaseSearchCommandParameter implements SearchCommandParameter {
+ // Static --------------------------------------------------------
+
private static final Logger LOG =
Logger.getLogger(BaseSearchCommandParameter.class);
protected enum Origin {
@@ -61,6 +65,8 @@
CUSTOM
};
+ // Attributes ----------------------------------------------------
+
private final String name;
private final Origin[] lookupOrder;
@@ -69,6 +75,12 @@
private final SearchCommand.Context context;
+ private final SearchConfiguration searchConfiguration;
+
+ private final DataModel datamodel;
+
+ // Constructors --------------------------------------------------
+
BaseSearchCommandParameter(
final SearchCommand.Context context,
final String name,
@@ -77,8 +89,12 @@
this.context = context;
this.name = name;
this.lookupOrder = Arrays.copyOf(lookupOrder, lookupOrder.length);
+ this.searchConfiguration = context.getSearchConfiguration();
+ this.datamodel = context.getDataModel();
}
+ // Public --------------------------------------------------------
+
public String getName() {
return name;
}
@@ -101,7 +117,7 @@
switch (origin) {
case REQUEST:
- final StringDataObject sdo =
context.getDataModel().getParameters().getValue(name);
+ final StringDataObject sdo =
datamodel.getParameters().getValue(name);
if (null != sdo) {
result = sdo.getString();
@@ -109,14 +125,14 @@
break;
case USER:
- result =
context.getDataModel().getUser().getUser().getUserPropertiesMap().get(name);
+ result =
datamodel.getUser().getUser().getUserPropertiesMap().get(name);
break;
case CONFIGURATION:
try{
final PropertyDescriptor[] properties =
Introspector.getBeanInfo(
-
context.getSearchConfiguration().getClass())
+ searchConfiguration.getClass())
.getPropertyDescriptors();
for (PropertyDescriptor property : properties) {
@@ -125,7 +141,7 @@
if (null != property.getReadMethod()) {
result = (String)
property.getReadMethod().invoke(
-
context.getSearchConfiguration(),
+ searchConfiguration,
new Object[0]);
break;
@@ -155,6 +171,10 @@
}
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
/** The origin the current value was found from.
*
* @return the origin the current value was found from.
@@ -175,4 +195,5 @@
return context;
}
+ // Private -------------------------------------------------------
}
Modified:
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/NavigationSearchCommandParameter.java
===================================================================
---
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/NavigationSearchCommandParameter.java
2008-12-02 13:22:38 UTC (rev 7010)
+++
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/NavigationSearchCommandParameter.java
2008-12-02 17:25:36 UTC (rev 7011)
@@ -18,6 +18,7 @@
*/
package no.sesat.search.mode.command;
+import no.sesat.search.datamodel.navigation.NavigationDataObject;
import no.sesat.search.view.navigation.NavigationConfig.Nav;
/** Implementation that handles parameters that are related to the navigation
configuration.
@@ -28,8 +29,16 @@
*/
class NavigationSearchCommandParameter extends BaseSearchCommandParameter {
+ // Static --------------------------------------------------------
+ // Attributes ----------------------------------------------------
+
private final String navigationMapKey;
+ private final NavigationDataObject navDO;
+
+ // Constructors --------------------------------------------------
+ // Public --------------------------------------------------------
+
public NavigationSearchCommandParameter(
final SearchCommand.Context context,
final String name,
@@ -38,6 +47,7 @@
super(context, name, lookupOrder);
this.navigationMapKey = navigationMapKey;
+ this.navDO = context.getDataModel().getNavigation();
}
/** [EMAIL PROTECTED]
@@ -51,15 +61,18 @@
@Override
public boolean isActive() {
- final boolean navMapExists =
- null != getContext().getDataModel().getNavigation()
- && null !=
getContext().getDataModel().getNavigation().getConfiguration();
+ final boolean navMapExists = null != navDO && null !=
navDO.getConfiguration();
final Nav nav = navMapExists
- ?
getContext().getDataModel().getNavigation().getConfiguration().getNavMap().get(navigationMapKey)
+ ? navDO.getConfiguration().getNavMap().get(navigationMapKey)
: null;
return null != nav &&
getContext().getSearchConfiguration().getId().equals(nav.getCommandName());
}
+
+ // Package protected ---------------------------------------------
+ // Protected -----------------------------------------------------
+ // Private -------------------------------------------------------
+
}
Modified:
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/AbstractQueryBuilder.java
===================================================================
---
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/AbstractQueryBuilder.java
2008-12-02 13:22:38 UTC (rev 7010)
+++
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/AbstractQueryBuilder.java
2008-12-02 17:25:36 UTC (rev 7011)
@@ -17,7 +17,6 @@
package no.sesat.search.mode.command.querybuilder;
import java.util.Collection;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
import no.sesat.search.mode.config.querybuilder.QueryBuilderConfig;
import no.sesat.search.query.Clause;
@@ -25,7 +24,6 @@
import no.sesat.search.query.LeafClause;
import no.sesat.search.query.NotClause;
import no.sesat.search.query.UnaryClause;
-import no.sesat.search.query.Query;
import no.sesat.search.query.XorClause;
import no.sesat.commons.visitor.AbstractReflectionVisitor;
Modified: branches/2.18/site-spi/src/main/java/no/sesat/search/site/Site.java
===================================================================
--- branches/2.18/site-spi/src/main/java/no/sesat/search/site/Site.java
2008-12-02 13:22:38 UTC (rev 7010)
+++ branches/2.18/site-spi/src/main/java/no/sesat/search/site/Site.java
2008-12-02 17:25:36 UTC (rev 7011)
@@ -29,6 +29,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import no.sesat.commons.ioc.BaseContext;
import org.apache.log4j.Level;
@@ -90,6 +91,7 @@
private static final String CORE_CONF_FILE = "core.properties";
private static final Map<String,Site> INSTANCES = new
HashMap<String,Site>();
private static final ReentrantReadWriteLock INSTANCES_LOCK = new
ReentrantReadWriteLock();
+ private static final Map<Locale,String> LOCALE_DISPLAY_NAMES = new
ConcurrentHashMap<Locale, String>();
private static volatile boolean constructingDefault = false;
@@ -377,7 +379,13 @@
*/
public static String getUniqueName(final String siteName, final Locale
locale) {
- return siteName + '[' + locale.getDisplayName() + ']';
+ String localDisplayName = LOCALE_DISPLAY_NAMES.get(locale);
+ if(null == localDisplayName){
+ localDisplayName = locale.getDisplayName();
+ LOCALE_DISPLAY_NAMES.put(locale, localDisplayName);
+ }
+
+ return siteName + '[' + localDisplayName + ']';
}
private static String ensureTrailingSlash(final String theSiteName) {
@@ -406,6 +414,7 @@
}
return res;
}
+ @Override
public String describe() {
return "List content of INSTANCES in Site.";
}
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits