public abstract class SimpleServicePublisher extends Object implements org.osgi.service.cm.ManagedService
Using this class helps to decouple business logic from the OSGi environment. The business class can be kept clean
from any OSGi specific needs like dependency setters, activate/deactivate methods or the implementation of OSGi
related interfaces like ManagedService to receive configuration data. This makes the business logic far
easier to test and results in a mucher cleaner design.
Another approach to decouple the service logic from the OSGi environment is to create an abstract service class which declares all it's dependencies as abstract getter methods. The OSGi connection is then implemented in an inheriting class. This method, however, has the drawback of having to renounce a constructor implementation since no dependencies have been set yet.
| Modifier and Type | Class and Description |
|---|---|
static class |
SimpleServicePublisher.ServiceReg |
| Constructor and Description |
|---|
SimpleServicePublisher() |
| Modifier and Type | Method and Description |
|---|---|
void |
activate(org.osgi.service.component.ComponentContext cc)
OSGi callback.
|
static Effect0 |
close(Closeable c)
Create an effect to close a closeable suitable to return by
registerService(java.util.Dictionary, org.osgi.service.component.ComponentContext). |
static Effect0 |
close(PersistenceEnv penv)
Create an effect to close a persistence environment suitable to return by
registerService(java.util.Dictionary, org.osgi.service.component.ComponentContext). |
void |
deactivate()
OSGi callback.
|
abstract boolean |
needConfig()
Return false if the service to be registered does not need a configuration dictionary provided by the ConfigAdmin.
|
static org.osgi.framework.ServiceRegistration |
registerService(org.osgi.service.component.ComponentContext cc,
Object o,
Class serviceClass,
String serviceDescription)
Register a service with the OSGi environment in a standardized way.
|
abstract SimpleServicePublisher.ServiceReg |
registerService(Dictionary properties,
org.osgi.service.component.ComponentContext cc)
Create and register a service object.
|
static Effect0 |
unregisterService(org.osgi.framework.ServiceRegistration sr)
Create an effect to unregister a service suitable to return by
registerService(java.util.Dictionary, org.osgi.service.component.ComponentContext). |
void |
updated(Dictionary properties) |
public abstract SimpleServicePublisher.ServiceReg registerService(Dictionary properties, org.osgi.service.component.ComponentContext cc) throws org.osgi.service.cm.ConfigurationException
registerService(org.osgi.service.component.ComponentContext, Object, Class, String) or
cc.getBundleContext().registerService(..).properties - a configuration object received by the ManagedService.updated(java.util.Dictionary) callback,
never nullorg.osgi.service.cm.ConfigurationExceptionpublic abstract boolean needConfig()
public void activate(org.osgi.service.component.ComponentContext cc)
throws org.osgi.service.cm.ConfigurationException
org.osgi.service.cm.ConfigurationExceptionpublic void deactivate()
public void updated(Dictionary properties) throws org.osgi.service.cm.ConfigurationException
updated in interface org.osgi.service.cm.ManagedServiceorg.osgi.service.cm.ConfigurationExceptionpublic static org.osgi.framework.ServiceRegistration registerService(org.osgi.service.component.ComponentContext cc,
Object o,
Class serviceClass,
String serviceDescription)
Constants.SERVICE_PID and Constants.SERVICE_DESCRIPTION are
created properly.public static Effect0 unregisterService(org.osgi.framework.ServiceRegistration sr)
registerService(java.util.Dictionary, org.osgi.service.component.ComponentContext).public static Effect0 close(Closeable c)
registerService(java.util.Dictionary, org.osgi.service.component.ComponentContext).public static Effect0 close(PersistenceEnv penv)
registerService(java.util.Dictionary, org.osgi.service.component.ComponentContext).Copyright © 2009–2020 Opencast Project. All rights reserved.