[jetty-users] Jetty HttpClient & ContentExchange

classic Classic list List threaded Threaded
4 messages Options
zia
Reply | Threaded
Open this post in threaded view
|

[jetty-users] Jetty HttpClient & ContentExchange

zia
Hi All. I hope I am on the correct place to ask about Jetty HttpClient and ContentExchange.

I would like to ask you the following questions to see if my understanding is correct or not:
1) According to this API, shall I set the connector type as bellow?

a.	for asynchronous mode,
client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);

b.	for synchronous mode,
client.setConnectorType(HttpClient.CONNECTOR_SOCKET);

2) As it is said in this tutorial “Since HttpClient does not have any settings related to a particular address, it can be used to exchange requests/responses with several HTTP servers. You normally need one HttpClient instance for all your needs, even if you plan to connect to multiple HTTP servers.”

Based on the above lines, can I choose singleton pattern?

3) My application will have 60 requests per min. on average. Will the following configuration be sufficient?
client.setMaxConnectionsPerAddress(60); // max 60 concurrent connections to every address
client.setThreadPool(new QueuedThreadPool(60)); // max 60 threads
4) Do I have to create a new instance of ContentExchange for each request? I will have at most 20 URLs. As I said before there might be 60 requests per minute from among those 20 URLs.

Please help me by answering the 4 questions above. Thanks in advance.

-Zia

_______________________________________________
jetty-users mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: [jetty-users] Jetty HttpClient & ContentExchange

Simone Bordet-2
Hi,

On Tue, Mar 13, 2012 at 03:08, Mohammad Ziaul Ahsan <[hidden email]> wrote:

>
> Hi All. I hope I am on the correct place to ask about Jetty HttpClient and
> ContentExchange.
>
> I would like to ask you the following questions to see if my understanding
> is correct or not:
> 1) According to this API, shall I set the connector type as bellow?
>
> a. for asynchronous mode,
> client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
>
> b. for synchronous mode,
> client.setConnectorType(HttpClient.CONNECTOR_SOCKET);

Correct, although it's not exactly "synchronous", but "blocking"/"non-blocking".

> 2) As it is said in this tutorial “Since HttpClient does not have any
> settings related to a particular address, it can be used to exchange
> requests/responses with several HTTP servers. You normally need one
> HttpClient instance for all your needs, even if you plan to connect to
> multiple HTTP servers.”
>
> Based on the above lines, can I choose singleton pattern?

You do not have to. Just create one instance only of the HttpClient,
and pass it where needed.
Singletons are old-fashioned.

> 3) My application will have 60 requests per min. on average. Will the
> following configuration be sufficient?
>
> client.setMaxConnectionsPerAddress(60); // max 60 concurrent connections
> to every address
> client.setThreadPool(new QueuedThreadPool(60)); // max 60 threads

Difficult to say, it depends on how much time each request takes to complete.

> 4) Do I have to create a new instance of ContentExchange for each request?

Yes.

> I will have at most 20 URLs. As I said before there might be 60 requests per
> minute from among those 20 URLs.

Fine.

Simon
--
http://cometd.org
http://intalio.com
http://bordet.blogspot.com
----
Finally, no matter how good the architecture and design are,
to deliver bug-free software with optimal performance and reliability,
the implementation technique must be flawless.   Victoria Livschitz
_______________________________________________
jetty-users mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/jetty-users
zia
Reply | Threaded
Open this post in threaded view
|

Re: [jetty-users] Jetty HttpClient & ContentExchange

zia
Hi Simone, Thank you very much for answering all my questions. May I ask more?

1. I did not find any explanation of the boolean parameter 'cacheFields' ContentExchange(boolean cacheFields) here in API. Could any one explain please?

2. For blocking method, waitForDone(): "Wait until the exchange is "done". Done is defined as when a final state has been passed to the HttpExchange via the associated onXxx call. Note that an exchange can transit a final state when being used as part of a dialog (eg SecurityListener. Done status is thus defined as:  
done == onConnectionFailed || onException || onExpire || onRequestComplete && onResponseComplete"

I would like to confirm the mapping between these onXxx calls and the corresponding Exceptions they throw and the corresponding HttpExchange Fields returned by the waitForDone() method. Please correct the mapping in the following table if I am wrong and please tell me the value marked ?????.

onXxx call                          Exception Classes               HttpExchange Field
-----------------------          ---------------------               ---------------------
onConnectionFailed            ConnectException                   ?????
onException                       Exception                              STATUS_EXCEPTED
onExpire                          SocketTimeoutException          STATUS_EXPIRED
onRequestComplete &&      NOT APPLICABLE                    STATUS_COMPLETED
onResponseComplete

Thanks.

-Zia





Simone Bordet-2 wrote
Hi,

On Tue, Mar 13, 2012 at 03:08, Mohammad Ziaul Ahsan <[hidden email]> wrote:
>
> Hi All. I hope I am on the correct place to ask about Jetty HttpClient and
> ContentExchange.
>
> I would like to ask you the following questions to see if my understanding
> is correct or not:
> 1) According to this API, shall I set the connector type as bellow?
>
> a. for asynchronous mode,
> client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
>
> b. for synchronous mode,
> client.setConnectorType(HttpClient.CONNECTOR_SOCKET);

Correct, although it's not exactly "synchronous", but "blocking"/"non-blocking".

> 2) As it is said in this tutorial “Since HttpClient does not have any
> settings related to a particular address, it can be used to exchange
> requests/responses with several HTTP servers. You normally need one
> HttpClient instance for all your needs, even if you plan to connect to
> multiple HTTP servers.”
>
> Based on the above lines, can I choose singleton pattern?

You do not have to. Just create one instance only of the HttpClient,
and pass it where needed.
Singletons are old-fashioned.

> 3) My application will have 60 requests per min. on average. Will the
> following configuration be sufficient?
>
> client.setMaxConnectionsPerAddress(60); // max 60 concurrent connections
> to every address
> client.setThreadPool(new QueuedThreadPool(60)); // max 60 threads

Difficult to say, it depends on how much time each request takes to complete.

> 4) Do I have to create a new instance of ContentExchange for each request?

Yes.

> I will have at most 20 URLs. As I said before there might be 60 requests per
> minute from among those 20 URLs.

Fine.

Simon
--
http://cometd.org
http://intalio.com
http://bordet.blogspot.com
----
Finally, no matter how good the architecture and design are,
to deliver bug-free software with optimal performance and reliability,
the implementation technique must be flawless.   Victoria Livschitz
_______________________________________________
jetty-users mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: [jetty-users] Jetty HttpClient & ContentExchange

Simone Bordet-2
Hi,

On Wed, Mar 14, 2012 at 03:28, zia <[hidden email]> wrote:
> Hi Simone, Thank you very much for answering all my questions. May I ask
> more?
>
> 1. I did not find any explanation of the boolean parameter 'cacheFields'
> ContentExchange(boolean cacheFields)
> http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/client/ContentExchange.html#ContentExchange(boolean)
> here in API . Could any one explain please?

If false, the response fields are discarded, otherwise they are kept
in the exchange.

> 2. For blocking method, waitForDone(): "Wait until the exchange is "done".
> Done is defined as when a final state has been passed to the HttpExchange
> via the associated onXxx call. Note that an exchange can transit a final
> state when being used as part of a dialog (eg SecurityListener. Done status
> is thus defined as:
> done == onConnectionFailed || onException || onExpire || onRequestComplete
> && onResponseComplete"
>
> I would like to confirm the mapping between these onXxx calls and the
> corresponding Exceptions they throw and the corresponding HttpExchange
> Fields returned by the waitForDone() method. Please correct the mapping in
> the following table if I am wrong and please tell me the value marked ?????.
>
> onXxx call                          Exception Classes
> HttpExchange Field
> -----------------------          ---------------------
> ---------------------
> onConnectionFailed            ConnectException                   ?????
> onException                       Exception
> STATUS_EXCEPTED
> onExpire                                  SocketTimeoutException
> STATUS_EXPIRED
> onRequestComplete &&      NOT APPLICABLE                    STATUS_COMPLETED
> onResponseComplete

The table got garbled, but onConnectionFailed maps to
ConnectExceptions and other exceptions that may be thrown at connect
time, while onException for exceptions happening after the connection
has been established.
Method onExpire() is called when the idle timeout expires, not when a
SocketTimeoutException is thrown.

Simon
--
http://cometd.org
http://intalio.com
http://bordet.blogspot.com
----
Finally, no matter how good the architecture and design are,
to deliver bug-free software with optimal performance and reliability,
the implementation technique must be flawless.   Victoria Livschitz
_______________________________________________
jetty-users mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/jetty-users