Hi Frederik,
Fredrik Alströmer schrieb:
Hi,
got another question regarding Declarative Services. Is there anyway
for a component to provide an interface which is NOT published to the
service registry before the component is activated? Let's say I have a
component which provides, among other things, some kind of an event
handler, however, the very fact that events are generated should not
cause the component to be activated, but should only be registered in
the service registry whenever the SCR activates the component (i.e.
when one of the 'other things' is requested).
I am not sure, whether I understand you correctly. Let's see: You want
to have a component, which is delayed and only gets activated, when
"some things" of it are request.
No usually such components register services such that these "some
things" can in fact be requested. If components would not be registered
as services, they are not accessible from outside the component.
Otherwise, you could define the component as being an immediate
component. This means, that component is really activated _before_ it is
registered as a saervice. By default components providing services are
assumed as delayed components. For those delayed components the services
are registered and only when the service is requested, is the component
really activated.
I realize that this is of course possible by registering the services
upon activation (and unregistering on deactivation), I also realize
that this is probably the best solution when considering race
conditions. I am, however, currently more concerned with if it's
possible without referencing OSGi classes to any larger extent in the
code.
Yes, this is possible. Still: how is the component triggered to be
activated ?
Is this be possible? Eventing when the component is
activated/deactivated and letting another component do the work would
probably also do the trick, however, I found no reference to any
events in those situations, did I miss something?
Another functionality, where you have more control (and more exposure to
OSGi) is using a component factory: In this case the component factory
is created by the runtime and registered as a ComponentFactory service.
You may then access this ComponentFactory service and request the real
component be created and activated (and registered) on demand. This
gives you much control on the activation and registration process but
also involves OSGi code, of course.
Regards
Felix
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev