Announcement Announcement Module

Spring Dynamic Modules forum decommissioned in favor of Eclipse Gemini Blueprint

With the official first release of Eclipse Gemini Blueprint shipped, the migration of the Spring Dynamic Modules code base to the Eclipse Foundation, as part of the Gemini project, has been completed.

As such, this forum has been decommissioned in favour of the Eclipse Gemini forums.
See more
See less
How can I expose a service which is lazy registration? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I expose a service which is lazy registration?

    Hi, everybody.
    I want to expose a service with lazy registration feature. This is my <osgi:element> element in a spring.xml file.
    <osgi:service id="simpleServiceOsgi" interface="com.test.ISayHello" >
    <bean class="com.test.Sayhello" lazy-init="true" name="name">
    But it is not work. The service implement class ctor was involked when OsgiServiceFactoryBean registers my service. As Spring-DM specification said, "If the lazy-init attribute is set to true then the service will not be created until it is referenced." Then where does the lazy-init attribute place? or Where is my error?
    I used Spring DM 1.1.0 M2 and equinox 3.3.2
    Help me.

  • #2
    The exporter needs to be lazy not the bean. The exporter will always trigger the exported bean to be initialized. There were some discussions to postpone the creation of the service until it is actually used but this leads to some subtle problems:
    - what happens if the creation fails, since the service is not initialized, there is no way to validate its state
    - what happens if the creations takes a lot of time? Suddenly a service that is published as being available, starts eating CPU on first access.

    All in all, it makes sense to postpone the export instead of postponing the service creation.

    But that just one point of view, feel free to raise an issue (w/ some arguments) if you think otherwise.


    • #3
      I want to register a lot of services at first the application startup, but not every service will be used. So I think to create these services but don't instantiate to decrease the consume of memory.
      "it makes sense to postpone the export instead of postponing the service creation." is really true, however, my application will be installed in client.Maybe it is not a good idea to use OSGi.
      In Neil's artical A Comparison of Eclipse Extensions and OSGi Services, he write that "To support lazy registration, DS has the notion of “delayed” services. When the SCR registers a delayed service, it creates a proxy object to act as a placeholder, and registers that in the service registry. "
      I just need this effect: the actual service object doesn't instantiate when the service registrates, but instantiate when the first consume bundle start. It's true that with DS when I started an bundle which provided service, the service object's ctor wasn't invoked, then after I started the first consumer bundle the service's ctor was invoked.


      • #4
        Is there no "lazy-init" tag in "osgi:service" element?


        • #5
          A feature similar to this was though for Spring-DM but due to the arguments explained before, this was not performed. Note that lazy bean have a certain effect on tracking between importers/exporters as well since the dependency cannot be fully resolved until the bean is instantiated.
          This being said, please raise an issue to request this feature - we might provided in 1.1.x+.

          And no, there is no lazy-init on osgi:service since normally you don't depend on it (as it returns a service registration) which means it doesn't get initialized and thus it doesn't register a service inside the OSGi space.


          • #6
            Thank you very much. Costin.