Open main menu

CDOT Wiki β

Changes

OSGi Concepts Services

283 bytes added, 15:30, 21 January 2011
no edit summary
{{Ecl_menu}}<h2>OSGi Services</h2>
:A bundles can register and use services in OSGi. OSGi provides therefore a central registry for this purpose. A service is defined by a Java interface (POJI - Plain Old Java Interface) [http://www.vogella.de/articles/OSGi/article.html#OSGiintro_services].
:Access to the service registry is performed via the class [http://www.osgi.org/javadoc/r4v42/org/osgi/framework/BundleContext.html BundleContext]. OSGi injects the BundleContext into each bundle during the startup of the bundle. A bundle can also register itself to the BundleContext [http://www.osgi.org/javadoc/r4v42/org/osgi/framework/ServiceEvent.html ServiceEvents] which are for example triggered if a new service is installed or de-installed.
 
For example, let us suppose that one wants to define a service that is capable to define the day and time.
For the purpose one defines an interface:
 
<source lang="java">
 
package cs.ecl.osgi.simple.declarativeservice.say;
 
 
public interface Sayable {
String say();
}
 
</source>