use of org.apache.felix.dm.Component in project felix by apache.
the class AbstractDecorator method updatedSafe.
@SuppressWarnings("rawtypes")
private void updatedSafe(String pid, Dictionary properties) throws Exception {
if (!m_decoratorComponent.isActive()) {
// Our decorator component has been removed: ignore the configuration update.
return;
}
Component service = m_services.get(pid);
if (service == null) {
service = createService(new Object[] { properties });
m_services.put(pid, service);
m_manager.add(service);
} else {
updateService(new Object[] { properties, service });
}
}
use of org.apache.felix.dm.Component in project felix by apache.
the class AbstractDecorator method added.
// callbacks for bundles
public void added(Bundle bundle) throws Exception {
Component newService = createService(new Object[] { bundle });
m_services.put(bundle, newService);
m_manager.add(newService);
}
use of org.apache.felix.dm.Component in project felix by apache.
the class RemovedDependencyTest method testRemoveDependencyAndConsumerMustRemainStarted.
public void testRemoveDependencyAndConsumerMustRemainStarted() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// Create two providers
Hashtable props = new Hashtable();
props.put("name", "provider1");
Component sp = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), props);
props = new Properties();
props.put("name", "provider2");
Component sp2 = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), props);
props = new Properties();
props.put("name", "provider3");
Component sp3 = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), props);
// Create the consumer, and start it
Dependency d1 = m.createServiceDependency().setService(ServiceInterface.class, "(name=provider1)").setRequired(true).setCallbacks("add", "remove");
Dependency d2 = m.createServiceDependency().setService(ServiceInterface.class, "(name=provider2)").setRequired(true).setCallbacks("add", "remove");
Dependency d3 = m.createServiceDependency().setService(ServiceInterface.class, "(name=provider3)").setRequired(true).setCallbacks("add", "remove");
ServiceConsumer consumer = new ServiceConsumer(e, d3);
Component sc = m.createComponent().setImplementation(consumer).add(d1, d2);
// Add the first two providers and the consumer
m.add(sp);
m.add(sp2);
m.add(sp3);
m.add(sc);
// Check if consumer has been bound to the three providers
e.waitForStep(3, 5000);
Assert.assertEquals(3, consumer.getProvidersCount());
Assert.assertNotNull(consumer.getProvider("provider1"));
Assert.assertNotNull(consumer.getProvider("provider2"));
Assert.assertNotNull(consumer.getProvider("provider3"));
// Now remove the provider2, and check if the consumer is still alive
sc.remove(d2);
Assert.assertFalse(consumer.isStopped());
Assert.assertEquals(2, consumer.getProvidersCount());
Assert.assertNotNull(consumer.getProvider("provider1"));
Assert.assertNull(consumer.getProvider("provider2"));
Assert.assertNotNull(consumer.getProvider("provider3"));
// Now remove the provider3 (the consumer has an instance bound dependency on it), and check if the consumer is still alive
sc.remove(d3);
Assert.assertFalse(consumer.isStopped());
Assert.assertEquals(1, consumer.getProvidersCount());
Assert.assertNotNull(consumer.getProvider("provider1"));
Assert.assertNull(consumer.getProvider("provider2"));
Assert.assertNull(consumer.getProvider("provider3"));
m.clear();
}
use of org.apache.felix.dm.Component in project felix by apache.
the class ResourceAdapterDependencyAddAndRemoveTest method testBasicResourceAdapter.
public void testBasicResourceAdapter() throws Exception {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create and add a service provider
m.add(m.createComponent().setInterface(ServiceInterface.class.getName(), null).setImplementation(new ServiceProvider(e)));
// create and add a resource provider
ResourceProvider provider = new ResourceProvider(context, new URL("file://localhost/path/to/file1.txt"));
m.add(m.createComponent().setImplementation(provider).add(m.createServiceDependency().setService(ResourceHandler.class).setCallbacks("add", "remove")));
// create a resource adapter for our single resource
// note that we can provide an actual implementation instance here because there will be only one
// adapter, normally you'd want to specify a Class here
// also, create a callback instance which will be used for both callbacks on resource changes and
// life cycle callbacks on the adapters themselves
Dependency d = m.createServiceDependency().setService(ServiceInterface.class).setRequired(true);
CallbackInstance callbackInstance = new CallbackInstance(e, d);
Component component = m.createResourceAdapterService("(&(path=/path/to/*.txt)(host=localhost))", false, callbackInstance, "changed").setImplementation(new ResourceAdapter(e)).setCallbacks(callbackInstance, "init", "start", "stop", "destroy");
// add the resource adapter
m.add(component);
// wait until the single resource is available (the adapter has been started)
e.waitForStep(1, 5000);
// trigger a 'change' in our resource
provider.change();
// wait until the changed callback is invoked
e.waitForStep(2, 5000);
// and has completed (ensuring no "extra" steps are invoked in the mean time)
e.waitForStep(3, 5000);
// remove the resource adapter again
// add a component state listener, in order to track resource adapter destruction
component.add(new ComponentStateListenerImpl(e));
m.remove(component);
// wait for the stopped callback in the state listener
e.waitForStep(4, 5000);
m.clear();
}
use of org.apache.felix.dm.Component in project felix by apache.
the class ServiceDependencyCallbackSignaturesTest method declareConsumer.
private void declareConsumer(DependencyManager m, Object consumerImpl) {
Component consumer = m.createComponent().setImplementation(consumerImpl).add(m.createServiceDependency().setService(Provider.class).setCallbacks("bind", "change", "change").setRequired(true));
m.add(consumer);
}
Aggregations