Hi,

Let me give a try. Please see my comments inline.

Thanks,
Raymond

----- Original Message ----- From: "Nicholas Williams" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, May 15, 2007 8:36 AM
Subject: Ambiguity in SCA Common Annotations and APIs specification re. conversations


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

<rfeng>
I think it depends. There are two factors:
1) What's the current conversation if any?
2) What's the scope of the target component?

If the getServiceReference() is invoked twice in the same conversation, I assume it will get ServiceReference instances for the same conversation. If the getServiceReference() is invoked from two different conversations (or no conversations), then ServiceReference instances will refer to different conversations.
</rfeng>

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)

<rfeng>I think what you're asking for is a way to declare references using annotation without being injected automatically. Another thing is that the injection of the reference shouldn't trigger the start of the conversation.</rfeng>

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