use of org.apache.felix.dm.Component in project felix by apache.
the class UngetAspectServiceTest method testUngetSwappedService.
public void testUngetSwappedService() {
DependencyManager m = getDM();
Client clientInstance = new Client();
Component client = m.createComponent().setImplementation(clientInstance).add(m.createServiceDependency().setService(Provider.class).setRequired(true).setCallbacks("bind", null, null, "swap"));
Component provider = m.createComponent().setImplementation(new ProviderImpl()).setInterface(Provider.class.getName(), null);
Aspect aspectInstance = new Aspect();
Component aspect = m.createAspectService(Provider.class, null, 1).setImplementation(aspectInstance);
// add client, provider
m.add(client);
m.add(provider);
// wait for client to be bound to provider
m_ensure.waitForStep(1, 5000);
// add aspect
m.add(aspect);
// check for client to be swapped with aspect
m_ensure.waitForStep(2, 5000);
// remove client, and aspect
m.remove(client);
m.remove(aspect);
// Now, no more references should point to the provider
Assert.assertEquals(false, this.context.ungetService(clientInstance.getServiceRef()));
}
use of org.apache.felix.dm.Component in project felix by apache.
the class UngetServiceTest method testUngetService.
public void testUngetService() {
DependencyManager m = getDM();
Component service = m.createComponent().setImplementation(new Service()).setInterface(Service.class.getName(), null);
m.add(service);
Client clientImpl = new Client();
Component client = m.createComponent().setImplementation(clientImpl).add(m.createServiceDependency().setService(Service.class).setRequired(true).setCallbacks("bind", null));
m.add(client);
m_ensure.waitForStep(1, 5000);
m.remove(client);
// The client has been removed and the service reference must have been ungotten.
ServiceReference ref = clientImpl.getServiceRef();
Assert.assertEquals(false, this.context.ungetService(ref));
m.remove(service);
}
use of org.apache.felix.dm.Component in project felix by apache.
the class Activator method init.
@Override
public void init(BundleContext context, DependencyManager dm) throws Exception {
Component c = createComponent().setImplementation(AddRemoveService.class).setInterface(AddRemoveService.class.getName(), null);
dm.add(c);
dm.remove(c);
}
use of org.apache.felix.dm.Component in project felix by apache.
the class AdapterAndConsumerTest method testServiceWithAdapterAndConsumer.
public void testServiceWithAdapterAndConsumer() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
Component provider = component(m).provides(OriginalService.class).impl(new ServiceProvider(e)).build();
Component consumer = component(m).impl(new ServiceConsumer(e)).withSvc(AdaptedService.class, true).build();
Component adapter = adapter(m, OriginalService.class).provides(AdaptedService.class).impl(ServiceAdapter.class).build();
// add the provider and the adapter
m.add(provider);
m.add(adapter);
// add a consumer that will invoke the adapter
// which will in turn invoke the original provider
m.add(consumer);
// now validate that both have been invoked in the right order
e.waitForStep(2, 5000);
// remove the provider again
m.remove(provider);
// ensure that the consumer is stopped
e.waitForStep(3, 5000);
// remove adapter and consumer
m.remove(adapter);
m.remove(consumer);
}
use of org.apache.felix.dm.Component in project felix by apache.
the class AdapterWithCallbackInstanceTest method testServiceWithAdapterAndConsumer.
public void testServiceWithAdapterAndConsumer() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
ServiceProvider serviceProvider = new ServiceProvider(e);
Component provider = component(m).provides(OriginalService.class).impl(serviceProvider).build();
Component consumer = component(m).impl(new ServiceConsumer(e)).withSvc(AdaptedService.class, true).build();
ServiceAdapterCallbackInstance callbackInstance = new ServiceAdapterCallbackInstance(e);
Component adapter = adapter(m, OriginalService.class).provides(AdaptedService.class).impl(new ServiceAdapter(e)).propagate(true).autoConfig("m_originalService").callbackInstance(callbackInstance).add("set").change("changed").remove("unset").build();
// add the provider and the adapter
m.add(provider);
m.add(adapter);
// Checks if the callbackInstances is called, and if the adapter start method is called
e.waitForStep(2, 5000);
// add a consumer that will invoke the adapter
// which will in turn invoke the original provider
m.add(consumer);
// now validate that both have been invoked in the right order
e.waitForStep(4, 5000);
// change the service properties of the provider, and check that the adapter callback instance is changed.
serviceProvider.changeServiceProperties();
e.waitForStep(5, 5000);
// remove the provider
m.remove(provider);
// ensure that the consumer is stopped, the adapter callback is called in its unset method, and the adapter is stopped.
e.waitForStep(8, 5000);
// remove adapter and consumer
m.remove(adapter);
m.remove(consumer);
}
Aggregations