Previous Topic

Next Topic

Book Contents

Book Index

SCR Service

Provides information on an implementation of the Service Component Runtime according to the OSGi Declarative Services Specification Release 6.0.

Overview

The specification defines a declarative model of using OSGi services that allows to delay the creation of the service object until the moment it is actually used. Using the declarative services model provides the following benefits:

Registering Bundle

The service is registered by OSGi SCR Bundle.

Service Component

The declarative services model defines a service component as main unit for manipulating with OSGi services functionality.

A service component is an entity consisting of a Java class and its XML description, which can register or reference a service in a lazy fashion. Both, service component's Java class and its description are packed in a bundle that is deployed in the OSGi framework where it functions like any traditional OSGi bundle.

A service component has the following features:

A service component will be referred to as component and its XML description as component description from now on in this document.

Service Component Runtime

The Service Component Runtime (SCR) is the module that manages the components and their lifecycle. It performs the following functions:

Component Context

A component can receive its Component Context through its activate method. A Component Context can be used to locate services referenced by the component, or to enable or disable components from the same bundle.

Component Description

The declaration of a component in an XML format is the component description. It uniquely identifies the component to the SCR and provides information about the component's functionality that will be used by the SCR to perform its management operations.

The component description provides information about:

Component Factories

The declarative services model supports creating multiple instances of the same component type in compliance with the Service Factory concept in the OSGi framework.

Multiple instances of the same component type can be created by:

A component cannot be declared as a factory component and use a Managed Service Factory and Service Factory at the same time. You have to choose only one of these factories to produce new instances of the same component type.

Component Properties

A component can have a set of properties specified in three places in the following order of precedence:

Each component also has COMPONENT_NAME property defined in its description and COMPONENT_ID property given by the SCR.

The COMPONENT_NAME and COMPONENT_ID properties are obligatory and their values cannot be overridden as they uniquely identify the component to the SCR.