Nicholas,

As one of the culprits on the Specifications, let me try to give a view - comments inline.

Yours,  Mike.

Nicholas Williams wrote:
Hi all,

I would like clarification on what I perceive to be an ambiguity in the SCA 
Common Annotations and API specification regarding when conversations are 
started.

Lines [475 - 478] reads:
475 Conversations start on the client side when one of the following occur: 476 * A @Reference to a conversational service is injected 477 * A call is made to CompositeContext.getServiceReference [sidenote: should read ComponentContext] 478 and then a method of the service is called.
Which of the following behaviour would you expect if a client chooses to call 
ComponentContext.getServiceReference more than once using the same method 
arguments:
a) each returned ServiceReference will refer to separate conversations.
b) each returned ServiceReference will refer to the same conversation
My interpretation (and preference) would be a).  This would allow a client to 
start multiple conversations to the same reference, which is a common and 
useful pattern.

**Please could you confirm this is what the spec intends.**

My opinion (and expectation from the spec) is that each ServiceReference is a separate connection from a client to a provider. Its the same reference - so the same wire(s) and target(s) are involved.

Logically, for an implementation like Tuscany, I would expect a separate proxy to be supplied by the runtime to the application.


There is however one ugly element to coding a client that wishes to start 
multiple conversations to the same reference.  Consider the following client 
code:

@Scope("CONVRSATION")
@Service(Client.class)
public class ClientImpl implements Client
{

    @Context
    protected ComponentContext componentContext;

    @Reference(name = "server")
    protected Server dummyServer;

    public void op(int count)
    {
        for (int i = 0; i < count; i++)
        {
        //create a separate conversation for each iteration
        final ServiceReference<Server> serviceReference = 
componentContext.getServiceReference(Server.class, "server");
            Server server = serviceReference.getService;
            server.setId("id" + i);
        server.doStuff();
        }
    }

}

The ugly bit in the above code is that I've had to declare an @Reference 
against a dummyServer field, but I have no intention of using the injected 
service because I am programmatically using the ComponentContext instead.  My 
suggestion would be to allow the @Reference to target a type (it can currently 
only target field, method, constructor).  The code would become:

@Scope("CONVERSATION")
@Service(Client.class)
@Reference(name = "server", type=Server.class)
public class ClientImpl implements Client
{

    @Context
    protected ComponentContext componentContext;

    public void op(int count)
    {
        for (int i = 0; i < count; i++)
        {
        //create a separate conversation for each iteration
        final ServiceReference<Server> serviceReference = 
componentContext.getServiceReference(Server.class, "server");
            Server server = serviceReference.getService;
            server.setId("id" + i);
        server.doStuff();
        }
    }

}

A Type-targetted @Reference annotation would be useful in a number of scenarios:
  - the client requires zero to many conversations (as described above)
  - the client requires zero or one conversation (why inject a reference if it 
might not be used)
  - the client needs fine control of when the conversation is started (the 
developer may want lazy reference lookup and won't appreciate the service being 
injected before the @init method)


There is a distinction (in SCA terms) between getting a reference proxy for a service that is conversational and the starting of the conversation itself. The spec quote that you have earlier makes this clear - there is no conversation in progress until at least one method of the service interface has been invoked by the client. Merely having a proxy object in the client code does not constitute the starting of a conversation.

In principle, it might also be the case that some service operations do NOT start a conversation. However, the assembly spec does not provide a way for the service provider to mark the interface in a way that would make this clear to the client. The safe assumption is that the invocation of ANY service method involves starting the conversation - EXCEPT for service methods which are declared to end the conversation (SCA does provide marking for these methods).

I think that this discussion merits an issue being raised against the SCA Java C&I specifications to clarify the status of multiple reference objects obtained via getServiceReference().

The second question you raise of needing to have a way to annotate a reference WITHOUT getting a reference automatically injected is already
answered in the SCA Java Common Annotations & APIs spec:

Line 1415:

• required (optional) – whether injection of service or services is required. Defaults to true.


In other words, if you DON'T want a reference injected into a field annotated with the @reference annotation, say:

@Reference(name="fred" required=false)

What do you think?

Thank you




Information contained in this e-mail and any attachments are intended for the 
use of the addressee only, and may contain confidential information of Ubiquity 
Software Corporation. All unauthorized use, disclosure or distribution is 
strictly prohibited.  If you are not the addressee, please notify the sender 
immediately and destroy all copies of this email. Ubiquity Software Corporation 
plc, a company registered under the laws of England and Wales, Registration 
2719723, registered offices at Eastern Business Park, Building 3, Wern Fawr 
Lane, St. Mellons, Cardiff CF3 5EA, Wales, United Kingdom.


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



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

Reply via email to