use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class FactoryConfigurationAdapterImplTest method createConfigurationDependency.
private FactoryConfigurationAdapterImpl createConfigurationDependency(Object service, Class<?> configType) {
BundleContext bc = mock(BundleContext.class);
DependencyManager dm = new DependencyManager(bc);
Component result = dm.createFactoryConfigurationAdapterService("does.not.matter", "updated", false, service, configType);
// Normally, when creating a factory pid adapter, you specify the class of the adapter implementation which will be instantiated
// for each created factory pid. To do so, you invoke the setImplementation(Object impl) method, and this methods
// accepts a class parameter, or an object instance. Usually, you always pass a class, because the intent of a factory pid adapter is to
// create a component instance for each created factory pid. But in our case, the "service" parameter represents our adapter instance,
// so just use it as the factory adapter implementation instance:
result.setImplementation(service);
// *Important note:* the semantic of the factory conf pid adapter is really similar to a ManagedServiceFactory:
// - when the factory pid is created, a component is created; called in updated; and called in start().
// - when the factory pid is updated, the component is called in updated().
// - but when the factory pid is removed, updated(null) is not invoked (unlike in case of ConfigurationDependency), and the component is simply
// stopped. This is actually the same semantic as ManagedServiceFactory: when factory pid is removed, ManagedServiceFactory.deleted() is called
// and the deleted() method is assumed to stop and unregister the service that was registered for the pid being removed.
dm.add(result);
return (FactoryConfigurationAdapterImpl) result;
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class ServiceFactoryAnnotationTest method testServiceFactory.
public void testServiceFactory() {
ServiceRegistration sr = register(m_ensure, ServiceFactoryAnnotation.ENSURE);
DependencyManager m = new DependencyManager(context);
// Wait for the factory.
m.add(m.createComponent().setImplementation(this).add(m.createServiceDependency().setService(Set.class, "(" + Component.FACTORY_NAME + "=" + ServiceFactoryAnnotation.FACTORY + ")").setRequired(true).setCallbacks("bindFactory", null)));
// Check if the test.annotation components have been initialized orderly
m_ensure.waitForStep(10, 5000);
m.clear();
sr.unregister();
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class AbstractBuilder method setCommonServiceParams.
/**
* Sets common Service parameters, if provided from our Component descriptor
*/
protected void setCommonServiceParams(Component c, MetaData srvMeta) throws Exception {
// Set auto configured component fields.
DependencyManager dm = c.getDependencyManager();
boolean autoConfigureComponents = "true".equals(dm.getBundleContext().getProperty(Activator.CONF_ENABLE_AUTOCONFIG));
if (!autoConfigureComponents) {
c.setAutoConfig(BundleContext.class, Boolean.FALSE);
c.setAutoConfig(ServiceRegistration.class, Boolean.FALSE);
c.setAutoConfig(DependencyManager.class, Boolean.FALSE);
c.setAutoConfig(Component.class, Boolean.FALSE);
}
// See if BundleContext must be auto configured.
String bundleContextField = srvMeta.getString(Params.bundleContextField, null);
if (bundleContextField != null) {
c.setAutoConfig(BundleContext.class, bundleContextField);
}
// See if DependencyManager must be auto configured.
String dependencyManagerField = srvMeta.getString(Params.dependencyManagerField, null);
if (dependencyManagerField != null) {
c.setAutoConfig(DependencyManager.class, dependencyManagerField);
}
// See if Component must be auto configured.
String componentField = srvMeta.getString(Params.componentField, null);
if (componentField != null) {
c.setAutoConfig(Component.class, componentField);
}
// See if Service Registration must be auto configured
String registrationField = srvMeta.getString(Params.registrationField, null);
if (registrationField != null) {
c.setAutoConfig(ServiceRegistration.class, registrationField);
}
// Now, if the component has a @Started annotation, then add our component state listener,
// which will callback the corresponding annotated method, once the component is started.
String registered = srvMeta.getString(Params.registered, null);
String unregistered = srvMeta.getString(Params.unregistered, null);
if (registered != null || unregistered != null) {
c.add(new RegistrationListener(registered, unregistered));
}
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class DependencyManagerRuntime method bundleStopped.
/**
* Unregisters all services for a stopping bundle.
* @param b
*/
protected void bundleStopped(Bundle b) {
Log.instance().info("Runtime: Removing services from stopping bundle: %s", b.getSymbolicName());
DependencyManager dm = m_managers.remove(b);
if (dm != null) {
List<Component> services = new ArrayList<Component>(dm.getComponents());
for (Component service : services) {
Log.instance().info("Runtime: Removing service: %s", service);
dm.remove(service);
}
}
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class DependencyManagerRuntime method stop.
/**
* Stops our service. We'll stop all activated DependencyManager services.
*/
protected void stop() {
Log.instance().info("Runtime: stopping services");
for (DependencyManager dm : m_managers.values()) {
List<Component> services = new ArrayList<Component>(dm.getComponents());
for (Component service : services) {
dm.remove(service);
}
}
m_managers.clear();
}
Aggregations