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 no...@apache.org on 2010/04/01 17:47:16 UTC

svn commit: r930014 - in /james/server/trunk: mina-socket/src/main/java/org/apache/james/socket/mina/ remotemanager/src/main/java/org/apache/james/remotemanager/mina/ smtpserver/src/main/java/org/apache/james/smtpserver/ smtpserver/src/main/java/org/ap...

Author: norman
Date: Thu Apr  1 15:47:15 2010
New Revision: 930014

URL: http://svn.apache.org/viewvc?rev=930014&view=rev
Log:
Make sure Mail objects are properly disposed after no longer needed (JAMES-986). This patch includes fixes for the following .m64 leaks:
 * call NioSocketAcceptor.dispose() on shutdown. This will close all open IoSessions which then will tricker the dispose on all Mail objects which are currently in use by the SMTPServer
 * Dispose Mail objects after complete a camel route. This includes successful completion and completion due exceptions
 
 With this patches in place I don't saw any .m64 files as left over

Added:
    james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/SMTPConstants.java
Modified:
    james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/mina/AbstractAsyncServer.java
    james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/mina/AsyncRemoteManager.java
    james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java
    james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/JamesDataCmdHandler.java
    james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/mina/AsyncSMTPServer.java
    james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/mina/SMTPIoHandler.java
    james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/mina/SMTPSessionImpl.java
    james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/AbstractProcessorRouteBuilder.java
    james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/AbstractRemoteDelivery.java

Modified: james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/mina/AbstractAsyncServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/mina/AbstractAsyncServer.java?rev=930014&r1=930013&r2=930014&view=diff
==============================================================================
--- james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/mina/AbstractAsyncServer.java (original)
+++ james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/mina/AbstractAsyncServer.java Thu Apr  1 15:47:15 2010
@@ -23,6 +23,7 @@ import java.net.InetSocketAddress;
 import java.net.UnknownHostException;
 
 import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
 import javax.annotation.Resource;
 
 import org.apache.commons.configuration.Configuration;
@@ -114,7 +115,8 @@ public abstract class AbstractAsyncServe
 
     private SslContextFactory contextFactory;
 
-    
+    private SocketAcceptor acceptor;  
+
     @Resource(name="dnsserver")
     public final void setDNSService(DNSService dns) {
         this.dns = dns;
@@ -279,7 +281,7 @@ public abstract class AbstractAsyncServe
                 builder.addFirst( "sslFilter", new SslFilter(contextFactory.newInstance()));
             }
             
-            SocketAcceptor acceptor = new NioSocketAcceptor();  
+            acceptor = new NioSocketAcceptor();  
             acceptor.setFilterChainBuilder(builder);
             acceptor.setBacklog(backlog);
             acceptor.setReuseAddress(true);
@@ -289,6 +291,14 @@ public abstract class AbstractAsyncServe
         }
     }
 
+    @PreDestroy
+    public final void destroy() {
+        getLogger().info("Dispose " + getServiceType());
+        
+        acceptor.dispose();
+    }
+    
+    
     /**
      * This method is called on init of the Server. Subclasses should override this method to init stuff
      *

Modified: james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/mina/AsyncRemoteManager.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/mina/AsyncRemoteManager.java?rev=930014&r1=930013&r2=930014&view=diff
==============================================================================
--- james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/mina/AsyncRemoteManager.java (original)
+++ james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/mina/AsyncRemoteManager.java Thu Apr  1 15:47:15 2010
@@ -1,134 +1,134 @@
-/****************************************************************
- * 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.remotemanager.mina;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.james.protocols.api.ProtocolHandlerChain;
-import org.apache.james.remotemanager.RemoteManagerHandlerConfigurationData;
-import org.apache.james.remotemanager.RemoteManagerMBean;
-import org.apache.james.remotemanager.RemoteManagerResponse;
-import org.apache.james.remotemanager.mina.filter.RemoteManagerResponseFilter;
-import org.apache.james.socket.mina.AbstractAsyncServer;
-import org.apache.james.socket.mina.filter.ResponseValidationFilter;
-import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
-import org.apache.mina.core.service.IoHandler;
-
-public class AsyncRemoteManager extends AbstractAsyncServer implements RemoteManagerMBean{
-
-    private Map<String,String> adminAccounts = new HashMap<String, String>();
-    private ProtocolHandlerChain handlerChain;
-    private RemoteManagerHandlerConfigurationData configData = new RemoteManagerHandlerConfigurationDataImpl();
-    
-    public void setProtocolHandlerChain(ProtocolHandlerChain handlerChain) {
-        this.handlerChain = handlerChain;
-    }
-    
-    @Override
-    protected IoHandler createIoHandler() {
-        return new RemoteManagerIoHandler(configData, handlerChain, getLogger());
-    }
-
-    @Override
-    protected int getDefaultPort() {
-        return 4555;
-    }
-
-    @Override
-    protected String getServiceType() {
-        return "plain";
-    }
-
-    @SuppressWarnings("unchecked")
-    @Override
-    protected void doConfigure(HierarchicalConfiguration config) throws ConfigurationException {
-        super.doConfigure(config);
-        HierarchicalConfiguration handlerConfiguration = config.configurationAt("handler");
-        List<HierarchicalConfiguration> accounts = handlerConfiguration.configurationsAt("administrator_accounts.account");
-        for (int i = 0; i < accounts.size(); i++) {
-            adminAccounts.put(accounts.get(i).getString("[@login]"), accounts.get(i).getString("[@password]"));
-        }
-    }
-
-    protected DefaultIoFilterChainBuilder createIoFilterChainBuilder() {
-        DefaultIoFilterChainBuilder builder = super.createIoFilterChainBuilder();
-        
-        // response and validation filter to the chain
-        builder.addLast(RemoteManagerResponseFilter.NAME, new RemoteManagerResponseFilter());
-        builder.addLast("requestValidationFilter", new ResponseValidationFilter<RemoteManagerResponse>(getLogger(),RemoteManagerResponse.class));
-        return builder;
-    }
-    
-  
-    
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.remotemanager.RemoteManagerMBean#getNetworkInterface()
-     */
-    public String getNetworkInterface() {
-        return "unknown";
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.remotemanager.RemoteManagerMBean#getSocketType()
-     */
-    public String getSocketType() {
-        return "plain";
-    }
-    
-    /**
-     * A class to provide RemoteManager handler configuration to the handlers
-     */
-    private class RemoteManagerHandlerConfigurationDataImpl
-        implements RemoteManagerHandlerConfigurationData {
-
-        /**
-         * @see org.apache.james.remotemanager.RemoteManagerHandlerConfigurationData#getHelloName()
-         */
-        public String getHelloName() {
-            if (getHelloName() == null) {
-                return AsyncRemoteManager.this.getMailServer().getHelloName();
-            } else {
-                return AsyncRemoteManager.this.getHelloName();
-            }
-        }
-        
-        /**
-         * @see org.apache.james.remotemanager.RemoteManagerHandlerConfigurationData#getAdministrativeAccountData()
-         */
-        public Map<String,String> getAdministrativeAccountData() {
-            return AsyncRemoteManager.this.adminAccounts;
-        }
-
-        /**
-         * @see org.apache.james.remotemanager.RemoteManagerHandlerConfigurationData#getPrompt()
-         */
-        public String getPrompt() {
-            return "";
-        }
-        
-    }
-
-}
+/****************************************************************
+ * 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.remotemanager.mina;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.james.protocols.api.ProtocolHandlerChain;
+import org.apache.james.remotemanager.RemoteManagerHandlerConfigurationData;
+import org.apache.james.remotemanager.RemoteManagerMBean;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.mina.filter.RemoteManagerResponseFilter;
+import org.apache.james.socket.mina.AbstractAsyncServer;
+import org.apache.james.socket.mina.filter.ResponseValidationFilter;
+import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
+import org.apache.mina.core.service.IoHandler;
+
+public class AsyncRemoteManager extends AbstractAsyncServer implements RemoteManagerMBean{
+
+    private Map<String,String> adminAccounts = new HashMap<String, String>();
+    private ProtocolHandlerChain handlerChain;
+    private RemoteManagerHandlerConfigurationData configData = new RemoteManagerHandlerConfigurationDataImpl();
+    
+    public void setProtocolHandlerChain(ProtocolHandlerChain handlerChain) {
+        this.handlerChain = handlerChain;
+    }
+    
+    @Override
+    protected IoHandler createIoHandler() {
+        return new RemoteManagerIoHandler(configData, handlerChain, getLogger());
+    }
+
+    @Override
+    protected int getDefaultPort() {
+        return 4555;
+    }
+
+    @Override
+    protected String getServiceType() {
+        return "RemoteManager Service";
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    protected void doConfigure(HierarchicalConfiguration config) throws ConfigurationException {
+        super.doConfigure(config);
+        HierarchicalConfiguration handlerConfiguration = config.configurationAt("handler");
+        List<HierarchicalConfiguration> accounts = handlerConfiguration.configurationsAt("administrator_accounts.account");
+        for (int i = 0; i < accounts.size(); i++) {
+            adminAccounts.put(accounts.get(i).getString("[@login]"), accounts.get(i).getString("[@password]"));
+        }
+    }
+
+    protected DefaultIoFilterChainBuilder createIoFilterChainBuilder() {
+        DefaultIoFilterChainBuilder builder = super.createIoFilterChainBuilder();
+        
+        // response and validation filter to the chain
+        builder.addLast(RemoteManagerResponseFilter.NAME, new RemoteManagerResponseFilter());
+        builder.addLast("requestValidationFilter", new ResponseValidationFilter<RemoteManagerResponse>(getLogger(),RemoteManagerResponse.class));
+        return builder;
+    }
+    
+  
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#getNetworkInterface()
+     */
+    public String getNetworkInterface() {
+        return "unknown";
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#getSocketType()
+     */
+    public String getSocketType() {
+        return "plain";
+    }
+    
+    /**
+     * A class to provide RemoteManager handler configuration to the handlers
+     */
+    private class RemoteManagerHandlerConfigurationDataImpl
+        implements RemoteManagerHandlerConfigurationData {
+
+        /**
+         * @see org.apache.james.remotemanager.RemoteManagerHandlerConfigurationData#getHelloName()
+         */
+        public String getHelloName() {
+            if (getHelloName() == null) {
+                return AsyncRemoteManager.this.getMailServer().getHelloName();
+            } else {
+                return AsyncRemoteManager.this.getHelloName();
+            }
+        }
+        
+        /**
+         * @see org.apache.james.remotemanager.RemoteManagerHandlerConfigurationData#getAdministrativeAccountData()
+         */
+        public Map<String,String> getAdministrativeAccountData() {
+            return AsyncRemoteManager.this.adminAccounts;
+        }
+
+        /**
+         * @see org.apache.james.remotemanager.RemoteManagerHandlerConfigurationData#getPrompt()
+         */
+        public String getPrompt() {
+            return "";
+        }
+        
+    }
+
+}

Modified: james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java?rev=930014&r1=930013&r2=930014&view=diff
==============================================================================
--- james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java (original)
+++ james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java Thu Apr  1 15:47:15 2010
@@ -99,8 +99,8 @@ public final class DataLineJamesMessageH
      * @see org.apache.james.smtpserver.protocol.core.DataLineFilter#onLine(org.apache.james.smtpserver.protocol.SMTPSession, byte[], org.apache.james.api.protocol.LineHandler)
      */
     public void onLine(SMTPSession session, byte[] line, LineHandler<SMTPSession> next) {
-        MimeMessageInputStreamSource mmiss = (MimeMessageInputStreamSource) session.getState().get(JamesDataCmdHandler.DATA_MIMEMESSAGE_STREAMSOURCE);
-        OutputStream out = (OutputStream)  session.getState().get(JamesDataCmdHandler.DATA_MIMEMESSAGE_OUTPUTSTREAM);
+        MimeMessageInputStreamSource mmiss = (MimeMessageInputStreamSource) session.getState().get(SMTPConstants.DATA_MIMEMESSAGE_STREAMSOURCE);
+        OutputStream out = (OutputStream)  session.getState().get(SMTPConstants.DATA_MIMEMESSAGE_OUTPUTSTREAM);
 
         try {
             // 46 is "."
@@ -114,6 +114,10 @@ public final class DataLineJamesMessageH
                     new MailImpl(mailServer.getId(),
                                  (MailAddress) session.getState().get(SMTPSession.SENDER),
                                  recipientCollection);
+                
+                // store mail in the session so we can be sure it get disposed later
+                session.getState().put(SMTPConstants.MAIL, mail);
+                
                 MimeMessageCopyOnWriteProxy mimeMessageCopyOnWriteProxy = null;
                 try {
                     mimeMessageCopyOnWriteProxy = new MimeMessageCopyOnWriteProxy(mmiss);

Modified: james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/JamesDataCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/JamesDataCmdHandler.java?rev=930014&r1=930013&r2=930014&view=diff
==============================================================================
--- james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/JamesDataCmdHandler.java (original)
+++ james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/JamesDataCmdHandler.java Thu Apr  1 15:47:15 2010
@@ -38,9 +38,6 @@ import org.apache.james.services.MailSer
 public class JamesDataCmdHandler extends DataCmdHandler {
 
     
-    static final String DATA_MIMEMESSAGE_STREAMSOURCE = "org.apache.james.core.DataCmdHandler.DATA_MIMEMESSAGE_STREAMSOURCE";
-
-    static final String DATA_MIMEMESSAGE_OUTPUTSTREAM = "org.apache.james.core.DataCmdHandler.DATA_MIMEMESSAGE_OUTPUTSTREAM";
 
     private MailServer mailServer;
     
@@ -74,8 +71,8 @@ public class JamesDataCmdHandler extends
             MimeMessageInputStreamSource mmiss = new MimeMessageInputStreamSource(mailServer.getId());
             OutputStream out = mmiss.getWritableOutputStream();
 
-            session.getState().put(DATA_MIMEMESSAGE_STREAMSOURCE, mmiss);
-            session.getState().put(DATA_MIMEMESSAGE_OUTPUTSTREAM, out);
+            session.getState().put(SMTPConstants.DATA_MIMEMESSAGE_STREAMSOURCE, mmiss);
+            session.getState().put(SMTPConstants.DATA_MIMEMESSAGE_OUTPUTSTREAM, out);
 
         } catch (IOException e) {
             session.getLogger().warn("Error creating temporary outputstream for incoming data",e);

Added: james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/SMTPConstants.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/SMTPConstants.java?rev=930014&view=auto
==============================================================================
--- james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/SMTPConstants.java (added)
+++ james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/SMTPConstants.java Thu Apr  1 15:47:15 2010
@@ -0,0 +1,35 @@
+/****************************************************************
+ * 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.smtpserver;
+
+/**
+ * Constants which are used within SMTP Session
+ * 
+ *
+ */
+public interface SMTPConstants {
+
+    public static final String DATA_MIMEMESSAGE_STREAMSOURCE = "org.apache.james.core.DataCmdHandler.DATA_MIMEMESSAGE_STREAMSOURCE";
+
+    public static final String DATA_MIMEMESSAGE_OUTPUTSTREAM = "org.apache.james.core.DataCmdHandler.DATA_MIMEMESSAGE_OUTPUTSTREAM";
+    
+    public static final String MAIL = "MAIL";
+
+}

Modified: james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/mina/AsyncSMTPServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/mina/AsyncSMTPServer.java?rev=930014&r1=930013&r2=930014&view=diff
==============================================================================
--- james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/mina/AsyncSMTPServer.java (original)
+++ james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/mina/AsyncSMTPServer.java Thu Apr  1 15:47:15 2010
@@ -23,6 +23,7 @@ package org.apache.james.smtpserver.mina
 
 
 
+
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.james.api.dnsservice.util.NetMatcher;
@@ -308,7 +309,6 @@ public class AsyncSMTPServer extends Abs
     }
 
 
-
     /**
      * @see org.apache.james.socket.mina.AbstractAsyncServer#createIoHandler()
      */

Modified: james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/mina/SMTPIoHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/mina/SMTPIoHandler.java?rev=930014&r1=930013&r2=930014&view=diff
==============================================================================
--- james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/mina/SMTPIoHandler.java (original)
+++ james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/mina/SMTPIoHandler.java Thu Apr  1 15:47:15 2010
@@ -1,98 +1,115 @@
-/****************************************************************
- * 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.smtpserver.mina;
-
-import org.apache.commons.logging.Log;
-
-import org.apache.james.protocols.api.ProtocolHandlerChain;
-import org.apache.james.protocols.api.ProtocolSession;
-import org.apache.james.protocols.smtp.SMTPConfiguration;
-import org.apache.james.protocols.smtp.SMTPResponse;
-import org.apache.james.protocols.smtp.SMTPRetCode;
-import org.apache.james.protocols.smtp.SMTPSession;
-import org.apache.james.socket.mina.AbstractIoHandler;
-import org.apache.james.socket.mina.codec.LineLengthExceededException;
-import org.apache.mina.core.session.IoSession;
-import org.apache.mina.filter.codec.ProtocolDecoderException;
-import org.apache.mina.filter.ssl.SslContextFactory;
-
-/**
- * This IoHandler handling the calling of ConnectHandler and LineHandlers
- * 
- *
- */
-public class SMTPIoHandler extends AbstractIoHandler{    
-    private Log logger;
-    private SMTPConfiguration conf;
-    private SslContextFactory contextFactory;
-
-    public SMTPIoHandler(ProtocolHandlerChain chain,
-            SMTPConfiguration conf, Log logger) {
-        this(chain,conf,logger,null);
-    }
-    
-    public SMTPIoHandler(ProtocolHandlerChain chain,
-            SMTPConfiguration conf, Log logger, SslContextFactory contextFactory) {
-        super(chain);
-        this.conf = conf;
-        this.logger = logger;
-        this.contextFactory = contextFactory;
-    }
-
-    /**
-     * @see org.apache.mina.core.service.IoHandler#exceptionCaught(org.apache.mina.core.session.IoSession,
-     *      java.lang.Throwable)
-     */
-    public void exceptionCaught(IoSession session, Throwable exception)
-            throws Exception {
-        logger.debug("Caught exception: " + session.getCurrentWriteMessage(),
-                exception);
-        if (exception instanceof ProtocolDecoderException) {
-            ProtocolDecoderException e = (ProtocolDecoderException) exception;
-            if (e.getCause() instanceof LineLengthExceededException) {
-                session.write(new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_COMMAND_UNRECOGNIZED, "Line length exceeded. See RFC 2821 #4.5.3.1."));
-                return;
-            }
-        }
-
-            
-        if (session.isConnected()) {
-            session.write(new SMTPResponse(SMTPRetCode.LOCAL_ERROR, "Unable to process smtp request"));
-        }
-        
-        
-    }
-
-    @Override
-    protected ProtocolSession createSession(IoSession session) throws Exception{
-        SMTPSession smtpSession;
-        if (contextFactory == null) {
-            smtpSession= new SMTPSessionImpl(conf, logger, session);
-        } else {
-            smtpSession= new SMTPSessionImpl(conf, logger, session, contextFactory.newInstance());
-        }        
-        return smtpSession;
-    }
-
-    @Override
-    protected String getSessionKey() {
-        return SMTPSessionImpl.SMTP_SESSION;
-    }
-}
+/****************************************************************
+ * 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.smtpserver.mina;
+
+import org.apache.commons.logging.Log;
+
+import org.apache.james.lifecycle.LifecycleUtil;
+import org.apache.james.protocols.api.ProtocolHandlerChain;
+import org.apache.james.protocols.api.ProtocolSession;
+import org.apache.james.protocols.smtp.SMTPConfiguration;
+import org.apache.james.protocols.smtp.SMTPResponse;
+import org.apache.james.protocols.smtp.SMTPRetCode;
+import org.apache.james.protocols.smtp.SMTPSession;
+import org.apache.james.smtpserver.SMTPConstants;
+import org.apache.james.socket.mina.AbstractIoHandler;
+import org.apache.james.socket.mina.codec.LineLengthExceededException;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderException;
+import org.apache.mina.filter.ssl.SslContextFactory;
+
+/**
+ * This IoHandler handling the calling of ConnectHandler and LineHandlers
+ * 
+ *
+ */
+public class SMTPIoHandler extends AbstractIoHandler{    
+    private Log logger;
+    private SMTPConfiguration conf;
+    private SslContextFactory contextFactory;
+
+    public SMTPIoHandler(ProtocolHandlerChain chain,
+            SMTPConfiguration conf, Log logger) {
+        this(chain,conf,logger,null);
+    }
+    
+    @Override
+    public void sessionClosed(IoSession session) throws Exception {
+        
+        logger.debug("Dispose objects while closing session " + session.getId());
+        // Make sure we dispose everything on exit on session close
+        SMTPSession smtpSession = (SMTPSession) session.getAttribute(getSessionKey());
+        
+        LifecycleUtil.dispose(smtpSession.getState().get(SMTPConstants.MAIL));
+        LifecycleUtil.dispose(smtpSession.getState().get(SMTPConstants.DATA_MIMEMESSAGE_STREAMSOURCE));
+        LifecycleUtil.dispose(smtpSession.getState().get(SMTPConstants.DATA_MIMEMESSAGE_OUTPUTSTREAM));
+        
+        
+        super.sessionClosed(session);
+    }
+
+    public SMTPIoHandler(ProtocolHandlerChain chain,
+            SMTPConfiguration conf, Log logger, SslContextFactory contextFactory) {
+        super(chain);
+        this.conf = conf;
+        this.logger = logger;
+        this.contextFactory = contextFactory;
+    }
+
+    /**
+     * @see org.apache.mina.core.service.IoHandler#exceptionCaught(org.apache.mina.core.session.IoSession,
+     *      java.lang.Throwable)
+     */
+    public void exceptionCaught(IoSession session, Throwable exception)
+            throws Exception {
+        logger.debug("Caught exception: " + session.getCurrentWriteMessage(),
+                exception);
+        if (exception instanceof ProtocolDecoderException) {
+            ProtocolDecoderException e = (ProtocolDecoderException) exception;
+            if (e.getCause() instanceof LineLengthExceededException) {
+                session.write(new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_COMMAND_UNRECOGNIZED, "Line length exceeded. See RFC 2821 #4.5.3.1."));
+                return;
+            }
+        }
+
+            
+        if (session.isConnected()) {
+            session.write(new SMTPResponse(SMTPRetCode.LOCAL_ERROR, "Unable to process smtp request"));
+        }
+        
+        
+    }
+
+    @Override
+    protected ProtocolSession createSession(IoSession session) throws Exception{
+        SMTPSession smtpSession;
+        if (contextFactory == null) {
+            smtpSession= new SMTPSessionImpl(conf, logger, session);
+        } else {
+            smtpSession= new SMTPSessionImpl(conf, logger, session, contextFactory.newInstance());
+        }        
+        return smtpSession;
+    }
+
+    @Override
+    protected String getSessionKey() {
+        return SMTPSessionImpl.SMTP_SESSION;
+    }
+}

Modified: james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/mina/SMTPSessionImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/mina/SMTPSessionImpl.java?rev=930014&r1=930013&r2=930014&view=diff
==============================================================================
--- james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/mina/SMTPSessionImpl.java (original)
+++ james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/mina/SMTPSessionImpl.java Thu Apr  1 15:47:15 2010
@@ -38,7 +38,9 @@ import org.apache.mina.core.session.IoSe
 
 public class SMTPSessionImpl extends AbstractMINASession implements SMTPSession {
 
+      
         public final static String SMTP_SESSION = "SMTP_SESSION";
+        
         private static Random random = new Random();
 
         private boolean relayingAllowed;

Modified: james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/AbstractProcessorRouteBuilder.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/AbstractProcessorRouteBuilder.java?rev=930014&r1=930013&r2=930014&view=diff
==============================================================================
--- james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/AbstractProcessorRouteBuilder.java (original)
+++ james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/AbstractProcessorRouteBuilder.java Thu Apr  1 15:47:15 2010
@@ -53,7 +53,6 @@ import org.apache.mailet.base.MatcherInv
 /**
  * Build up the Camel Route by parsing the spoolmanager.xml configuration file. 
  * 
- * TODO:  - Limit Threads
  */
 public abstract class AbstractProcessorRouteBuilder extends RouteBuilder implements SpoolManager, Configurable, LogEnabled {
 
@@ -108,6 +107,12 @@ public abstract class AbstractProcessorR
                 // use transaction
                 .transacted()
                 
+                // dispose the mail object if an exception was thrown while processing this route
+                .onException(Exception.class).process(disposeProcessor).end()
+                
+                // dispose the mail object if route processing was complete
+                .onCompletion().process(disposeProcessor).end()
+                
                 // check that body is not null, just to be sure...
                 .choice().when(body().isNotNull());
             
@@ -214,7 +219,7 @@ public abstract class AbstractProcessorR
                             .choice()
                
                             // if the mailstate is GHOST whe should just dispose and stop here.
-                            .when(new MailStateEquals(Mail.GHOST)).process(disposeProcessor).stop()
+                            .when(new MailStateEquals(Mail.GHOST)).stop()
                              
                             // check if the state of the mail is the same as the
                             // current processor. If not just route it to the right endpoint via recipientList and stop processing.

Modified: james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/AbstractRemoteDelivery.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/AbstractRemoteDelivery.java?rev=930014&r1=930013&r2=930014&view=diff
==============================================================================
--- james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/AbstractRemoteDelivery.java (original)
+++ james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/AbstractRemoteDelivery.java Thu Apr  1 15:47:15 2010
@@ -60,6 +60,7 @@ import org.apache.camel.builder.RouteBui
 import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.api.dnsservice.TemporaryResolutionException;
 import org.apache.james.services.MailServer;
+import org.apache.james.transport.camel.DisposeProcessor;
 import org.apache.james.transport.camel.InMemoryMail;
 import org.apache.james.transport.camel.JamesCamelConstants;
 import org.apache.james.util.TimeConverter;
@@ -1707,12 +1708,20 @@ public abstract class AbstractRemoteDeli
 	 * 
 	 */
 	private final class RemoteDeliveryRouteBuilder extends RouteBuilder {
+        private Processor disposeProcessor = new DisposeProcessor();
 
 		@Override
 		public void configure() throws Exception {
 			from(getOutgoingQueueEndpoint(outgoingQueue))
 			.inOnly()
 			.transacted()
+            
+            // dispose the mail object if an exception was thrown while processing this route
+            .onException(Exception.class).process(disposeProcessor).end()
+                
+            // dispose the mail object if route processing was complete
+            .onCompletion().process(disposeProcessor).end()
+            
 			.process(new DeliveryProcessor())
 			.choice()
 			.when(header(JamesCamelConstants.JAMES_RETRY_DELIVERY).isNotNull()).to(getOutgoingRetryQueueEndpoint(outgoingRetryQueue)).otherwise().stop().end();
@@ -1720,6 +1729,13 @@ public abstract class AbstractRemoteDeli
 			fromF("pollingjms:queue?delay=30000&consumer.endpointUri=%s", getOutgoingRetryQueueEndpoint(outgoingRetryQueue))
 			.inOnly()
 			.transacted()
+            
+            // dispose the mail object if an exception was thrown while processing this route
+            .onException(Exception.class).process(disposeProcessor).end()
+                
+            // dispose the mail object if route processing was complete
+            .onCompletion().process(disposeProcessor).end()
+            
 			.process(new DeliveryProcessor())
 			.choice()
 			.when(header(JamesCamelConstants.JAMES_RETRY_DELIVERY).isNotNull()).toF(getOutgoingRetryQueueEndpoint(outgoingRetryQueue)).otherwise().stop().end();



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org