[ 
https://issues.apache.org/jira/browse/DIRMINA-218?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12514876
 ] 

Trustin Lee commented on DIRMINA-218:
-------------------------------------

Your patch looks very nice.  I'm impressed! :)

Before we apply this patch, what do you think about providing this feature via 
IoSession.write() method?  For example, user could call 
session.write(fileChannel).  One problem is that a user cannot provide position 
and count parameter.  We could provide a class like the following:

public class FileRegion { // please suggest a better name
    private final FileChannel ch;
    private final long pos;
    private final long count;

    ...
}

If a user calls write() with a FileChannel, BaseIoSession.write() could wrap it 
with FileRegion transparently.
Additionally, TransportType.getEnvelopeType() could return multiple classes 
rather than just one type (i.e. ByteBuffer).

Please let me know what do you think about my idea.  Once agreed, please check 
in the patch, then I will do the remaining modification I am suggesting.

and.. here comes a few comments on the patch:

* I think setPosition() sounds better than incPosition().
* No license header: SendFileRequest.java, DefaultSendFileRequest.java

> Ability to transfer channels to socket channels owned by Mina
> -------------------------------------------------------------
>
>                 Key: DIRMINA-218
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-218
>             Project: MINA
>          Issue Type: New Feature
>    Affects Versions: 2.0.0-M1
>            Reporter: dave irving
>            Assignee: Mike Heath
>            Priority: Minor
>             Fix For: 2.0.0-M1
>
>         Attachments: sendfile.patch
>
>
> Id like to be able to transfer file contents to a socket as effeciently as 
> possible.
> In some cases, making use of FileChannel#transferTo(long, long, 
> WritableByteChannel) is a good choice, as it (in theory) allows the OS to do 
> the transfer without bringing the file content in to user space (e.g. could 
> make use of sendfile behind the scenes or whatever).
> There is no direct way to obtain the channel from an IOSession - but even if 
> there was - allowing a user to do this directly is dangerous as Mina could 
> have queued writes pending for the channel.
> This JIRA issue can hopefully kick off some discussion.
> I see two basic ways to do this:
> 1) Add "sendFile(FileChannel)" or similar to IoSession. Mina then queues this 
> request along with other pending writes. Of course, mina must take care of 
> potentially several invocations to FileChannel#transferTo - as all bytes 
> might not be transfered in one go.
> 2) Allow the user to schedule their own channel commands. For example, a 
> "write command" scheduled by the user would be invoked by mina when the write 
> queue was free. 
> Im not sure that option 2 is really needed - and could be quite complex, so 
> my preference is (1).
> If we can get agreement on approach, I'll start on a patch.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to