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.**

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)

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]

Reply via email to