Skip to content

Commit

Permalink
JAMES-2114 Deprecate the mailet Logging APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
chibenwa committed Aug 24, 2017
1 parent ecccda0 commit f35ab92
Show file tree
Hide file tree
Showing 90 changed files with 739 additions and 792 deletions.
Expand Up @@ -37,6 +37,8 @@
import org.apache.mailet.MailAddress;
import org.apache.mailet.base.GenericMailet;
import org.apache.mailet.base.RFC2822Headers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* <p>
Expand Down Expand Up @@ -121,16 +123,17 @@
* @since 2.3.0
*/
@Experimental
public class BayesianAnalysis extends GenericMailet implements Log {
public class BayesianAnalysis extends GenericMailet {
private static final Logger LOGGER = LoggerFactory.getLogger(BayesianAnalysis.class);
/**
* The JDBCUtil helper class
*/
private final JDBCUtil theJDBCUtil = new JDBCUtil(this);
private final JDBCUtil theJDBCUtil = new JDBCUtil();

/**
* The JDBCBayesianAnalyzer class that does all the work.
*/
private final JDBCBayesianAnalyzer analyzer = new JDBCBayesianAnalyzer(this);
private final JDBCBayesianAnalyzer analyzer = new JDBCBayesianAnalyzer();

DataSource datasource;

Expand Down Expand Up @@ -229,16 +232,16 @@ public void init() throws MessagingException {
ignoreLocalSender = Boolean.valueOf(getInitParameter("ignoreLocalSender"));

if (ignoreLocalSender) {
log("Will ignore messages coming from local senders");
LOGGER.debug("Will ignore messages coming from local senders");
} else {
log("Will analyze messages coming from local senders");
LOGGER.debug("Will analyze messages coming from local senders");
}

String maxSizeParam = getInitParameter("maxSize");
if (maxSizeParam != null) {
setMaxSize(Integer.parseInt(maxSizeParam));
}
log("maxSize: " + getMaxSize());
LOGGER.debug("maxSize: " + getMaxSize());

String tag = getInitParameter("tagSubject");
if (tag != null && tag.equals("false")) {
Expand Down Expand Up @@ -318,7 +321,7 @@ public void service(Mail mail) throws MessagingException {
}
if (probability > 0.1) {
final Collection<MailAddress> recipients = mail.getRecipients();
log(headerName + ": " + probabilityString + "; From: " + senderString + "; Recipient(s): " + getAddressesString(recipients));
LOGGER.debug(headerName + ": " + probabilityString + "; From: " + senderString + "; Recipient(s): " + getAddressesString(recipients));

// Check if we should tag the subject
if (tagSubject) {
Expand All @@ -329,7 +332,7 @@ public void service(Mail mail) throws MessagingException {
saveChanges(message);

} catch (Exception e) {
log("Exception: " + e.getMessage(), e);
LOGGER.error("Exception: " + e.getMessage(), e);
throw new MessagingException("Exception thrown", e);
}
}
Expand All @@ -349,7 +352,7 @@ void loadData(Connection conn) throws java.sql.SQLException {
analyzer.tokenCountsClear();
}

log("BayesianAnalysis Corpus loaded");
LOGGER.error("BayesianAnalysis Corpus loaded");

touchLastCorpusLoadTime();

Expand Down Expand Up @@ -389,7 +392,7 @@ private void appendToSubject(MimeMessage message, String toAppend) {
message.setSubject(toAppend + " " + subject, "iso-8859-1");
}
} catch (MessagingException ex) {
log("Failure to append to subject phrase: '" + toAppend + "'", ex);
LOGGER.error("Failure to append to subject phrase: '" + toAppend + "'", ex);
}
}

Expand Down
Expand Up @@ -34,6 +34,8 @@
import org.apache.mailet.Experimental;
import org.apache.mailet.Mail;
import org.apache.mailet.base.GenericMailet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* <p>
Expand Down Expand Up @@ -125,16 +127,18 @@
* @since 2.3.0
*/
@Experimental
public class BayesianAnalysisFeeder extends GenericMailet implements Log {
public class BayesianAnalysisFeeder extends GenericMailet {
private static final Logger LOGGER = LoggerFactory.getLogger(BayesianAnalysisFeeder.class);

/**
* The JDBCUtil helper class
*/
private final JDBCUtil theJDBCUtil = new JDBCUtil(this);
private final JDBCUtil theJDBCUtil = new JDBCUtil();

/**
* The JDBCBayesianAnalyzer class that does all the work.
*/
private final JDBCBayesianAnalyzer analyzer = new JDBCBayesianAnalyzer(this);
private final JDBCBayesianAnalyzer analyzer = new JDBCBayesianAnalyzer();

private DataSource datasource;

Expand Down Expand Up @@ -209,7 +213,7 @@ public void init() throws MessagingException {
if (maxSizeParam != null) {
setMaxSize(Integer.parseInt(maxSizeParam));
}
log("maxSize: " + getMaxSize());
LOGGER.debug("maxSize: " + getMaxSize());

initDb();

Expand Down Expand Up @@ -250,7 +254,7 @@ public void service(Mail mail) {
String messageId = message.getMessageID();

if (message.getSize() > getMaxSize()) {
log(messageId + " Feeding HAM/SPAM ignored because message size > " + getMaxSize() + ": " + message.getSize());
LOGGER.debug(messageId + " Feeding HAM/SPAM ignored because message size > " + getMaxSize() + ": " + message.getSize());
return;
}

Expand All @@ -275,14 +279,14 @@ public void service(Mail mail) {
analyzer.clear();

if ("ham".equalsIgnoreCase(feedType)) {
log(messageId + " Feeding HAM");
LOGGER.debug(messageId + " Feeding HAM");
// Process the stream as ham (not spam).
analyzer.addHam(br);

// Update storage statistics.
analyzer.updateHamTokens(conn);
} else {
log(messageId + " Feeding SPAM");
LOGGER.debug(messageId + " Feeding SPAM");
// Process the stream as spam.
analyzer.addSpam(br);

Expand All @@ -294,18 +298,18 @@ public void service(Mail mail) {
if (conn != null && dbUpdated && !conn.getAutoCommit()) {
conn.commit();
dbUpdated = false;
log(messageId + " Training ended successfully");
LOGGER.debug(messageId + " Training ended successfully");
JDBCBayesianAnalyzer.touchLastDatabaseUpdateTime();
}

}

} catch (java.sql.SQLException se) {
log("SQLException: " + se.getMessage());
LOGGER.error("SQLException: ", se);
} catch (java.io.IOException ioe) {
log("IOException: " + ioe.getMessage());
LOGGER.error("IOException: ", ioe);
} catch (javax.mail.MessagingException me) {
log("MessagingException: " + me.getMessage());
LOGGER.error("MessagingException: ", me);
} finally {
// Rollback our changes if necessary.
try {
Expand All @@ -314,7 +318,7 @@ public void service(Mail mail) {
dbUpdated = false;
}
} catch (Exception e) {
log("Failed to rollback after last error.", e);
LOGGER.error("Failed to rollback after last error.", e);
}
theJDBCUtil.closeJDBCConnection(conn);
}
Expand All @@ -329,7 +333,7 @@ private void clearAllHeaders(MimeMessage message) throws javax.mail.MessagingExc
try {
message.removeHeader(header.getName());
} catch (javax.mail.MessagingException me) {
log("Cannot remove header.", me);
LOGGER.error("Cannot remove header.", me);
}
}
message.saveChanges();
Expand Down
Expand Up @@ -19,10 +19,14 @@

package org.apache.james.ai.classic;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Periodically reloads corpus.
*/
class CorpusLoaderThread extends Thread {
private static final Logger LOGGER = LoggerFactory.getLogger(CorpusLoaderThread.class);

private final BayesianAnalysis analysis;

Expand All @@ -35,19 +39,19 @@ class CorpusLoaderThread extends Thread {
* Thread entry point.
*/
public void run() {
analysis.log("CorpusLoader thread started: will wake up every " + BayesianAnalysis.CORPUS_RELOAD_INTERVAL + " ms");
LOGGER.info("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 ...");
LOGGER.info("Reloading Corpus ...");
try {
analysis.loadData(analysis.datasource.getConnection());
analysis.log("Corpus reloaded");
LOGGER.info("Corpus reloaded");
} catch (java.sql.SQLException se) {
analysis.log("SQLException: ", se);
LOGGER.error("SQLException: ", se);
}

}
Expand Down

0 comments on commit f35ab92

Please sign in to comment.