hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1444179 - in /httpcomponents/benchmark/httpcore/trunk: ./ src/main/java/org/apache/http/benchmark/ src/main/java/org/apache/http/benchmark/httpcore/ src/main/java/org/apache/http/benchmark/netty/
Date Fri, 08 Feb 2013 18:22:36 GMT
Author: olegk
Date: Fri Feb  8 18:22:36 2013
New Revision: 1444179

URL: http://svn.apache.org/r1444179
Log:
Added Netty test server (Netty version 3.6.2.FINAL); upgraded HttpCore to version 4.2.3

Added:
    httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/
    httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/HttpServerPipelineFactory.java
  (with props)
    httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/NettyNIOServer.java
  (with props)
    httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/RandomDataHandler.java
  (with props)
Modified:
    httpcomponents/benchmark/httpcore/trunk/pom.xml
    httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/Benchmark.java
    httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpCoreNIOServer.java
    httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpCoreServer.java
    httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpListener.java
    httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/NRandomDataHandler.java

Modified: httpcomponents/benchmark/httpcore/trunk/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/pom.xml?rev=1444179&r1=1444178&r2=1444179&view=diff
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/pom.xml (original)
+++ httpcomponents/benchmark/httpcore/trunk/pom.xml Fri Feb  8 18:22:36 2013
@@ -84,6 +84,12 @@
       <version>1.5.10</version>
       <scope>compile</scope>
     </dependency>
+    <dependency>
+      <groupId>io.netty</groupId>
+      <artifactId>netty</artifactId>
+      <version>3.6.2.Final</version>
+      <scope>compile</scope>
+    </dependency>
   </dependencies>
 
   <properties>

Modified: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/Benchmark.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/Benchmark.java?rev=1444179&r1=1444178&r2=1444179&view=diff
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/Benchmark.java
(original)
+++ httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/Benchmark.java
Fri Feb  8 18:22:36 2013
@@ -37,6 +37,7 @@ import org.apache.http.benchmark.httpcor
 import org.apache.http.benchmark.httpcore.HttpCoreServer;
 import org.apache.http.benchmark.jetty.JettyNIOServer;
 import org.apache.http.benchmark.jetty.JettyServer;
+import org.apache.http.benchmark.netty.NettyNIOServer;
 
 public class Benchmark {
 
@@ -68,6 +69,7 @@ public class Benchmark {
         benchmark.run(new JettyServer(PORT), config);
         benchmark.run(new HttpCoreServer(PORT), config);
         benchmark.run(new JettyNIOServer(PORT), config);
+        benchmark.run(new NettyNIOServer(PORT), config);
         benchmark.run(new HttpCoreNIOServer(PORT), config);
     }
 

Modified: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpCoreNIOServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpCoreNIOServer.java?rev=1444179&r1=1444178&r2=1444179&view=diff
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpCoreNIOServer.java
(original)
+++ httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpCoreNIOServer.java
Fri Feb  8 18:22:36 2013
@@ -38,10 +38,10 @@ import org.apache.http.nio.protocol.Http
 import org.apache.http.nio.protocol.HttpAsyncService;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.ListeningIOReactor;
+import org.apache.http.params.BasicHttpParams;
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.params.CoreProtocolPNames;
 import org.apache.http.params.HttpParams;
-import org.apache.http.params.SyncBasicHttpParams;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.ImmutableHttpProcessor;
 import org.apache.http.protocol.ResponseConnControl;
@@ -61,7 +61,7 @@ public class HttpCoreNIOServer implement
         }
         this.port = port;
 
-        final HttpParams params = new SyncBasicHttpParams();
+        final HttpParams params = new BasicHttpParams();
         params
             .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 10000)
             .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 12 * 1024)

Modified: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpCoreServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpCoreServer.java?rev=1444179&r1=1444178&r2=1444179&view=diff
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpCoreServer.java
(original)
+++ httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpCoreServer.java
Fri Feb  8 18:22:36 2013
@@ -87,8 +87,11 @@ public class HttpCoreServer implements H
                 params);
 
         this.workers = new ConcurrentLinkedQueue<HttpWorker>();
+        ServerSocket serverSocket = new ServerSocket(port);
+        serverSocket.setReuseAddress(true);
+        serverSocket.setReceiveBufferSize(8 * 1024);
         this.listener = new HttpListener(
-                new ServerSocket(port),
+                serverSocket,
                 httpservice,
                 new StdHttpWorkerCallback(this.workers));
     }

Modified: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpListener.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpListener.java?rev=1444179&r1=1444178&r2=1444179&view=diff
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpListener.java
(original)
+++ httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpListener.java
Fri Feb  8 18:22:36 2013
@@ -68,6 +68,9 @@ class HttpListener extends Thread {
             try {
                 // Set up HTTP connection
                 final Socket socket = this.serversocket.accept();
+                socket.setReceiveBufferSize(8 * 1024);
+                socket.setSendBufferSize(8 * 1024);
+
                 final DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
                 conn.bind(socket, this.httpservice.getParams());
 

Modified: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/NRandomDataHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/NRandomDataHandler.java?rev=1444179&r1=1444178&r2=1444179&view=diff
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/NRandomDataHandler.java
(original)
+++ httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/NRandomDataHandler.java
Fri Feb  8 18:22:36 2013
@@ -97,12 +97,16 @@ class NRandomDataHandler implements Http
         private final ByteBuffer buf;
         private final int count;
 
-        private int remaining;
-
         public RandomAsyncResponseProducer(final int count) {
             super();
             this.count = count;
-            this.buf = ByteBuffer.allocate(1024);
+            this.buf = ByteBuffer.allocate(count);
+            final int r = Math.abs(this.buf.hashCode());
+            for (int i = 0; i < count; i++) {
+                final byte b = (byte) ((r + i) % 96 + 32);
+                this.buf.put(b);
+            }
+            this.buf.flip();
         }
 
         public void close() throws IOException {
@@ -117,7 +121,6 @@ class NRandomDataHandler implements Http
             entity.setContentLength(this.count);
             entity.setContentType(ContentType.TEXT_PLAIN.toString());
             response.setEntity(entity);
-            this.remaining = this.count;
             return response;
         }
 
@@ -126,21 +129,15 @@ class NRandomDataHandler implements Http
 
         public void produceContent(
                 final ContentEncoder encoder, final IOControl ioctrl) throws IOException
{
-            final int r = Math.abs(this.buf.hashCode());
-            final int chunk = Math.min(this.buf.remaining(), this.remaining);
-            if (chunk > 0) {
-                for (int i = 0; i < chunk; i++) {
-                    final byte b = (byte) ((r + i) % 96 + 32);
-                    this.buf.put(b);
+            while (this.buf.hasRemaining()) {
+                final int bytesWritten = encoder.write(this.buf);
+                if (this.buf.remaining() == 0) {
+                    encoder.complete();
+                }
+                if (bytesWritten <= 0) {
+                    break;
                 }
             }
-            this.buf.flip();
-            final int bytesWritten = encoder.write(this.buf);
-            this.remaining -= bytesWritten;
-            if (this.remaining == 0 && this.buf.remaining() == 0) {
-                encoder.complete();
-            }
-            this.buf.compact();
         }
 
     }

Added: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/HttpServerPipelineFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/HttpServerPipelineFactory.java?rev=1444179&view=auto
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/HttpServerPipelineFactory.java
(added)
+++ httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/HttpServerPipelineFactory.java
Fri Feb  8 18:22:36 2013
@@ -0,0 +1,47 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.benchmark.netty;
+
+import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.Channels;
+import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
+import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
+
+public class HttpServerPipelineFactory implements ChannelPipelineFactory {
+
+    public ChannelPipeline getPipeline() throws Exception {
+        ChannelPipeline pipeline = Channels.pipeline();
+        pipeline.addLast("decoder", new HttpRequestDecoder());
+        pipeline.addLast("encoder", new HttpResponseEncoder());
+        pipeline.addLast("handler", new RandomDataHandler());
+        return pipeline;
+    }
+
+
+}

Propchange: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/HttpServerPipelineFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/HttpServerPipelineFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/HttpServerPipelineFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/NettyNIOServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/NettyNIOServer.java?rev=1444179&view=auto
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/NettyNIOServer.java
(added)
+++ httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/NettyNIOServer.java
Fri Feb  8 18:22:36 2013
@@ -0,0 +1,92 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.benchmark.netty;
+
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.http.benchmark.HttpServer;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+
+public class NettyNIOServer implements HttpServer {
+
+    private final int port;
+    private final ServerBootstrap serverBootstrap;
+
+    public NettyNIOServer(final int port) {
+        super();
+        if (port <= 0) {
+            throw new IllegalArgumentException("Server port may not be negative or null");
+        }
+        this.port = port;
+        this.serverBootstrap = new ServerBootstrap(
+            new NioServerSocketChannelFactory(
+            Executors.newCachedThreadPool(),
+            Executors.newCachedThreadPool()));
+        this.serverBootstrap.setPipelineFactory(new HttpServerPipelineFactory());
+        this.serverBootstrap.setOption("child.tcpNoDelay", Boolean.TRUE);
+    }
+
+    public String getName() {
+        return "Netty";
+    }
+
+    public String getVersion() {
+        return "3.6.2";
+    }
+
+    public void start() throws Exception {
+        serverBootstrap.bind(new InetSocketAddress(port));
+    }
+
+    public void shutdown() {
+        serverBootstrap.releaseExternalResources();
+    }
+
+    public static void main(final String[] args) throws Exception {
+        if (args.length != 1) {
+            System.out.println("Usage: <port>");
+            System.exit(1);
+        }
+        int port = Integer.parseInt(args[0]);
+        final NettyNIOServer server = new NettyNIOServer(port);
+        System.out.println("Listening on port: " + port);
+        server.start();
+
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+
+            @Override
+            public void run() {
+                server.shutdown();
+            }
+
+        });
+    }
+
+}

Propchange: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/NettyNIOServer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/NettyNIOServer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/NettyNIOServer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/RandomDataHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/RandomDataHandler.java?rev=1444179&view=auto
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/RandomDataHandler.java
(added)
+++ httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/RandomDataHandler.java
Fri Feb  8 18:22:36 2013
@@ -0,0 +1,172 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.benchmark.netty;
+
+import static org.jboss.netty.handler.codec.http.HttpHeaders.is100ContinueExpected;
+import static org.jboss.netty.handler.codec.http.HttpHeaders.isKeepAlive;
+import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONNECTION;
+import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_LENGTH;
+import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE;
+import static org.jboss.netty.handler.codec.http.HttpResponseStatus.CONTINUE;
+import static org.jboss.netty.handler.codec.http.HttpResponseStatus.OK;
+import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;
+
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.jboss.netty.channel.ChannelFuture;
+import org.jboss.netty.channel.ChannelFutureListener;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ExceptionEvent;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
+import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
+import org.jboss.netty.handler.codec.http.HttpChunk;
+import org.jboss.netty.handler.codec.http.HttpHeaders;
+import org.jboss.netty.handler.codec.http.HttpRequest;
+import org.jboss.netty.handler.codec.http.HttpResponse;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+import org.jboss.netty.util.CharsetUtil;
+
+class RandomDataHandler extends SimpleChannelUpstreamHandler {
+
+    private HttpRequest request;
+    private boolean readingChunks;
+    private int count;
+
+    public RandomDataHandler() {
+        super();
+    }
+
+    @Override
+    public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent e) throws
Exception {
+        count = 100;
+        if (!readingChunks) {
+            HttpRequest request = this.request = (HttpRequest) e.getMessage();
+            String target = request.getUri();
+
+            int idx = target.indexOf('?');
+            if (idx != -1) {
+                String s = target.substring(idx + 1);
+                if (s.startsWith("c=")) {
+                    s = s.substring(2);
+                    try {
+                        count = Integer.parseInt(s);
+                    } catch (NumberFormatException ex) {
+                        writeError(e, HttpResponseStatus.BAD_REQUEST, ex.getMessage());
+                        return;
+                    }
+                }
+            }
+
+            if (is100ContinueExpected(request)) {
+                send100Continue(e);
+            }
+
+            if (request.isChunked()) {
+                readingChunks = true;
+            } else {
+                writeResponse(e);
+            }
+        } else {
+            HttpChunk chunk = (HttpChunk) e.getMessage();
+            if (chunk.isLast()) {
+                readingChunks = false;
+                writeResponse(e);
+            }
+        }
+    }
+
+    private void writeError(final MessageEvent e, final HttpResponseStatus status, final
String message) {
+        // Decide whether to close the connection or not.
+        boolean keepAlive = isKeepAlive(request);
+
+        // Build the response object.
+        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
+        response.setContent(ChannelBuffers.copiedBuffer(message, CharsetUtil.UTF_8));
+        response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
+
+        if (keepAlive) {
+            // Add 'Content-Length' header only for a keep-alive connection.
+            response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes());
+            // Add keep alive header as per:
+            // - http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
+            response.setHeader(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
+        }
+
+        // Write the response.
+        ChannelFuture future = e.getChannel().write(response);
+
+        // Close the non-keep-alive connection after the write operation is done.
+        if (!keepAlive) {
+            future.addListener(ChannelFutureListener.CLOSE);
+        }
+    }
+
+    private void writeResponse(final MessageEvent e) {
+        // Decide whether to close the connection or not.
+        boolean keepAlive = isKeepAlive(request);
+
+        // Build the response object.
+        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
+
+        byte[] buf = new byte[count];
+        int r = Math.abs(buf.hashCode());
+        for (int i = 0; i < count; i++) {
+            buf[i] = (byte) ((r + i) % 96 + 32);
+        }
+        response.setContent(ChannelBuffers.copiedBuffer(buf));
+
+        response.setHeader(CONTENT_TYPE, "text/plain");
+        if (keepAlive) {
+            // Add 'Content-Length' header only for a keep-alive connection.
+            response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes());
+            // Add keep alive header as per:
+            // - http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
+            response.setHeader(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
+        }
+
+        // Write the response.
+        ChannelFuture future = e.getChannel().write(response);
+
+        // Close the non-keep-alive connection after the write operation is done.
+        if (!keepAlive) {
+            future.addListener(ChannelFutureListener.CLOSE);
+        }
+    }
+
+    private static void send100Continue(final MessageEvent e) {
+        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, CONTINUE);
+        e.getChannel().write(response);
+    }
+
+    @Override
+    public void exceptionCaught(final ChannelHandlerContext ctx, final ExceptionEvent e)
+            throws Exception {
+        e.getCause().printStackTrace();
+        e.getChannel().close();
+    }
+
+}

Propchange: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/RandomDataHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/RandomDataHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/netty/RandomDataHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message