On 7/7/11 8:23 AM, Sergey Beryozkin wrote:
> 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();
> }
>
> }
>
With the current model, injecting an Invocation is illegal as it is, by
its intended definition, a per-request item. You might want to inject
a Link though, which is also thread safe with the current model.
--
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com