Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » ComponentFactory unsatisfied(ComponentFactory of component with required dependency to other dynamic component is unsatisfied)
ComponentFactory unsatisfied [message #878378] Tue, 29 May 2012 07:24 Go to next message
Bert Robben is currently offline Bert Robben
Messages: 1
Registered: May 2012
Junior Member
Hi all,

I'm using declarative services and want to do the following:
- I have two components A and B
- An instance of A always has a 1..1 reference to an instance of B
- I want to have multiple instances of A and B

So I tried the following (complete source in attached file):
- define component A with a factory and a 1..1 reference to B

<scr:component xmlns:scr="..." activate="activate" factory="playground_osgi.A" name="A">
<implementation class="playground_osgi.A"/>
<property name="name" type="String" value="unknown"/>
<reference bind="onBUp" cardinality="1..1" interface="playground_osgi.B" name="B" policy="static" target="(name=to_be_set_dynamically)"/>
</scr:component>

- define component B with a factory

<scr:component xmlns:scr="..." activate="activate" factory="playground_osgi.B" name="B">
<implementation class="playground_osgi.B"/>
<property name="name" type="String" value="unknown"/>
<service>
<provide interface="playground_osgi.B"/>
</service>
</scr:component>

- inject the componentFactory of A and the componentFactory of B somewhere and dynamically create new instances. To make sure that each A is connected to his own instance of B dynamically set the target of the reference to an appropriate value. This is shown in the following code.

for (int i = 1; i < 5; i++) {
Dictionary<String, String> properties = new Hashtable<String, String>();
String nameB = "B_" + i;
properties.put("name", nameB);
componentFactoryB.newInstance(properties);
properties.put("name", "A_" + i);
properties.put("B.target", "(name=" + nameB + ")");
componentFactoryA.newInstance(properties);
}


However, when I try to do this, this fails because A is unsatisfied and as a result I can't inject the componentFactory of A. A is unsatisfied because it can't find an appropriate instance of B to refer to.

One work-around (hack?) to solve this issue is to change the cardinality of the reference from A->B to 0..1. If I do that, the componentFactory of A can be resolved and the piece of code above nicely creates 5 couples (A->B).


However, this really seems to be a dirty hack to me. In addition, I don't fully understand what I am doing wrong here. Is this not supported by the spec? Or is this a bug/feature of equinox?


Bert
Re: ComponentFactory unsatisfied [message #878487 is a reply to message #878378] Tue, 29 May 2012 12:19 Go to previous message
BJ Hargrave is currently offline BJ Hargrave
Messages: 55
Registered: July 2009
Member
To provide the component factory service for A, all the references for A must be satisfied. That is, the references for component A are considered the dependencies of the factory for A and must be present. See 112.5.5 Factory Component in the DS spec.

This is why you must have a B registered before the component factory for A becomes satisfied. I think you solution is the right one since the component factory is not itself dependent upon B and you always make sure the necessary B service is available before instantiating an A.
Previous Topic:Error with P2 ant task
Next Topic:Register IPartListener2 at start-up using DS.
Goto Forum:
  


Current Time: Thu Oct 23 20:55:10 GMT 2014

Powered by FUDForum. Page generated in 0.01608 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software