1

Can someone please explain me how to configure OSGI DS to be a singleton? I use Equinox as OSGi container.

SCR component

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="Simple Dictionary">
   <implementation class="foo.bar.services.DictionaryImpl"/>
   <service>
      <provide interface="foo.bar.services.Dictionary"/>
   </service>
</scr:component>

OSGI console output

osgi> services (objectClass=foo.bar.services*)
{foo.bar.services.Dictionary}={
component.name=Simple Dictionary,
component.id=0,
service.id=51,
service.bundleid=7,
service.scope=bundle
}
"Registered by bundle:" foo.bar.services_1.0.0.qualifier [7]
"No bundles using service."

Butch
  • 13
  • 3

1 Answers1

1

It is a singleton unless you say servicefactory="true". DS will always use a SerivceFactory to register the service of the component. This allows the actual component creation and activation to be lazy. So you will never see service.scope=singleton on the registered service.

For DS 1.3, servicefactory will be replaced by scope but the above statement about DS always using a ServiceFactory is still true.

BJ Hargrave
  • 9,324
  • 1
  • 19
  • 27
  • Does latest version of apache felix support DS 1.3? As I see https://en.wikipedia.org/wiki/OSGi_Specification_Implementations#112:_Declarative_Services it does. But I can't find information how to use scopes. – Pavel_K Jul 13 '15 at 11:38