use of org.osgi.framework.ServiceRegistration in project felix by apache.
the class ExtraServicePropertiesTest method testExtraFactoryServiceProperties.
/**
* Tests if a Service instantiated by a Factory set can provide its service properties from its start method.
*/
public void testExtraFactoryServiceProperties() {
Ensure e = new Ensure();
ServiceRegistration sr = register(e, ExtraFactoryServiceProperties.ENSURE);
e.waitForStep(3, 10000);
sr.unregister();
}
use of org.osgi.framework.ServiceRegistration in project felix by apache.
the class FELIX5337Test method testCatchAllServicesUsingAnnotation.
public void testCatchAllServicesUsingAnnotation() {
Ensure e = new Ensure();
ServiceRegistration sr = register(e, FELIX5337.ENSURE);
// wait for S to be started
e.waitForStep(2, 5000);
// remove our sequencer: this will stop S
sr.unregister();
// ensure that S is stopped and destroyed
e.waitForStep(3, 5000);
}
use of org.osgi.framework.ServiceRegistration in project felix by apache.
the class FactoryConfigurationAdapterAnnotationTest method testFactoryConfigurationAdapterAnnotation.
@SuppressWarnings("serial")
public void testFactoryConfigurationAdapterAnnotation() throws Throwable {
Ensure e = new Ensure();
ServiceRegistration sr = register(e, ServiceProvider.ENSURE);
ConfigurationAdmin cm = (ConfigurationAdmin) context.getService(context.getServiceReference(ConfigurationAdmin.class.getName()));
try {
// Create a factory configuration in order to instantiate the ServiceProvider
org.osgi.service.cm.Configuration cf = cm.createFactoryConfiguration("FactoryPidTest", null);
cf.update(new Hashtable() {
{
put("foo2", "bar2");
}
});
// Wait for the ServiceProvider activation.
e.waitForStep(2, MAXWAIT);
// Update conf
cf.update(new Hashtable() {
{
put("foo2", "bar2_modified");
}
});
// Wait for effective update
e.waitForStep(4, MAXWAIT);
// Remove configuration.
cf.delete();
// Check if ServiceProvider has been stopped.
e.waitForStep(6, MAXWAIT);
e.ensure();
sr.unregister();
} catch (IOException err) {
err.printStackTrace();
Assert.fail("can't create factory configuration");
}
}
use of org.osgi.framework.ServiceRegistration in project felix by apache.
the class Felix4357Test method testSingleProperty.
public void testSingleProperty() {
Ensure e = new Ensure();
ServiceRegistration sr = register(e, Felix4357.ENSURE);
// wait for S to be started
e.waitForStep(30, 10000);
// remove our sequencer: this will stop S
sr.unregister();
}
use of org.osgi.framework.ServiceRegistration in project felix by apache.
the class Felix method registerService.
/**
* Implementation for BundleContext.registerService(). Registers
* a service for the specified bundle bundle.
*
* @param classNames A string array containing the names of the classes
* under which the new service is available.
* @param svcObj The service object or <code>ServiceFactory</code>.
* @param dict A dictionary of properties that further describe the
* service or null.
* @return A <code>ServiceRegistration</code> object or null.
*/
ServiceRegistration registerService(BundleContextImpl context, String[] classNames, Object svcObj, Dictionary dict) {
if (classNames == null) {
throw new NullPointerException("Service class names cannot be null.");
} else if (svcObj == null) {
throw new IllegalArgumentException("Service object cannot be null.");
}
ServiceRegistration reg = null;
// service object is a service factory.
if (!(svcObj instanceof ServiceFactory)) {
for (int i = 0; i < classNames.length; i++) {
Class clazz = Util.loadClassUsingClass(svcObj.getClass(), classNames[i], m_secureAction);
if (clazz == null) {
throw new IllegalArgumentException("Cannot cast service: " + classNames[i]);
} else if (!clazz.isAssignableFrom(svcObj.getClass())) {
throw new IllegalArgumentException("Service object is not an instance of \"" + classNames[i] + "\".");
}
}
}
reg = m_registry.registerService(context.getBundle(), classNames, svcObj, dict);
// to invoke the callback with all existing service listeners.
if (HookRegistry.isHook(classNames, org.osgi.framework.hooks.service.ListenerHook.class, svcObj)) {
org.osgi.framework.hooks.service.ListenerHook lh = (org.osgi.framework.hooks.service.ListenerHook) getService(this, reg.getReference(), false);
if (lh != null) {
try {
m_secureAction.invokeServiceListenerHookAdded(lh, m_dispatcher.getAllServiceListeners());
} catch (Throwable th) {
m_logger.log(reg.getReference(), Logger.LOG_WARNING, "Problem invoking service registry hook", th);
} finally {
this.ungetService(this, reg.getReference(), null);
}
}
}
this.fireServiceEvent(new ServiceEvent(ServiceEvent.REGISTERED, reg.getReference()), null);
return reg;
}
Aggregations