You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2007/12/08 20:30:40 UTC

svn commit: r602534 - /jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java

Author: olegk
Date: Sat Dec  8 11:30:39 2007
New Revision: 602534

URL: http://svn.apache.org/viewvc?rev=602534&view=rev
Log:
Fixed bug; added an option to disable direct FileChannel transfers

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java?rev=602534&r1=602533&r2=602534&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java Sat Dec  8 11:30:39 2007
@@ -93,6 +93,13 @@
             System.err.println("Please specify document root directory");
             System.exit(1);
         }
+        boolean useFileChannels = true;
+        if (args.length >= 2) {
+            String s = args[1];
+            if (s.equalsIgnoreCase("disableFileChannels")) {
+                useFileChannels = false;
+            }
+        }
         HttpParams params = new BasicHttpParams();
         params
             .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 20000)
@@ -103,7 +110,7 @@
 
         ListeningIOReactor ioReactor = new DefaultListeningIOReactor(2, params);
 
-        NHttpServiceHandler handler = new FileServiceHandler(args[0], params);
+        NHttpServiceHandler handler = new FileServiceHandler(args[0], useFileChannels, params);
         IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params);
         
         try {
@@ -210,14 +217,19 @@
     public static class FileServiceHandler implements NHttpServiceHandler {
 
         private final String docRoot;
+        private boolean useFileChannels;
         private final HttpParams params;
         private final HttpResponseFactory responseFactory;
         private final HttpProcessor httpProcessor;
         private final ConnectionReuseStrategy connStrategy;
         
-        public FileServiceHandler(final String docRoot, final HttpParams params) {
+        public FileServiceHandler(
+                final String docRoot, 
+                boolean useFileChannels, 
+                final HttpParams params) {
             super();
             this.docRoot = docRoot;
+            this.useFileChannels = useFileChannels;
             this.params = params;
             this.responseFactory = new DefaultHttpResponseFactory();
             this.httpProcessor = createProtocolProcessor();
@@ -350,7 +362,9 @@
                 long transferred;
 
                 // Test if the decoder is capable of direct transfer to file
-                if (decoder instanceof FileContentDecoder && channel instanceof FileChannel) {
+                if (this.useFileChannels && 
+                        decoder instanceof FileContentDecoder && 
+                        channel instanceof FileChannel) {
                     long pos = connState.getInputCount();
                     transferred = ((FileContentDecoder) decoder).transfer(
                             (FileChannel) channel, pos, Integer.MAX_VALUE);
@@ -390,7 +404,9 @@
                 long transferred;
 
                 // Test if the encoder is capable of direct transfer from file
-                if (encoder instanceof FileContentDecoder && channel instanceof FileChannel) {
+                if (this.useFileChannels && 
+                        encoder instanceof FileContentEncoder && 
+                        channel instanceof FileChannel) {
                     long pos = connState.getOutputCount();
                     transferred = ((FileContentEncoder) encoder).transfer(
                             (FileChannel) channel, pos, Integer.MAX_VALUE);