All eXtreme
Scale ObjectGrid and BackingMap
plug-ins can be defined as OSGi beans and services using the OSGi
Blueprint Service available with Eclipse Gemini or Apache Aries.
Before you begin
Before you can configure your plug-ins as OSGi services,
you
must first package your plug-ins in an OSGi bundle, and understand
the fundamental principles of the required plug-ins. The bundle must
import the
WebSphere® eXtreme Scale server
or client packages and other dependent packages required by the plug-ins,
or create a bundle dependency on the
eXtreme Scale server or client
bundles This topic describes how to configure the Blueprint XML to
create plug-in beans and expose them as OSGi services for
eXtreme Scale to use.
About this task
Beans and services are defined in a Blueprint XML file,
and the Blueprint container discovers, creates, and wires the beans
together and exposes them as services. The process makes the beans
available to other OSGi bundles, including the eXtreme Scale server and client
bundles.
When creating custom plug-in services for use with eXtreme Scale, the bundle that
is to host the plug-ins, must be configured to use Blueprint. In addition,
a Blueprint XML file must be created and stored within the bundle.
Read about building OSGi applications with the Blueprint Container
specification for a general understanding of the specification.
Procedure
- Create a Blueprint XML file. You can name the
file anything. However, you must include the blueprint namespace:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
...
</blueprint>
- Create bean definitions
in the Blueprint XML file for each eXtreme Scale plug-in.
Beans
are defined using the
<bean> element and can be
wired to other bean references and can include initialization parameters.
Important: When defining a bean, you must use the correct
scope. Blueprint supports the singleton and prototype scopes. eXtreme Scale also supports a custom
shard scope.
Define most eXtreme Scale plug-ins as prototype
or shard-scoped beans, since all of the beans must be unique for each ObjectGrid shard
or BackingMap instance it is associated with.
Shard-scoped beans can be useful when using the beans in other contexts
to allow retrieving the correct instance.
To define a prototype-scoped
bean, use the
scope="prototype" attribute on the
bean:
<bean id="myPluginBean" class="com.mycompany.MyBean" scope="prototype">
...
</bean>
To define a shard-scoped bean, you must
add the
objectgrid namespace to the XML schema,
and use the
scope="objectgrid:shard" attribute on
the bean:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:objectgrid="http://www.ibm.com/schema/objectgrid"
xsi:schemaLocation="http://www.ibm.com/schema/objectgrid
http://www.ibm.com/schema/objectgrid/objectgrid.xsd">
<bean id="myPluginBean" class="com.mycompany.MyBean"
scope="objectgrid:shard">
...
</bean>
...
- Create PluginServiceFactory bean definitions
for each plug-in bean. All eXtreme Scale beans must have a PluginServiceFactory bean
defined so that the correct bean scope can be applied. eXtreme Scale includes a BlueprintServiceFactory that
you can use. It includes two properties that must be set. You must
set the blueprintContainer property to the blueprintContainer reference,
and the beanId property must be set to the bean
identifier name. When eXtreme Scale looks
up the service to instantiate the appropriate beans, the server looks
up the bean component instance using the Blueprint container.
bean id="myPluginBeanFactory"
class="com.ibm.websphere.objectgrid.plugins.osgi.BluePrintServiceFactory">
<property name="blueprintContainer" ref="blueprintContainer" />
<property name="beanId" value="myPluginBean" />
</bean>
- Create a service manager
for each PluginServiceFactory bean. Each service manager exposes the PluginServiceFactory bean,
using the <service> element. The service element
identifies the name to expose to OSGi, the reference to the PluginServiceFactory bean,
the interface to expose, and the ranking of the service. eXtreme Scale uses the service
manager ranking to perform service upgrades when the eXtreme Scale grid is active.
If the ranking is not specified, the OSGi framework assumes a ranking
of 0. Read about updating service rankings for more information.
Blueprint
includes several options for configuring service managers. To define
a simple service manager for a
PluginServiceFactory bean,
create a
<service> element for each
PluginServiceFactory bean:
<service ref="myPluginBeanFactory"
interface="com.ibm.websphere.objectgrid.plugins.osgi.PluginServiceFactory"
ranking="1">
</service>
- Store the Blueprint
XML file in the plug-ins bundle. The Blueprint XML file
must be stored in the OSGI-INF/blueprint directory
for the Blueprint container to be discovered.
To store the Blueprint
XML file in a different directory, you must specify the following
Bundle-Blueprint manifest header:
Bundle-Blueprint: OSGI-INF/blueprint.xml
Results
The
eXtreme Scale plug-ins
are now configured to be exposed in an OSGi Blueprint container, In
addition, the ObjectGrid descriptor XML file is configured to reference
the plug-ins using the OSGi Blueprint service.