Hello Hargrave,
serviceAimpl has the following code:
package serviceAimpl;
import serviceA.*;
import serviceB.*;
import org.osgi.service.component.*;
public class serviceAimpl implements serviceA{
serviceB b;
public void set(serviceB b)
{
System.out.println("This is the set");
this.b=b;
}
public void unset(serviceB b)
{
System.out.println("This is the unset");
this.b=null;
}
public void activate(ComponentContext cnt)
{
System.out.println("Activation of componentA");
b.printB();
}
public void deactivate(ComponentContext cnt)
{
System.out.println("Deactivation of componentA");
}
public void printA()
{
System.out.println("This is the printA function");
}
}
serviceBimpl has the following code:
package serviceBimpl;
import serviceB.*;
import serviceA.*;
import org.osgi.service.component.*;
public class serviceBimpl implements serviceB{
serviceA a;
public void printB()
{
System.out.println("This is the service b print function");
}
public void set(serviceA a)
{
System.out.println("This is the set");
this.a=a;
}
public void unset(serviceA a)
{
System.out.println("This is the unset");
this.a=null;
}
public void activate(ComponentContext cnt)
{
System.out.println("Activation of componentA");
a.printA();
}
public void deactivate(ComponentContext cnt)
{
System.out.println("Deactivation of componentA");
}
}
This is what i did in the osgi console
972 RESOLVED ComponentA_1.0.0
984 RESOLVED ComponentB_1.0.0
osgi> start 984
osgi> start 972
osgi> Activation of componentA
b.printB() is not invoked... why is it?????????????/
Thank you,
Raji
B has an optional dynamic reference to A.
A has a mandatory dynamic reference to B.
So B must be activated first without an A service.
A can then be activated with the B service.
B can then have the A service bound to it.
--
BJ Hargrave
Senior Technical Staff Member, IBM
OSGi Fellow and CTO of the OSGi Alliance
[email protected]
office: +1 386 848 1781
mobile: +1 386 848 3788
From:
rajalaxmi chandran <[email protected]>
To:
[email protected]
Date:
2009/05/14 12:32
Subject:
[osgi-dev] circular service dependencies in osgi
Sent by:
[email protected]
Hi,
please help....
i am stuck with circular dependecies in osgi. i am using declarative
services. This is my situation
*Component A registers ServiceA
*Component B registers ServiceB
*Component A needs to use ServiceB
*Component B needs to use ServiceA.
componetA.xml file has:
<?xml version="1.0" encoding="UTF-8"?>
<component name="componentA" immediate="true">
<implementation class="serviceAimpl.serviceAimpl"/>
<service>
<provide interface="serviceA.serviceA"/>
</service>
<reference name="SERVICEBUSE" interface="serviceB.serviceB" bind="set"
unbind=unset" cardinality="1..1" policy="dynamic"/>
</component>
componentB.xml file has:
<?xml version="1.0" encoding="UTF-8"?>
<component name="componentB">
<implementation class="serviceBimpl.serviceBimpl"/>
<service>
<provide interface="serviceB.serviceB"/>
</service>
<reference name="SERVICEAUSE" interface="serviceA.serviceA" bind="set"
unbind="unset" cardinality="0..1" policy="dynamic"/>
</component>
component A gets activated because of the immediate attribute being true,
but i cannot use the serviceB nor is componentB able to use serviceA....
how do i rectify this error????????????
how do we implement service contracts in OSGI????
please help
thank you
Raji
Explore and discover exciting holidays and getaways with Yahoo! India
Travel http://in.travel.yahoo.com/_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev