SCR always registers a ServiceFactory for the service since SCR must intermediate the service requests to construct the service object from your implementation class. So even though SCR registers ServiceFactory (which show as SCOPE_BUNDLE), since you have declared the component with ServiceScope.SINGLETON, only a single instance of your component class will be created by SCR and provided to all bundles using the service.
--
BJ Hargrave
Senior Technical Staff Member, IBM // office: +1 386 848 1781
OSGi Fellow and CTO of the OSGi Alliance // mobile: +1 386 848 3788
hargr...@us.ibm.com
BJ Hargrave
Senior Technical Staff Member, IBM // office: +1 386 848 1781
OSGi Fellow and CTO of the OSGi Alliance // mobile: +1 386 848 3788
hargr...@us.ibm.com
----- Original message -----
From: Michael Lipp <m...@mnl.de>
Sent by: osgi-dev-boun...@mail.osgi.org
To: osgi-dev@mail.osgi.org
Cc:
Subject: [osgi-dev] Service scope reported as bundle, not as singleton
Date: Sat, Sep 30, 2017 1:01 PM
I'm afraid this is going to turn out as a real stupid question, but ...
I have declared a class as service:
@org.osgi.service.component.annotations.Component(scope=ServiceScope.SINGLETON)
public class BundleListPortletFactory
implements PortletFactory<BundleListPortlet> {
...
}
Please ignore that the class name ends in "...Factory". The service is
used to create objects, but these objects aren't OSGi services, so it
has the role of a factory in my application, but it is not an OSGi
service factory.
The generated XML looks fine:
<?xml version="1.0" encoding="UTF-8"?>
<scr:componentxmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0"name="org.jgrapes.osgi.portlets.bundles.BundleListPortletFactory">;;
<implementation
class="org.jgrapes.osgi.portlets.bundles.BundleListPortletFactory"/>
<service scope="singleton">
<provide interface="org.jgrapes.osgi.factory.portlet.PortletFactory"/>
</service>
</scr:component>
And everything works as expected. But when I retrieve the
ServiceReference for this component from the BundleContext at runtime,
and query the SERVICE_SCOPE property, I get SCOPE_BUNDLE! I cannot
believe that this is a framework error that has been overlooked (I'm
using Apache Felix Declarative Services (org.apache.felix.scr) 2.0.2).
I've also checked that "PortletFactory" does not inherit from
"ServiceFactory" (which -- from my understanding -- would be the
prerequisite for having scope "bundle" in the first place).
Any ideas?
_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.osgi.org_mailman_listinfo_osgi-2Ddev&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=p-HkGsKTJWWSiO-pz0kKXl8ALzmlqvUGeFfgHUZX8ms&m=N3RV6wRIOBcURj0DHja9Yfxlma_PTb3-uqYLAH2cohw&s=7_27I_6EMvU9ffI5Wg0NxsXGr1azGwJPRioOKcRkJmU&e=
_______________________________________________ OSGi Developer Mail List osgi-dev@mail.osgi.org https://mail.osgi.org/mailman/listinfo/osgi-dev