[ 
https://issues.apache.org/jira/browse/HTTPCORE-148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12571198#action_12571198
 ] 

Sam Berlin commented on HTTPCORE-148:
-------------------------------------

Would it be possible to leave thread-safety requirements to implementations 
that spawn new threads?  It's very possible for implementations to only perform 
actions on the same thread.  For example, consider the case of a proxy server 
that takes the request & internally performs a non-blocking request to another 
host, sending that host's response back.  If the proxy is using the Async 
handler, it's highly likely that it fully supports non-blocking I/O and is 
doing that request on the same non-blocking I/O thread, which would cause the 
response to be triggered on the same thread too.  In our scenario, where we 
plug in our own NIO layer, the implementation we'd use would do something like:

 void handle(...) {
     assert isDispatchThread();
     new Thread() {
         public void run() {
             byte[] data = getResponseFromAnotherRequest();
             runInDispatchThread(new Runnable() {
                  public void run() {
                      response.setEntity(new NByteArrayEntity(data));
                       trigger.submitResponse(response);
                  }
             }
        }
     }.start();
}

We can even add assertions that implementations using the trigger follow the 
thread-safety by passing the current thread to the Trigger's creation, and 
asserting that Thread.currentThread() == createdThread in the submit methods.  
This would let the trigger be used in a thread-safe manner, while still 
allowing implementations to delay sending a response.

> Create AsyncNHttpServiceHandler & AsyncNHttpClientHandler
> ---------------------------------------------------------
>
>                 Key: HTTPCORE-148
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-148
>             Project: HttpComponents HttpCore
>          Issue Type: New Feature
>          Components: HttpCore NIO
>    Affects Versions: 4.0-beta1
>            Reporter: Sam Berlin
>            Assignee: Oleg Kalnichevski
>             Fix For: 4.0-beta2
>
>         Attachments: changes.txt, changes.txt, changes2.txt
>
>
> Attached is a patch for AsyncNHttpServiceHandler.  It actually works (as 
> tested by running & hitting it with IE.)  :)
> To test, run the example 'AsyncNHttpFileServer' in the examples directory or 
> the TestAsyncNHttpHandlers test.

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to