[
https://issues.apache.org/jira/browse/FELIX-5336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16653279#comment-16653279
]
Pierre De Rop commented on FELIX-5336:
--------------------------------------
While trying to release the R12 candidate release, another issue regarding
service scopes has been noticed:
By default, when you define a scoped service using the DM API, then a prototype
instance is always created in case you implement a component.init method in
order to add extra required dependencies. So, the prototype instance is there
only to invoke the component.init method, but is never started or stopped. It
is only there to register the PrototypeServiceFactory once all required
dependencies (including required extra dependencies defined in the
component.init method) are injected in the prototype instance. And when someone
request a service instance (using the PrototypeServiceFactory.get mehod for
example), then at this point a new component instance is created, all
dependencies are cloned to it, and the new component instance is then started
and returned to the user. Finally, the component clone is stopped when the
PrototypeServiceFactory.unget() method is called.
Now, if you don't need the component.init() method and if you don't want to let
DM create a prototype instance, then you can set the init callback to null,
explicitely:
{code:java}
Component.setCallbacks(null, "start", "stop", null){code}
This ensures that no prototype instance is created.
When you use DM Annotations, this is what is done by default, except if you
annotate your init method with @Init.
Now, when you define a prototype component using the DM API, it is easy to
forget to set the "init" callback to null when you actually don't have an init
callback in the component, and in this case, the consequence is that the
component prototype instance is created uselessly.
DM API should auto detect if the init method is defined, and if yes, then the
prototype instance should be created. Else, the prototype instance should not
be created.
This will avoid people to wonder why the prototype instance is created.
> Add support for prototype scope services in DM4
> -----------------------------------------------
>
> Key: FELIX-5336
> URL: https://issues.apache.org/jira/browse/FELIX-5336
> Project: Felix
> Issue Type: New Feature
> Components: Dependency Manager, Dependency Manager Annotations,
> Dependency Manager Lambda, Dependency Manager Runtime
> Reporter: Pierre De Rop
> Assignee: Pierre De Rop
> Priority: Major
> Fix For: org.apache.felix.dependencymanager-r12
>
> Attachments: FELIX-5336.tgz
>
>
> In the users mailing list, there is a wish to add support in DM4 for OSGi
> prototype scope services, which allows any service consumer to get its own
> instance of a given service dependency.
> See http://www.mail-archive.com/[email protected]/msg17473.html
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)