Hi,
Am 02.03.2012 um 05:38 schrieb Nirmal Fernando:
> Greetings All,
>
> I'm having a trouble with getting my scenario to work. Would be glad if
> some one can help me out!
>
> Here's my problem scenario.
>
> 1) I have a component which provides a service A.
>
> @scr.component name="a.b.c.service" immediate="true"
> @scr.service value="a.b.c.service.myserviceInterface1"
>
> 2) I have another component which provides another service B.
>
> @scr.component name="a.b.d.service" immediate="true"
> @scr.service value="a.b.d.service.myserviceInterface2"
>
> 3) And inside a method of this 2nd service (B), I'm calling an instance of
> object X.
>
> 4) Instance X, calls an operation of service A.
>
> So my question is how can I pass the Service A object to X? What are the
> scr annotations I should use and where? Please also note, that X should
> aware of changes that takes place in Service A.
The big question to me is, how component/service B is getting the instance of
Object X. If Object X is created by B, then B will have a reference to A and
may pass it to X.
If X itself is a component and registered as a service, then A will be
reference for Object/Service X and B will have a reference to Object/Service X
to call it and thus be sure, X has a reference to A (which actually here is an
implementation detail of X, which is not known to B).
Hope this helps.
Regards
Felix
>
> I tried several referencing ways [1] but failed to get the thing to work as
> I want.
>
> Thank you!
>
> [1] example way I used was adding following annotations at class level of
> object X.
>
> @scr.component name="a.b.d.service.e" immediate="false"
> @scr.reference name="a.b.c.service"
> interface="a.b.c.service.myserviceInterface1"
> cardinality="1..1" bind="setServiceA" unbind="unsetServiceA"
>
> and I had following methods and variable too.
>
> private serviceA;
>
> public synchronized void setServiceA(myserviceInterface1 a) {
> serviceA = a;
> }
>
>
> public synchronized void unsetServiceB(myserviceInterface1 a) {
> serviceA = null;
> }
>
>
> --
> Best Regards,
> Nirmal
>
> C.S.Nirmal J. Fernando
> Software Engineer,
> WSO2 Inc.
>
> Blog: http://nirmalfdo.blogspot.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]