Author: rdonkin
Date: Fri Sep  4 20:04:09 2009
New Revision: 811529

URL: http://svn.apache.org/viewvc?rev=811529&view=rev
Log:
Prepare handling chain only during initialisation

Modified:
    
james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/AbstractJamesService.java
    
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java
    
james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java

Modified: 
james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/AbstractJamesService.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/AbstractJamesService.java?rev=811529&r1=811528&r2=811529&view=diff
==============================================================================
--- 
james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/AbstractJamesService.java
 (original)
+++ 
james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/AbstractJamesService.java
 Fri Sep  4 20:04:09 2009
@@ -456,6 +456,8 @@
         }
         getLogger().debug(getServiceType() + " init...");
 
+        prepareInit();
+        
         // keeping these looked up services locally, because they are only 
needed beyond initialization
         ThreadManager threadManager = (ThreadManager) 
componentManager.lookup(ThreadManager.ROLE);
         SocketManager socketManager = (SocketManager) 
componentManager.lookup(SocketManager.ROLE);
@@ -478,6 +480,17 @@
         doInit();
     }
     
+    
+    /**
+     * Hook for subclasses to perform an required initialisation
+     * before the superclass has been initialised.
+     * Called before the super class has completed it's initialisation.
+     * @throws Exception
+     */
+    protected void prepareInit() throws Exception {
+        
+    }
+    
     /**
      * Hook for subclasses to perform an required initialisation.
      * Called after the super class has completed it's initialisation.

Modified: 
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java?rev=811529&r1=811528&r2=811529&view=diff
==============================================================================
--- 
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java
 (original)
+++ 
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java
 Fri Sep  4 20:04:09 2009
@@ -81,6 +81,9 @@
     /** Loads instances */
     private LoaderService loader;
     
+    /** Cached configuration data for handler */
+    private Configuration handlerConfiguration;
+    
     /**
      * Whether authentication is required to use
      * this SMTP server.
@@ -170,7 +173,7 @@
             // TODO Remove this in next not backwards compatible release!
             if (hello == null) 
mailetcontext.setAttribute(Constants.HELLO_NAME, helloName);
             
-            Configuration handlerConfiguration = 
configuration.getChild("handler");
+            handlerConfiguration = configuration.getChild("handler");
             String authRequiredString = 
handlerConfiguration.getChild("authRequired").getValue("false").trim().toLowerCase();
             if (authRequiredString.equals("true")) authRequired = 
AUTH_REQUIRED;
             else if (authRequiredString.equals("announce")) authRequired = 
AUTH_ANNOUNCE;
@@ -240,29 +243,32 @@
             
             addressBracketsEnforcement = 
handlerConfiguration.getChild("addressBracketsEnforcement").getValueAsBoolean(true);
 
-            //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");
-            }
-            
-            //read from the XML configuration and create and configure each of 
the handlers
-            
ContainerUtil.configure(handlerChain,handlerConfiguration.getChild("handlerchain"));
-
         } else {
             // TODO Remove this in next not backwards compatible release!
             if (hello == null) 
mailetcontext.setAttribute(Constants.HELLO_NAME, "localhost");
         }
     }
 
+    private void prepareHandlerChain() throws ConfigurationException {
+        //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");
+        }
+        
+        //read from the XML configuration and create and configure each of the 
handlers
+        
ContainerUtil.configure(handlerChain,handlerConfiguration.getChild("handlerchain"));
+    }
+
     @Override
-    protected void doInit() throws Exception {
+    protected void prepareInit() throws Exception {
+        prepareHandlerChain();
         ContainerUtil.initialize(handlerChain);
     }
 

Modified: 
james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java?rev=811529&r1=811528&r2=811529&view=diff
==============================================================================
--- 
james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
 (original)
+++ 
james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
 Fri Sep  4 20:04:09 2009
@@ -145,7 +145,7 @@
     }
 
 
-    private int m_smtpListenerPort = Util.getNonPrivilegedPort();
+    private final int m_smtpListenerPort;
     private MockMailServer m_mailServer;
     private SMTPTestConfiguration m_testConfiguration;
     private SMTPServer m_smtpServer;
@@ -155,6 +155,7 @@
 
     public SMTPServerTest() {
         super("SMTPServerTest");
+        m_smtpListenerPort = Util.getNonPrivilegedPort();
     }
 
     public void verifyLastMail(String sender, String recipient, MimeMessage 
msg) throws IOException, MessagingException {



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to