[
https://issues.apache.org/jira/browse/FELIX-2923?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13795759#comment-13795759
]
David Jencks commented on FELIX-2923:
-------------------------------------
I'm not sure you can make this work with a separate FactoryDescriptor service,
but I have some ideas on what to try.
1. try with DS trunk. Possibly the circular dependency resolving code will
work here.
2. register the FactoryDescriptor service in a separate thread. This may well
introduce other concurrency issues that are worse :-)
3. Create a Factory component for FactoryDescriptor services and have
DirectoryService call newInstance on it with appropriate props. This is likely
to have the same problems as (1) but possibly getting DS involved in
registering the FactoryDescriptors would help.
4. If you can encode the existence of a processed Factory in a string, you
could use the felix extension that allows you to set the service properties on
a DS component, and have a multi valued String attribute, say "factories",
containing a list of factory names. Whenever a factory is registered or
unregistered you'd update the attribute value. Then the consumer can use a
filter (factories="desiredFactoryName") on the DirectoryService reference to
only get the directory service when the desired factory has been processed.
This may end up with a different loop, but also may not. To enable this
extension, use the xmlns http://felix.apache.org/xmlns/scr/v1.2.0-felix and you
can then have a Map<String, Object> return type from lifecycle methods
(activate, bindFactory etc) that will use the return value to set the service
properties.
> Get a ServiceFactory.getService() resulted in a cycle message when
> registering a service inside a DS activation method
> -----------------------------------------------------------------------------------------------------------------------
>
> Key: FELIX-2923
> URL: https://issues.apache.org/jira/browse/FELIX-2923
> Project: Felix
> Issue Type: Bug
> Components: Declarative Services (SCR)
> Affects Versions: scr-1.6.0
> Reporter: David Humeniuk
>
> I've run into an issue with Felix SCR where I get the message:
> ServiceFactory.getService() resulted in a cycle
> The reason this appers to be occuring is because within an activation method
> of a service component, call it ServiceAImpl (which provides ServiceA), the
> component registers another service, call it ServiceB.
> I have another service component, call it ServiceCImpl, which depends on both
> ServiceA and ServiceB. When ServiceAImpl registers ServiceB, ServiceCImpl is
> attemted to be activated within the call to activate ServiceAImpl. As part
> of the activation, the ServiceCImpl binding methods are called (at least
> attempted). When the binding method for ServiceA is attempted, the cycle is
> detected and the component fails to initialize.
> I guess what doesn't make sense is why the SCR will activate ServiceCImpl
> within the activation method of ServiceAImpl. I wouldn't think that
> ServiceCImpl would be considered satisfied until after the activation method
> has exited. Perhaps this is an issue of using declarative services while
> still registering services directly with the framework?
--
This message was sent by Atlassian JIRA
(v6.1#6144)