You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Simon Laws <si...@googlemail.com> on 2007/05/29 22:52:31 UTC

Wire binding selection?

While debugging through the code for other reasons I came across the
following at
org.apache.tuscany.sca.implementation.java.invocation.JavaComponentInfo line
192.

                if (ref.getMultiplicity() == Multiplicity.ONE_N ||
ref.getMultiplicity() == Multiplicity.ZERO_N) {
                    List<ObjectFactory<?>> factories = new
ArrayList<ObjectFactory<?>>();
                    for (int i = 0; i < wireList.size (); i++) {
                        ObjectFactory<?> factory = createWireFactory(
element.getType(), wireList.get(i));
                        factories.add(factory);
                    }
                    configuration.setObjectFactories(element, factories);
                } else {
                    if (wireList == null && ref.getMultiplicity() ==
Multiplicity.ONE_ONE) {
                        throw new IllegalStateException("Required reference
is missing: " + ref.getName());
                    }
                    if (wireList != null && !wireList.isEmpty()) {
>>>>>>             ObjectFactory<?> factory = createWireFactory(
element.getType (), wireList.get(0));
                        configuration.setObjectFactory(element, factory);
                    }
                }

The part of particular interest is the line marked >>>>> at the bottom. The
wire factory created here is used later when injecting the proxy into the
component reference. What I'm interested in is why it takes the first wire
only and in what circustances there will be more than one wire in the
wireList.

I note from the
org.apache.tuscany.sca.core.runtime.ComponentActivatorImplcreateRuntimeWires
method that a wire is created for each binding in each
reference. In this case I suspect that when we create the wire factory we
should be selecting the binding based on what is most appropriate rather
than which is the first one. For example.

If the reference has a "local" target (where local means a target in the
same composite)
   If there is more than one
      Find all those that match bindings on the target service
      If there is more than one
            Use the SCA binding if available
            Otherwise use the first alternative binding
Otherwise
  Use the fist binding on the list

Looking a little higher up the code it would seem that multiple wires are
also created where the cardinality of the reference is greater than one.

I may have interpreted the code here incorrectly. If so can someone explain
how multiple bindings are processed?

Thanks

Simon

Re: Wire binding selection?

Posted by Raymond Feng <en...@gmail.com>.
Hi, Simon.

Please see my comments inline.

Thanks,
Raymond

----- Original Message ----- 
From: "Simon Laws" <si...@googlemail.com>
To: <tu...@ws.apache.org>
Sent: Tuesday, May 29, 2007 11:51 PM
Subject: Re: Wire binding selection?


> Ok, Raymond, this is useful.
>
> So what it does seem to come down to is binding selection. It's not clear
> from your comment whether you believe this is already done somewhere or
> whether this is a new piece of functinality that we need to add.
>

I think we need to fix some of the code to make it fully supported.

> From what I see in the code I think we do need a way of marking which
> binding is intended to be active between any particular reference/service
> pair. When you say "Should it be done when we flatten the model?" do you
> mean when the components that each reference targets are resolved or do 
> you
> mean later on?.
>

I meant when the CompositeBuilder creates the model which reflects the 
effective configuration of the assembly.

> The issue I see at resoltuion time is that a reference holds bindings and
> targets independently. So we could change the model to allow us to create 
> a
> relationship between target and binding at this point. Alternatively we 
> can
> make the change at wire generation time where we have the wire structures 
> to
> hold this relationship. Can you think of scenarios where we don't want to 
> be
> deterministic and include this information in the model?
>

We could do it either way. But to be consistent, maybe it's better to do it 
before the wire generation.

> Regards
>
> Simon
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org


Re: Wire binding selection?

Posted by Simon Laws <si...@googlemail.com>.
Ok, Raymond, this is useful.

So what it does seem to come down to is binding selection. It's not clear
from your comment whether you believe this is already done somewhere or
whether this is a new piece of functinality that we need to add.

>From what I see in the code I think we do need a way of marking which
binding is intended to be active between any particular reference/service
pair. When you say "Should it be done when we flatten the model?" do you
mean when the components that each reference targets are resolved or do you
mean later on?.

The issue I see at resoltuion time is that a reference holds bindings and
targets independently. So we could change the model to allow us to create a
relationship between target and binding at this point. Alternatively we can
make the change at wire generation time where we have the wire structures to
hold this relationship. Can you think of scenarios where we don't want to be
deterministic and include this information in the model?

Regards

Simon

Re: Wire binding selection?

Posted by Raymond Feng <en...@gmail.com>.
Hi,

There are two issues behind:

1) For a reference with multiplicity 1..1, there should be one and only one 
target and that's why wireList.get(0) is used. To find the corresponding 
wire for a given binding, we have a better way: 
RuntimeComponentReference.getRuntimeWire(Binding binding).

2) Potentially, a reference with multiplicity 1..1 could have multiple 
bindings. When we take the binding selection into consideration, there 
should be only one resolved binding. Should it be done when we flatten the 
model?

Thanks,
Raymond

----- Original Message ----- 
From: "Simon Laws" <si...@googlemail.com>
To: "tuscany-dev" <tu...@ws.apache.org>
Sent: Tuesday, May 29, 2007 1:52 PM
Subject: Wire binding selection?


> While debugging through the code for other reasons I came across the
> following at
> org.apache.tuscany.sca.implementation.java.invocation.JavaComponentInfo 
> line
> 192.
>
>                if (ref.getMultiplicity() == Multiplicity.ONE_N ||
> ref.getMultiplicity() == Multiplicity.ZERO_N) {
>                    List<ObjectFactory<?>> factories = new
> ArrayList<ObjectFactory<?>>();
>                    for (int i = 0; i < wireList.size (); i++) {
>                        ObjectFactory<?> factory = createWireFactory(
> element.getType(), wireList.get(i));
>                        factories.add(factory);
>                    }
>                    configuration.setObjectFactories(element, factories);
>                } else {
>                    if (wireList == null && ref.getMultiplicity() ==
> Multiplicity.ONE_ONE) {
>                        throw new IllegalStateException("Required reference
> is missing: " + ref.getName());
>                    }
>                    if (wireList != null && !wireList.isEmpty()) {
>>>>>>>             ObjectFactory<?> factory = createWireFactory(
> element.getType (), wireList.get(0));
>                        configuration.setObjectFactory(element, factory);
>                    }
>                }
>
> The part of particular interest is the line marked >>>>> at the bottom. 
> The
> wire factory created here is used later when injecting the proxy into the
> component reference. What I'm interested in is why it takes the first wire
> only and in what circustances there will be more than one wire in the
> wireList.
>
> I note from the
> org.apache.tuscany.sca.core.runtime.ComponentActivatorImplcreateRuntimeWires
> method that a wire is created for each binding in each
> reference. In this case I suspect that when we create the wire factory we
> should be selecting the binding based on what is most appropriate rather
> than which is the first one. For example.
>
> If the reference has a "local" target (where local means a target in the
> same composite)
>   If there is more than one
>      Find all those that match bindings on the target service
>      If there is more than one
>            Use the SCA binding if available
>            Otherwise use the first alternative binding
> Otherwise
>  Use the fist binding on the list
>
> Looking a little higher up the code it would seem that multiple wires are
> also created where the cardinality of the reference is greater than one.
>
> I may have interpreted the code here incorrectly. If so can someone 
> explain
> how multiple bindings are processed?
>
> Thanks
>
> Simon
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org