Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 28994 invoked from network); 5 Feb 2008 16:11:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Feb 2008 16:11:31 -0000 Received: (qmail 92980 invoked by uid 500); 5 Feb 2008 16:11:11 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 92959 invoked by uid 500); 5 Feb 2008 16:11:11 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 92948 invoked by uid 99); 5 Feb 2008 16:11:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Feb 2008 08:11:11 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [72.22.94.67] (HELO virtual.halosg.com) (72.22.94.67) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Feb 2008 16:10:42 +0000 Received: (qmail 5784 invoked from network); 5 Feb 2008 10:02:23 -0600 Received: from 72-19-171-38.static.mesanetworks.net (HELO ?192.168.3.102?) (72.19.171.38) by halosg.com with SMTP; 5 Feb 2008 10:02:23 -0600 Message-ID: <47A88A95.2020509@hanik.com> Date: Tue, 05 Feb 2008 09:11:01 -0700 From: Filip Hanik - Dev Lists User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: Tomcat Users List Subject: Re: Obtain a SocketChannel instead of OutputStream ? References: <47A87F2D.1070909@unidata.ucar.edu> In-Reply-To: <47A87F2D.1070909@unidata.ucar.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org John Caron wrote: > My application is a scientific data server that transfers large > amounts of binary data. I am looking to make it as fast as possible > and have been experimenting with the NIO FileChannel.transferTo() > method. This appears to be much faster (3-10X) than using an > OutputStream, under some circumstances. So I am trying to see if I can > use this from within Tomcat. > > So the question is whether there is a way to obtain a SocketChannel > for the connection? The standard interface only allows to get an > OutputStream. While Channels.newChannel(OutputStream out) gives a > WriteableByteChannel, the transferTo() method does not work on it, > apparently one needs to get the SocketChannel at a deeper level. > > Has anyone else tried this? Any ideas would be much appreciated. we haven't exposed the API at this level, since the data you write to the network, must go through several filters. you can still take advantage of the direct transfers by using Tomcat's built in send file technique. A user previously wrote: Any servlet can instruct Tomcat to perform a sendfile call by setting the appropriate response attributes. When using sendfile... * org.apache.tomcat.sendfile.filename: Canonical filename of the file which will be sent as a String * org.apache.tomcat.sendfile.start: Start offset as a Long * org.apache.tomcat.sendfile.end: End offset as a Long So add these attributes into the request, (see DefaultServlet.java for an example), and if you are using the APR or the NIO connector in Tomcat, tomcat will transfer them directly Filip --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org