On Wed, Aug 18, 2010 at 2:27 PM, Millies, Sebastian <sebastian.mill...@ids-scheer.com> wrote: > Hello there, > > > > in section 5.8.5 of „Tuscany SCA in Action” a multi-client scenario > involving callbacks > > is presented: There are two clients making requests to a CreditCardPayment > service. > > The clients expect to be called back. There is only one CreditCardPayment > instance > > (i. e. it has composite scope). > > > > The authors go on to explain that it would be a bad idea to inject the > callback > > proxies into a CreditCardPayment instance member via a @Callback annotation, > > because in a multi-client scenario the callback reference would not be > overwritten by > > Tuscany, so the callback to the second client would go to the first client. > And even > > if it were overwritten, the approach would not be threadsafe. > > > > Instead they recommend using a RequestContext object. However, it appears > that > > this object is injected into the service instance via a @Context annotation > just like > > a callback instance would be. I do not see how this improves anything, given > that the > > Tuscany runtime allows concurrent access to the service instance. How is the > correct > > result ensured when the CreditCardPayment service executes > rqContext.getCallback() ? > > > > I do hope I have made myself clear, > > Sebastian > > > > PS: Is there any way to enforce a single-threaded execution model for access > to a > > service, as e. g. with servlets, without explicit synchronization? > >
That's a good spot Sebastian. What actually happens is that the instance of the request context object itself is not important but when you call its methods it rummages around and pulls the correct information out of the thread so that the correct callback proxy is made available. I'll see if I can make the text explain that better. Re. single threaded execution. The place that you are ensured that only a single thread is executing in a component instance at any one time is when a component has STATELESS scope. The default. In this case a new component instance is created for each request. I'm not sure if that's answering your question though as you talk about "access to a service" so let me know if there is more to your question. Thanks Simon -- Apache Tuscany committer: tuscany.apache.org Co-author of a book about Tuscany and SCA: tuscanyinaction.com