james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1240727 - /james/server/trunk/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
Date Sun, 05 Feb 2012 13:39:45 GMT
Author: norman
Date: Sun Feb  5 13:39:45 2012
New Revision: 1240727

URL: http://svn.apache.org/viewvc?rev=1240727&view=rev
Log:
ImapRequestFrameDecoder should handle big literals more efficient. See JAMES-1370

Modified:
    james/server/trunk/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java

Modified: james/server/trunk/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java?rev=1240727&r1=1240726&r2=1240727&view=diff
==============================================================================
--- james/server/trunk/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
(original)
+++ james/server/trunk/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
Sun Feb  5 13:39:45 2012
@@ -37,6 +37,7 @@ import org.jboss.netty.buffer.ChannelBuf
 import org.jboss.netty.buffer.ChannelBuffers;
 import org.jboss.netty.channel.Channel;
 import org.jboss.netty.channel.ChannelFutureListener;
+import org.jboss.netty.channel.ChannelHandler;
 import org.jboss.netty.channel.ChannelHandlerContext;
 import org.jboss.netty.channel.ChannelStateEvent;
 import org.jboss.netty.handler.codec.frame.FrameDecoder;
@@ -54,7 +55,6 @@ public class ImapRequestFrameDecoder ext
     private final static String WRITTEN_DATA = "WRITTEN_DATA";
     private final static String OUTPUT_STREAM = "OUTPUT_STREAM";
 
-
     public ImapRequestFrameDecoder(ImapDecoder decoder, int inMemorySizeLimit, int literalSizeLimit)
{
         this.decoder = decoder;
         this.inMemorySizeLimit = inMemorySizeLimit;
@@ -173,6 +173,11 @@ public class ImapRequestFrameDecoder ext
                 if (size == -1) {
                     reader.consumeLine();
                 }
+                
+                ChannelHandler handler = (ChannelHandler) attachment.remove(FRAMER);
+                if (handler != null) {
+                    channel.getPipeline().addFirst(FRAMER, handler);
+                }
                 attachment.clear();
                 return message;
             } catch (NettyImapRequestLineReader.NotEnoughDataException e) {
@@ -181,6 +186,11 @@ public class ImapRequestFrameDecoder ext
                 int neededData = e.getNeededSize();
                 // store the needed data size for later usage
                 attachment.put(NEEDED_DATA, neededData);
+                
+
+                ChannelHandler handler = channel.getPipeline().remove(FRAMER);
+                attachment.put(FRAMER, handler);
+                
                 buffer.resetReaderIndex();
                 return null;
             }
@@ -194,4 +204,19 @@ public class ImapRequestFrameDecoder ext
         }
     }
 
+    @SuppressWarnings("unchecked")
+    @Override
+    protected ChannelBuffer createCumulationDynamicBuffer(ChannelHandlerContext ctx) {
+        if (inMemorySizeLimit > 0) {
+            return ChannelBuffers.dynamicBuffer(inMemorySizeLimit, ctx.getChannel().getConfig().getBufferFactory());
+        } else {
+            Map<String, Object> attachment = (Map<String, Object>) ctx.getAttachment();
+            int size = (Integer) attachment.get(NEEDED_DATA);
+            if (size > 0) {
+                return ChannelBuffers.dynamicBuffer(size, ctx.getChannel().getConfig().getBufferFactory());
+            }
+            return super.createCumulationDynamicBuffer(ctx);
+        }
+    }
+
 }



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


Mime
View raw message