You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nutch.apache.org by do...@apache.org on 2007/06/21 17:15:34 UTC
svn commit: r549507 - in /lucene/nutch/trunk: CHANGES.txt
src/java/org/apache/nutch/searcher/NutchBean.java src/web/web.xml
Author: dogacan
Date: Thu Jun 21 08:15:32 2007
New Revision: 549507
URL: http://svn.apache.org/viewvc?view=rev&rev=549507
Log:
NUTCH-471 - Fix synchronization in NutchBean creation.
Modified:
lucene/nutch/trunk/CHANGES.txt
lucene/nutch/trunk/src/java/org/apache/nutch/searcher/NutchBean.java
lucene/nutch/trunk/src/web/web.xml
Modified: lucene/nutch/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/CHANGES.txt?view=diff&rev=549507&r1=549506&r2=549507
==============================================================================
--- lucene/nutch/trunk/CHANGES.txt (original)
+++ lucene/nutch/trunk/CHANGES.txt Thu Jun 21 08:15:32 2007
@@ -54,6 +54,9 @@
There was discussion to remove parse-rss, in light of the feed plugin,
however, this patch does not explicitly remove parse-rss. (dogacan, mattmann)
+17. NUTCH-471 - Fix synchronization in NutchBean creation.
+ (Enis Soztutar via dogacan)
+
Release 0.9 - 2007-04-02
1. Changed log4j confiquration to log to stdout on commandline
Modified: lucene/nutch/trunk/src/java/org/apache/nutch/searcher/NutchBean.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/src/java/org/apache/nutch/searcher/NutchBean.java?view=diff&rev=549507&r1=549506&r2=549507
==============================================================================
--- lucene/nutch/trunk/src/java/org/apache/nutch/searcher/NutchBean.java (original)
+++ lucene/nutch/trunk/src/java/org/apache/nutch/searcher/NutchBean.java Thu Jun 21 08:15:32 2007
@@ -19,7 +19,7 @@
import java.io.*;
import java.util.*;
-import javax.servlet.ServletContext;
+import javax.servlet.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -27,6 +27,7 @@
import org.apache.hadoop.fs.*;
import org.apache.hadoop.io.Closeable;
import org.apache.hadoop.conf.*;
+import org.apache.hadoop.util.StringUtils;
import org.apache.nutch.parse.*;
import org.apache.nutch.indexer.*;
import org.apache.nutch.crawl.Inlinks;
@@ -41,6 +42,7 @@
DistributedSearch.Protocol, Closeable {
public static final Log LOG = LogFactory.getLog(NutchBean.class);
+ public static final String KEY = "nutchBean";
// static {
// LogFormatter.setShowThreadIDs(true);
@@ -63,14 +65,10 @@
private FileSystem fs;
- /** Cache in servlet context. */
+ /** Returns the cached instance in the servlet context.
+ * @see NutchBeanConstructor*/
public static NutchBean get(ServletContext app, Configuration conf) throws IOException {
- NutchBean bean = (NutchBean)app.getAttribute("nutchBean");
- if (bean == null) {
- if (LOG.isInfoEnabled()) { LOG.info("creating new bean"); }
- bean = new NutchBean(conf);
- app.setAttribute("nutchBean", bean);
- }
+ NutchBean bean = (NutchBean)app.getAttribute(KEY);
return bean;
}
@@ -407,6 +405,28 @@
}
}
+ /** Responsible for constructing a NutchBean singleton instance and
+ * caching it in the servlet context. This class should be registered in
+ * the deployment descriptor as a listener
+ */
+ public static class NutchBeanConstructor implements ServletContextListener {
+
+ public void contextDestroyed(ServletContextEvent sce) { }
+ public void contextInitialized(ServletContextEvent sce) {
+ ServletContext app = sce.getServletContext();
+ Configuration conf = NutchConfiguration.get(app);
+
+ LOG.info("creating new bean");
+ NutchBean bean = null;
+ try {
+ bean = new NutchBean(conf);
+ app.setAttribute(KEY, bean);
+ }
+ catch (IOException ex) {
+ LOG.error(StringUtils.stringifyException(ex));
+ }
+ }
+ }
}
Modified: lucene/nutch/trunk/src/web/web.xml
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/src/web/web.xml?view=diff&rev=549507&r1=549506&r2=549507
==============================================================================
--- lucene/nutch/trunk/src/web/web.xml (original)
+++ lucene/nutch/trunk/src/web/web.xml Thu Jun 21 08:15:32 2007
@@ -22,6 +22,10 @@
<!-- order is very important here -->
+<listener>
+ <listener-class>org.apache.nutch.searcher.NutchBean$NutchBeanConstructor</listener-class>
+</listener>
+
<servlet>
<servlet-name>Cached</servlet-name>
<servlet-class>org.apache.nutch.servlet.Cached</servlet-class>