Hi Cristophe,
Thank you for your question, i think in the next weeks i'm going to
study new features of DS specification.
All you said is quite interesting, but i still need to get a
DeploymentService that let me to use the registered component factories
writing some code.
For example all my components created with component factories are
implementing the event handler interface, but the *event topic property* is
supplied to the component on the fly....
So basically when i use a CF to create a component instance i write
something like:
//
// This code live inside deployment service that is itself a DS
depending 0..n on ComponentFactory
//
ComponentFactory cf = (ComponentFactory)
componentContext.locateService("cf", sr);
if (subscribeOnEventAdmin){
String topicToSubscribe = getTopic(myServiceId)
topicToSubscribe =
SpagicUtils.normalizeTopic(topicToSubscribe);
properties.put(EventConstants.EVENT_TOPIC,
topicToSubscribe);
}
properties.put(Constants.MY_ID_PROPERTY, id);
ComponentInstance ci = cf.newInstance(properties);
Andrea
Il 12/03/2010 01:27, Christopher Armstrong ha scritto:
Hi Andrea
This is completely unnecessary. If you stop using ComponentFactorys in
DS, and just ordinary components, DS will manage it for you.
Using the "configuration-policy" mechanism which appears in the newer
DS 1.2 spec (OSGi 4.2), you make DS create, destroy and update your
components in line with a singleton configuration or a factory
configuration. If you set your DS component to be a non-factory
component, and then make its name the same as the service.pid of the
ConfigAdmin configuration you create, or if it is to behave like a
factory, set it to the factory.pid.
When you use ConfigAdmin to create a Configuration
(ConfigAdmin.getConfiguration() then .update()), DS will listen for
the events using EventAdmin and it will activate your component.
Delete the configuration, and it will deactivate your component, and
updating works similarly. This works for factory configurations too.
Understand that at no stage do you (or should you) register
MangaedServiceFactory or ManagedService instances using DS, as DS uses
the events sent out by ConfigAdmin.
OTOH, if you continue using the ComponentFactory mechanism, you can
get your "deployment" bundle to listen to ConfigAdmin events and
"create" a component when a new configuration is registered, dispose()
it when the configuration goes away, but you will probably have to
delete it and create a new one when a configuration is updated. You
get the advantage though that you can modify the configuration
properties before they get to the component, but there is mechanisms
in ConfigADmin to do this anyway.
Cheers
Chris
P.S. This won't work with DS implementations from the older spec (4.1)
as it has some ambiguities about component creation policy that makes
it impossible to tie them to configuration lifecycles.
On 12/03/2010, at 02:44 AM, Andrea Zoppello wrote:
Hi Neil/Phil,
Thx for this response, in my project i'm using a lot DS Component
Factories, and i've experience some
problems in integrating it with ConfigAdmin.
My requirements is to use ComponentFactories to create components
when some sort of deployment descriptor
appear in some folder.
I've basically write a simple OSGi service that keep monitored a
particular folder and then use anothre so called
"Deployment Service" to manage my components ( creating, destroying,
updating).
Phil my project is open-source so you could freely look at the way
i've managed this, feel free to ask me
if you need.
Andrea
Il 11/03/2010 13:38, Neil Bartlett ha scritto:
Phil,
ConfigAdmin and DS Component Factories do not work together. You are
required to programmatically call newInstance() yourself. However it
should be possible to build a bridge from a ComponentFactory to a
ManagedServiceFactory.
ManagedServiceFactory is not deprecated.
Regards
Neil
On Thu, Mar 11, 2010 at 12:30 PM, Philipp Kursawe
<[email protected]> wrote:
Hello,
someone out there that can explain me how the ConfigAdmin and DS
Component Factories work together?
I was under the impression that each factory configuration created
will invoke the newInstance method of the DS component factory?
Or do I have to create the instances myself programmatically?
What properties have to be set in the factory configuration to provoke
a creation of a new instance with that factory? Do I need to set the
service.factoryPid to the id of the factory?
There seem to be no tutorials out there when or how to use the DS
component factory. Only for the deprecated (?) ManagedServiceFactory.
Thanks,
Phil
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev
--------
Christopher Armstrong
[email protected]
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev