Author: rdonkin
Date: Sun May 8 17:09:22 2011
New Revision: 1100774
URL: http://svn.apache.org/viewvc?rev=1100774&view=rev
Log:
Factor out inner class used to reload corpus.
Added:
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/CorpusLoaderThread.java
(with props)
Modified:
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalysis.java
Modified:
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalysis.java
URL:
http://svn.apache.org/viewvc/james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalysis.java?rev=1100774&r1=1100773&r2=1100774&view=diff
==============================================================================
---
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalysis.java
(original)
+++
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalysis.java
Sun May 8 17:09:22 2011
@@ -139,12 +139,12 @@ public class BayesianAnalysis extends Ge
}
};
- private DataSource datasource;
+ DataSource datasource;
private String repositoryPath;
private static final String MAIL_ATTRIBUTE_NAME =
"org.apache.james.spam.probability";
private static final String HEADER_NAME = "X-MessageIsSpamProbability";
- private static final long CORPUS_RELOAD_INTERVAL = 600000;
+ static final long CORPUS_RELOAD_INTERVAL = 600000;
private String headerName;
private boolean ignoreLocalSender = false;
private boolean tagSubject = true;
@@ -345,7 +345,7 @@ public class BayesianAnalysis extends Ge
}
}
- private void loadData(Connection conn) throws java.sql.SQLException {
+ void loadData(Connection conn) throws java.sql.SQLException {
try {
// this is synchronized to avoid concurrent update of the corpus
@@ -410,46 +410,4 @@ public class BayesianAnalysis extends Ge
}
}
- private static class CorpusLoaderThread extends Thread {
-
- private BayesianAnalysis analysis;
-
- private CorpusLoaderThread(BayesianAnalysis analysis) {
- super("BayesianAnalysis Corpus Loader");
- this.analysis = analysis;
- }
-
- /**
- * Thread entry point.
- */
- public void run() {
- analysis.log("CorpusLoader thread started: will wake up every " +
CORPUS_RELOAD_INTERVAL + " ms");
-
- try {
- Thread.sleep(CORPUS_RELOAD_INTERVAL);
-
- while (true) {
- if (analysis.getLastCorpusLoadTime() <
JDBCBayesianAnalyzer.getLastDatabaseUpdateTime()) {
- analysis.log("Reloading Corpus ...");
- try {
-
analysis.loadData(analysis.datasource.getConnection());
- analysis.log("Corpus reloaded");
- } catch (java.sql.SQLException se) {
- analysis.log("SQLException: ", se);
- }
-
- }
-
- if (Thread.interrupted()) {
- break;
- }
- Thread.sleep(CORPUS_RELOAD_INTERVAL);
- }
- } catch (InterruptedException ex) {
- interrupt();
- }
- }
-
- }
-
}
Added:
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/CorpusLoaderThread.java
URL:
http://svn.apache.org/viewvc/james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/CorpusLoaderThread.java?rev=1100774&view=auto
==============================================================================
---
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/CorpusLoaderThread.java
(added)
+++
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/CorpusLoaderThread.java
Sun May 8 17:09:22 2011
@@ -0,0 +1,65 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.ai.classic;
+
+/**
+ * Periodically reloads corpus.
+ */
+class CorpusLoaderThread extends Thread {
+
+ private BayesianAnalysis analysis;
+
+ CorpusLoaderThread(BayesianAnalysis analysis) {
+ super("BayesianAnalysis Corpus Loader");
+ this.analysis = analysis;
+ }
+
+ /**
+ * Thread entry point.
+ */
+ public void run() {
+ analysis.log("CorpusLoader thread started: will wake up every " +
BayesianAnalysis.CORPUS_RELOAD_INTERVAL + " ms");
+
+ try {
+ Thread.sleep(BayesianAnalysis.CORPUS_RELOAD_INTERVAL);
+
+ while (true) {
+ if (analysis.getLastCorpusLoadTime() <
JDBCBayesianAnalyzer.getLastDatabaseUpdateTime()) {
+ analysis.log("Reloading Corpus ...");
+ try {
+ analysis.loadData(analysis.datasource.getConnection());
+ analysis.log("Corpus reloaded");
+ } catch (java.sql.SQLException se) {
+ analysis.log("SQLException: ", se);
+ }
+
+ }
+
+ if (Thread.interrupted()) {
+ break;
+ }
+ Thread.sleep(BayesianAnalysis.CORPUS_RELOAD_INTERVAL);
+ }
+ } catch (InterruptedException ex) {
+ interrupt();
+ }
+ }
+
+}
\ No newline at end of file
Propchange:
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/CorpusLoaderThread.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]