jsr339-experts@jax-rs-spec.java.net

[jsr339-experts] Re: client revisions

From: Sergey Beryozkin <sberyozkin_at_talend.com>
Date: Thu, 07 Jul 2011 13:23:13 +0100

Bill Burke wrote:
>
> On 7/7/11 8:01 AM, Sergey Beryozkin wrote:
>> Hi,
>>> On 7/7/11 5:28 AM, Sergey Beryozkin wrote:
>>>> I spent some time yesterday analyzing the current API draft on the
>>>> wiki and Bill's version,
>>>>
>>>> This is actually pretty close, definitely invocation.get() being the
>>>> last thing to call is good, but Invocation is just a wrong term, and
>>>> the current version breaks the idea of Invocation being fully
>>>> initialized for it to be used by batch processors, i.e, you can't call
>>>> Invocation.invoke() without setting the right method name and generic
>>>> processors have no idea about it.
>>>>
>>> NOt sure I'm understanding you. If you include an invoke() within
>>> Invocation, it can be used by batch processors.
>>>
>> what HTTP method will they use ? I guess a user will set that explicitly
>> on Invocation, using setMethod(method), before passing it in, but that
>> won't work in a case where Client references are injected given that
>> client.request().setMethod("GET").invoke won't be thread safe
>>
>
> You are losing me. Why wouldn't it be thread safe?
>
> final List<Invocation> invocations = ...;
>
> for (...)
> {
> Invocation inv = client.request("http://").body(...).method("PUT);
> invocations.add(inv);
> }
>
> Thread t = new Thread() {
>
> public void run()
> {
> invocations.invoke();
> }
> }
>
> The above code works out just fine. Whether or not it is thread safe is
> really a "feature" of the JAX-RS implementation.
>
>

I agree the above is thread safe but this is not:

public class MyBridge {

// points to "http://bar"
@Resource Invocation invocation;

// Thread Unsafe
public Response get() {
     return invocation.query(getCurrentQuery()).method("GET").invoke();
}

}

Sorry, that is actually not a problem of "invoke()" per se. But
having


public class MyBridge {

@Resource Client invocation;

// Thread Unsafe
public Response get() {
     return client.getRequest("http://bar" + getCurrentQuery()).invoke();
}

}

will be thread-safe

Cheers, Sergey