You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rd...@apache.org on 2009/09/17 13:10:53 UTC
svn commit: r816137 - in
/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server:
POP3HandlerChain.java POP3Server.java
Author: rdonkin
Date: Thu Sep 17 11:10:53 2009
New Revision: 816137
URL: http://svn.apache.org/viewvc?rev=816137&view=rev
Log:
JAMES-922 Switch chain to use commons logging https://issues.apache.org/jira/browse/JAMES-922
Modified:
james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3HandlerChain.java
james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java
Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3HandlerChain.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3HandlerChain.java?rev=816137&r1=816136&r2=816137&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3HandlerChain.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3HandlerChain.java Thu Sep 17 11:10:53 2009
@@ -21,29 +21,36 @@
package org.apache.james.pop3server;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Properties;
+
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Properties;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* The POP3HandlerChain is per service object providing access
* ConnectHandlers, Commandhandlers and message handlers
*/
-public class POP3HandlerChain extends AbstractLogEnabled implements Configurable, Serviceable {
+public class POP3HandlerChain implements Configurable, Serviceable {
+ /** This log is the fall back shared by all instances */
+ private static final Log FALLBACK_LOG = LogFactory.getLog(POP3HandlerChain.class);
+
+ /** Non context specific log should only be used when no context specific log is available */
+ private Log log = FALLBACK_LOG;
+
private HashMap commandHandlerMap = new HashMap();
private ArrayList messageHandlers = new ArrayList();
private ArrayList connectHandlers = new ArrayList();
@@ -53,6 +60,15 @@
private final static String[] mandatoryCommands = { "USER" , "PASS", "LIST"};
+ /**
+ * Sets the service log.
+ * Where available, a context sensitive log should be used.
+ * @param Log not null
+ */
+ public void setLog(Log log) {
+ this.log = log;
+ }
+
public void service(ServiceManager serviceManager) throws ServiceException {
this.serviceManager = serviceManager;
}
@@ -99,9 +115,6 @@
try {
Object handler = classLoader.loadClass(className).newInstance();
- //enable logging
- ContainerUtil.enableLogging(handler, getLogger());
-
//servicing the handler
ContainerUtil.service(handler,serviceManager);
@@ -111,8 +124,8 @@
//if it is a connect handler add it to list of connect handlers
if(handler instanceof ConnectHandler) {
connectHandlers.add((ConnectHandler)handler);
- if (getLogger().isInfoEnabled()) {
- getLogger().info("Added ConnectHandler: " + className);
+ if (log.isInfoEnabled()) {
+ log.info("Added ConnectHandler: " + className);
}
}
@@ -121,27 +134,27 @@
String commandName = children[i].getAttribute("command");
commandName = commandName.toUpperCase(Locale.US);
addToMap(commandName, (CommandHandler)handler);
- if (getLogger().isInfoEnabled()) {
- getLogger().info("Added Commandhandler: " + className);
+ if (log.isInfoEnabled()) {
+ log.info("Added Commandhandler: " + className);
}
}
} catch (ClassNotFoundException ex) {
- if (getLogger().isErrorEnabled()) {
- getLogger().error("Failed to add Commandhandler: " + className,ex);
+ if (log.isErrorEnabled()) {
+ log.error("Failed to add Commandhandler: " + className,ex);
}
} catch (IllegalAccessException ex) {
- if (getLogger().isErrorEnabled()) {
- getLogger().error("Failed to add Commandhandler: " + className,ex);
+ if (log.isErrorEnabled()) {
+ log.error("Failed to add Commandhandler: " + className,ex);
}
} catch (InstantiationException ex) {
- if (getLogger().isErrorEnabled()) {
- getLogger().error("Failed to add Commandhandler: " + className,ex);
+ if (log.isErrorEnabled()) {
+ log.error("Failed to add Commandhandler: " + className,ex);
}
} catch (ServiceException e) {
- if (getLogger().isErrorEnabled()) {
- getLogger().error("Failed to service Commandhandler: " + className,e);
+ if (log.isErrorEnabled()) {
+ log.error("Failed to service Commandhandler: " + className,e);
}
}
}
@@ -151,16 +164,16 @@
//the size must be greater than 1 because we added UnknownCmdHandler to the map
if(commandHandlerMap.size() < 2) {
- if (getLogger().isErrorEnabled()) {
- getLogger().error("No commandhandlers configured");
+ if (log.isErrorEnabled()) {
+ log.error("No commandhandlers configured");
}
throw new ConfigurationException("No commandhandlers configured");
} else {
boolean found = true;
for (int i = 0; i < mandatoryCommands.length; i++) {
if(!commandHandlerMap.containsKey(mandatoryCommands[i])) {
- if (getLogger().isErrorEnabled()) {
- getLogger().error("No commandhandlers configured for the command:" + mandatoryCommands[i]);
+ if (log.isErrorEnabled()) {
+ log.error("No commandhandlers configured for the command:" + mandatoryCommands[i]);
}
found = false;
break;
@@ -199,8 +212,8 @@
if (command == null) {
return null;
}
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Lookup command handler for command: " + command);
+ if (log.isDebugEnabled()) {
+ log.debug("Lookup command handler for command: " + command);
}
List handlers = (List)commandHandlerMap.get(command);
if(handlers == null) {
Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java?rev=816137&r1=816136&r2=816137&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java Thu Sep 17 11:10:53 2009
@@ -26,6 +26,7 @@
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.commons.logging.impl.AvalonLogger;
import org.apache.james.api.user.UsersRepository;
import org.apache.james.services.MailServer;
import org.apache.james.socket.AbstractProtocolServer;
@@ -103,17 +104,7 @@
if (getLogger().isInfoEnabled()) {
getLogger().info("The idle timeout will be reset every " + lengthReset + " bytes.");
}
- //set the logger
- ContainerUtil.enableLogging(handlerChain,getLogger());
-
- try {
- ContainerUtil.service(handlerChain,serviceManager);
- } catch (ServiceException e) {
- if (getLogger().isErrorEnabled()) {
- getLogger().error("Failed to service handlerChain",e);
- }
- throw new ConfigurationException("Failed to service handlerChain");
- }
+ prepareHandlerChain();
//read from the XML configuration and create and configure each of the handlers
ContainerUtil.configure(handlerChain,handlerConfiguration.getChild("handlerchain"));
@@ -121,6 +112,20 @@
}
}
+ private void prepareHandlerChain() throws ConfigurationException {
+ //set the logger
+ handlerChain.setLog(new AvalonLogger(getLogger()));
+
+ try {
+ ContainerUtil.service(handlerChain,serviceManager);
+ } catch (ServiceException e) {
+ if (getLogger().isErrorEnabled()) {
+ getLogger().error("Failed to service handlerChain",e);
+ }
+ throw new ConfigurationException("Failed to service handlerChain");
+ }
+ }
+
/**
* @see org.apache.james.socket.AbstractProtocolServer#getDefaultPort()
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org