blob: ad9869efa3cf5f51e14aaf2d702a1c85495c9516 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Example 8 - Spell Checker Service using Service Binder :: Apache Felix</title>
<link rel="canonical" href="https://felix.apache.org/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-8.html">
<meta name="generator" content="Antora 2.3.4">
<link rel="stylesheet" href="../../../_/css/site.css">
<link rel="icon" href="../../../_/img/favicon.png" type="image/x-icon">
</head>
<body class="article">
<header class="header">
<nav class="navbar">
<div class="navbar-brand">
<a class="navbar-item" href="https://felix.apache.org/index.html">
<span>
<img src="../../../_/img/logo.png">
</span>
</a>
<button class="navbar-burger" data-target="topbar-nav">
<span></span>
<span></span>
<span></span>
</button>
</div>
<div id="topbar-nav" class="navbar-menu">
<div class="navbar-end">
<a class="navbar-item" href="https://felix.apache.org/index.html">Home</a>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" href="#">Subprojects</a>
<div class="navbar-dropdown">
<a class="navbar-item" href="../../subprojects/apache-felix-dependency-manager.html">Dependency Manager</a>
<a class="navbar-item" href="../../subprojects/apache-felix-event-admin.html">Event Admin</a>
<a class="navbar-item" href="../../subprojects/apache-felix-file-install.html">File Install</a>
<a class="navbar-item" href="../../subprojects/apache-felix-framework.html">Framework</a>
<a class="navbar-item" href="../../subprojects/apache-felix-gogo.html">Gogo Shell</a>
<a class="navbar-item" href="../../subprojects/apache-felix-healthchecks.html">Health Checks</a>
<a class="navbar-item" href="../../subprojects/apache-felix-inventory.html">Inventory</a>
<a class="navbar-item" href="../../subprojects/apache-felix-log.html">Log</a>
<a class="navbar-item" href="../../subprojects/apache-felix-logback.html">Logback</a>
<a class="navbar-item" href="../../subprojects/apache-felix-maven-bundle-plugin.html">Maven bundle plugin</a>
<a class="navbar-item" href="../../subprojects/apache-felix-maven-scr-plugin.html">Maven SCR plugin</a>
<a class="navbar-item" href="../../subprojects/apache-felix-metatype-service.html">Metatype Service</a>
<a class="navbar-item" href="../../subprojects/apache-felix-preferences-service.html">Preferences Service</a>
<a class="navbar-item" href="../../subprojects/apache-felix-remote-shell.html">Remote Shell</a>
<a class="navbar-item" href="../../subprojects/apache-felix-script-console-plugin.html">Script console plugin</a>
<a class="navbar-item" href="../../subprojects/apache-felix-shell.html">Lightweight shell</a>
<a class="navbar-item" href="../../subprojects/apache-felix-shell-tui.html">Shell TUI</a>
<a class="navbar-item" href="../../subprojects/apache-felix-web-console.html">Web Console</a>
</div>
</div>
<div class="navbar-item">
<span class="control">
<a class="button is-primary" href="../../downloads.html">Downloads</a>
</span>
</div>
</div>
</div>
</nav>
</header>
<div class="body">
<div class="nav-container" data-component="documentation" data-version="master">
<aside class="nav">
<div class="panels">
<div class="nav-panel-menu is-active" data-panel="menu">
<nav class="nav-menu">
<h3 class="title"><a href="../../index.html">Documentation</a></h3>
<ul class="nav-list">
<li class="nav-item" data-depth="0">
<ul class="nav-list">
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../../documentation.html">Documentation</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../../downloads.html">Downloads</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../../getting-started.html">Getting Started</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../../news.html">News</a>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<span class="nav-text">Community</span>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../community/project-info.html">Apache Felix Project Info</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../community/contributing.html">Contributing</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../community/projects-using-felix.html">Projects Using Felix</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<span class="nav-text">Development</span>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../development/coding-standards.html">Coding Standards</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../development/dependencies-file-template.html">DEPENDENCIES file template</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../development/provisional-osgi-api-policy.html">Provisional OSGi API Policy</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../development/release-management-nexus.html">Release Management</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../development/site-how-to.html">Site How To</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../development/using-the-osgi-compliance-tests.html">Using the OSGi Compliance Tests</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../faqs.html">FAQS</a>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../faqs/apache-felix-bundle-plugin-faq.html">Apache Felix Bundle Plugin Frequently Asked Questions</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../faqs/apache-felix-scr-plugin-faq.html">Apache Felix SCR Plugin Frequently Asked Questions</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../subprojects.html">Subprojects</a>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager.html">Apache Felix Dependency Manager</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<span class="nav-text">Guides</span>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/guides/migrating-from-earlier-versions.html">Apache Felix Dependency Manager - Migrating from earlier versions</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/guides/annotations.html">Dependency Manager - Annotations</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/guides/background.html">Dependency Manager - Background</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/guides/bundles-and-dependencies.html">Dependency Manager - Bundles and Dependencies</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/guides/design-patterns.html">Dependency Manager - Design Patterns</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/guides/development.html">Dependency Manager - Development</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/guides/history.html">Dependency Manager - History</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/guides/javadocs.html">Dependency Manager - JavaDocs</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/guides/migrating-from-other-solutions.html">Dependency Manager - Migrating from other solutions.</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/guides/performance-tuning.html">Dependency Manager - Performance Tuning</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/guides/resources.html">Dependency Manager - Resource adapters</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/guides/whatsnew.html">Dependency Manager - What&#8217;s new in version 4?</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/guides/dm-lambda.html">Dependency Manager Lambda</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/guides/whatsnew-r15.html">What&#8217;s New in R15</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<span class="nav-text">Reference</span>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/reference/component-adapter.html">Dependency Manager - Adapter</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/reference/component-aspect.html">Dependency Manager - Aspect</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/reference/component-bundle-adapter.html">Dependency Manager - Bundle Adapter</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/reference/dependency-bundle.html">Dependency Manager - Bundle Dependency</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/reference/components.html">Dependency Manager - Components</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/reference/dependency-configuration.html">Dependency Manager - Configuration Dependency</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/reference/dependencies.html">Dependency Manager - Dependencies</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/reference/external-links.html">Dependency Manager - External Links</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/reference/component-factory-configuration-adapter.html">Dependency Manager - Factory Configuration Adapter Service</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/reference/component-resource-adapter.html">Dependency Manager - Resource Adapter</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/reference/dependency-resource.html">Dependency Manager - Resource Dependency</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/reference/dependency-service.html">Dependency Manager - Service Dependency</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/reference/service-scopes.html">Dependency Manager - Service Scopes</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/reference/component-singleton.html">Dependency Manager - Singleton Component</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/reference/thread-model.html">Dependency Manager - Thread Model</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/reference/dm-annotations.html">Dependency Manager Annotations</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<span class="nav-text">Tutorials</span>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/tutorials/working-with-annotations.html">Dependency Manager - Annotations</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/tutorials/getting-started.html">Dependency Manager - Getting Started</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/tutorials/leveraging-the-shell.html">Dependency Manager - Leveraging the shell</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-dependency-manager/tutorials/sample-code.html">Dependency Manager sample projects</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../subprojects/apache-felix-event-admin.html">Apache Felix Event Admin</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../subprojects/apache-felix-file-install.html">Apache Felix File Install</a>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../subprojects/apache-felix-framework.html">Apache Felix Framework</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../subprojects/apache-felix-framework/apache-felix-framework-bundle-cache.html">Apache Felix Framework Bundle Cache</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../subprojects/apache-felix-framework/apache-felix-framework-configuration-properties.html">Apache Felix Framework Configuration Properties</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../subprojects/apache-felix-framework/apache-felix-framework-faq.html">Apache Felix Framework Frequently Asked Questions</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../subprojects/apache-felix-framework/apache-felix-framework-launching-and-embedding.html">Apache Felix Framework Launching and Embedding</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../subprojects/apache-felix-framework/apache-felix-framework-usage-documentation.html">Apache Felix Framework Usage Documentation</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../subprojects/apache-felix-framework-security.html">Apache Felix Framework Security</a>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../subprojects/apache-felix-gogo.html">Apache Felix Gogo</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../subprojects/apache-felix-gogo/rfc-147-overview.html">RFC 147 Overview</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../subprojects/apache-felix-healthchecks.html">Apache Felix Health Checks</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../subprojects/apache-felix-inventory.html">Apache Felix Inventory Printer</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../subprojects/apache-felix-log.html">Apache Felix Log</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../subprojects/apache-felix-logback.html">Apache Felix Logback</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../subprojects/apache-felix-maven-bundle-plugin-bnd.html">Apache Felix Maven Bundle Plugin (BND)</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../subprojects/apache-felix-metatype-service.html">Apache Felix Metatype Service</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../subprojects/apache-felix-osgi-bundle-repository.html">Apache Felix OSGi Bundle Repository (OBR)</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../subprojects/apache-felix-preferences-service.html">Apache Felix Preferences Service</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../subprojects/apache-felix-remote-shell.html">Apache Felix Remote Shell</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../subprojects/apache-felix-shell.html">Apache Felix Shell</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../../subprojects/apache-felix-shell-tui.html">Apache Felix Shell TUI</a>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../subprojects/apache-felix-web-console.html">Apache Felix Web Console</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../subprojects/apache-felix-web-console/extending-the-apache-felix-web-console.html">Extending the Apache Felix Web Console</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../subprojects/apache-felix-web-console/web-console-restful-api.html">Web Console RESTful API</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../subprojects/apache-felix-web-console/web-console-security-provider.html">Web Console Security Provider</a>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<span class="nav-text">Extensions</span>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-web-console/extending-the-apache-felix-web-console/branding-the-web-console.html">Branding the Web Console</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-web-console/extending-the-apache-felix-web-console/providing-resources.html">Providing Resources</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-web-console/extending-the-apache-felix-web-console/providing-web-console-plugins.html">Providing Web Console Plugins</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-web-console/extending-the-apache-felix-web-console/web-console-logging.html">Web Console Logging</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="../../subprojects/apache-felix-web-console/extending-the-apache-felix-web-console/web-console-output-templating.html">Web Console Output Templating</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<span class="nav-text">Maven SCR plugin</span>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../subprojects/apache-felix-maven-scr-plugin/apache-felix-maven-scr-plugin-use.html">Apache Felix Maven SCR Plugin Use</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../subprojects/apache-felix-maven-scr-plugin/apache-felix-scr-bndtools-use.html">Apache Felix SCR Annotations BndTools Use</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../subprojects/apache-felix-maven-scr-plugin/apache-felix-scr-ant-task-use.html">Apache Felix SCR Ant Task Use</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../subprojects/apache-felix-maven-scr-plugin/extending-scr-annotations.html">Extending SCR Annotations Excerpt: How add new Annotations extending the base Annotations</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../subprojects/apache-felix-maven-scr-plugin/scr-annotations.html">SCR Annotations Excerpt: Using Java 5 Annotations to describe the component or service.</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../../subprojects/apache-felix-maven-scr-plugin/scr-javadoc-tags.html">SCR JavaDoc Tags Excerpt: Using JavaDoc Tags to describe the component or service.</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../../tutorials-examples-and-presentations.html">Tutorials</a>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../apache-felix-application-demonstration.html">Apache Felix Application Demonstration</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../apache-felix-osgi-tutorial.html">Apache Felix OSGi Tutorial</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../apache-felix-osgi-faq.html">OSGi Frequently Asked Questions</a>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<span class="nav-text">OSGI Tutorial</span>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-tutorial-example-1.html">Apache Felix Tutorial Example 1 - Service Event Listener Bundle</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-tutorial-example-2.html">Apache Felix Tutorial Example 2</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-tutorial-example-2b.html">Apache Felix Tutorial Example 2b</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-tutorial-example-3.html">Apache Felix Tutorial Example 3</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-tutorial-example-4.html">Apache Felix Tutorial Example 4</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-tutorial-example-5.html">Apache Felix Tutorial Example 5</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-tutorial-example-6.html">Example 6 - Spell Checker Service Bundle</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-tutorial-example-7.html">Example 7 - Spell Checker Client Bundle</a>
</li>
<li class="nav-item is-current-page" data-depth="3">
<a class="nav-link" href="apache-felix-tutorial-example-8.html">Example 8 - Spell Checker Service using Service Binder</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-tutorial-example-9.html">Example 9 - Spell Checker Service using Declarative Services</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../../license.html">Apache License 2.0</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../../site-map.html">Site map</a>
</li>
</ul>
</li>
</ul>
</nav>
</div>
<div class="nav-panel-explore" data-panel="explore">
<div class="context">
<span class="title">Documentation</span>
<span class="version">master</span>
</div>
<ul class="components">
<li class="component is-current">
<span class="title">Documentation</span>
<ul class="versions">
<li class="version is-current is-latest">
<a href="../../index.html">master</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</aside>
</div>
<main class="article">
<div class="toolbar" role="navigation">
<button class="nav-toggle"></button>
<a href="../../index.html" class="home-link"></a>
<nav class="breadcrumbs" aria-label="breadcrumbs">
<ul>
<li><a href="../../index.html">Documentation</a></li>
<li><a href="../../tutorials-examples-and-presentations.html">Tutorials</a></li>
<li>OSGI Tutorial</li>
<li><a href="apache-felix-tutorial-example-8.html">Example 8 - Spell Checker Service using Service Binder</a></li>
</ul>
</nav>
<div class="edit-this-page"><a href="https://github.com/apache/felix-antora-site/edit/main/modules/ROOT/pages/tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-8.adoc">Edit this Page</a></div>
</div>
<div class="content">
<article class="doc">
<h1 class="page">Example 8 - Spell Checker Service using Service Binder</h1>
<div class="paragraph">
<p><em>[Note: The Service Binder was the original project to attempt to automate service dependency management for the OSGi platform and was the inspiration for Declarative Services introduced in OSGi R4.
The Service Binder is no longer under active development, but this example is kept in the tutorial for historical purposes.
New projects should consider using one of the other dependency injection technologies (e.g., Declarative Services, Dependency Manager, or iPOJO).]({{ refs.note-the-service-binder-was-the-original-project-to-attempt-to-automate-service-dependency-management-for-the-osgi-platform-and-was-the-inspiration-for-declarative-services-introduced-in-osgi-r4-the-service-binder-is-no-longer-under-active-development-but-this-example-is-kept-in-the-tutorial-for-historical-purposes-new-projects-should-consider-using-one-of-the-other-dependency-injection-technologies-e-g-declarative-services-dependency-manager-or-ipojo.path }})</em></p>
</div>
<div class="paragraph">
<p>The purpose of this example is to re-implement the spell checker service in Example 6, but to do so using the Service Binder;
to complete this, we must download the link:{{ refs.link.path }}[Service Binder] bundle.
The Service Binder bundle is needed to compile the example and at run time to execute the example.</p>
</div>
<div class="paragraph">
<p>The spell checker service of Example 6 was complex because it needed to aggregate all available dictionary services and monitor their dynamic availability.
In addition, the spell checker service&#8217;s own availability was dependent upon the availability of dictionary services;
in other words, the spell checker service had a dynamic, one-to-many dependency on dictionary services.
As it turns out, service dependencies are not managed at all by the OSGi framework and end up being the responsibility of the application developer.
The Service Binder tries to eliminate complex and error-prone service dependency handling by automating it.
To do this, the Service Binder replaces the BundleActivator code with a generic bundle activator that parses an XML file that describes the instances we want to create and their service dependencies.
Instead of writing a lot of complex code, we simply write a declarative XML file.
For an example, consider the following code for the new service&#8217;s bundle activator in a file called <code>Activator.java</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>/*
* Apache Felix OSGi tutorial.
**/
package tutorial.example8;
import org.apache.felix.servicebinder.GenericActivator;
/**
* This example re-implements the spell checker service of
* Example 6 using the Service Binder. The Service Binder
* greatly simplifies creating OSGi applications by
* essentially eliminating the need to write OSGi-related
* code; instead of writing OSGi code for your bundle, you
* create a simple XML file to describe your bundle's service
* dependencies. This class extends the generic bundle activator;
* it does not provide any additional functionality. All
* functionality for service-related tasks, such as look-up and
* binding, is handled by the generic activator base class using
* data from the metadata.xml file. All application
* functionality is defined in the SpellCheckerImpl.java
* file.
**/
public class Activator extends GenericActivator
{
}</pre>
</div>
</div>
<div class="paragraph">
<p>All custom functionality has been removed from the bundle activator, it is only necessary to subclass the generic activator exported by the Service Binder.
The generic activator performs its task by parsing an XML meta-data file that describes what instances should be created and what their service dependencies are;
for our example, we create a file called <code>metadata.xml</code> that contains the instance and service dependency meta-data:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;bundle&gt;
&lt;!--
-- This meta-data file instructs the Service Binder to
-- create one instance of "SpellCheckerImpl". It also
-- tells the generic activator that this instance implements the
-- "SpellChecker" service interface and that it has an
-- aggregate dependency on "DictionaryService" services. Since
-- the service dependency on dictionary services has a lower
-- cardinality of one, the generic activator will create the instance
-- and offer its spell checker service only when there is at least
-- one dictionary service available. The service dependency is
-- "dynamic", which means that dictionary service availability
-- will be monitored dynamically at runtime and it also tells the
-- generic activator which methods to call when adding and removing
-- dictionary services.
--&gt;
&lt;instance class="tutorial.example8.SpellCheckerImpl"&gt;
&lt;service interface="tutorial.example6.service.SpellChecker"/&gt;
&lt;requires
service="tutorial.example2.service.DictionaryService"
filter="(Language=*)"
cardinality="1..n"
policy="dynamic"
bind-method="addDictionary"
unbind-method="removeDictionary"
/&gt;
&lt;/instance&gt;
&lt;/bundle&gt;</pre>
</div>
</div>
<div class="paragraph">
<p>The above meta-data tells the generic activator to create one instance of <code>tutorial.example8.SpellCheckerImpl</code>, which we will define next.
The meta-data also tells the generic activator that the instance has an aggregate service dependency (in this case, one-to-many) on dictionary services and that the services should be tracked dynamically.
It also specifies the bind and unbind methods that should be called on the instance when dictionary services appear and disappear.
It is important to understand that the generic activator is constantly trying to maintain the instances defined in the meta-data file.
At any given point in time, a specific instance may be valid (if all service dependencies are satisfied) or invalid (if any service dependencies are unsatisfied), but at all times the generic activator is trying to get the declared instances into a valid state.
The code for our new spell checker service is very similar to the implementation in Example 6, but it is no longer implemented as an inner class of the activator.
We define the new spell checker service in a file called <code>SpellCheckerImpl.java</code> as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>/*
* Apache Felix OSGi tutorial.
**/
package tutorial.example8;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;
import tutorial.example2.service.DictionaryService;
import tutorial.example6.service.SpellChecker;
/**
* This class re-implements the spell checker service of Example 6.
* This service implementation behaves exactly like the one in
* Example 6, specifically, it aggregates all available dictionary
* services, monitors their dynamic availability, and only offers
* the spell checker service if there are dictionary services
* available. The service implementation is greatly simplified,
* though, by using the Service Binder. Notice that there is no OSGi
* references in the application code; instead, the metadata.xml
* file describes the service dependencies, which is read by the
* Service Binder to automatically manage the dependencies and
* register the spell checker service as appropriate.
**/
public class SpellCheckerImpl implements SpellChecker
{
// List of service objects.
private ArrayList m_svcObjList = new ArrayList();
/**
* This method is used by the Service Binder to add
* new dictionaries to the spell checker service.
* @param dictionary the dictionary to add to the spell
* checker service.
**/
public void addDictionary(DictionaryService dictionary)
{
// Lock list and add service object.
synchronized (m_svcObjList)
{
m_svcObjList.add(dictionary);
}
}
/**
* This method is used by the Service Binder to remove
* dictionaries from the spell checker service.
* @param dictionary the dictionary to remove from the spell
* checker service.
**/
public void removeDictionary(DictionaryService dictionary)
{
// Lock list and remove service object.
synchronized (m_svcObjList)
{
m_svcObjList.remove(dictionary);
}
}
/**
* Checks a given passage for spelling errors. A passage is any
* number of words separated by a space and any of the following
* punctuation marks: comma (,), period (.), exclamation mark (!),
* question mark (?), semi-colon (;), and colon(:).
* @param passage the passage to spell check.
* @return An array of misspelled words or null if no
* words are misspelled.
**/
public String[] check(String passage)
{
// No misspelled words for an empty string.
if ((passage == null) || (passage.length() == 0))
{
return null;
}
ArrayList errorList = new ArrayList();
// Tokenize the passage using spaces and punctionation.
StringTokenizer st = new StringTokenizer(passage, " ,.!?;:");
// Lock the service list.
synchronized (m_svcObjList)
{
// Loop through each word in the passage.
while (st.hasMoreTokens())
{
String word = st.nextToken();
boolean correct = false;
// Check each available dictionary for the current word.
for (int i = 0; (!correct) &amp;&amp; (i &lt; m_svcObjList.size()); i++)
{
DictionaryService dictionary =
(DictionaryService) m_svcObjList.get(i);
if (dictionary.checkWord(word))
{
correct = true;
}
}
// If the word is not correct, then add it
// to the incorrect word list.
if (!correct)
{
errorList.add(word);
}
}
}
// Return null if no words are incorrect.
if (errorList.size() == 0)
{
return null;
}
// Return the array of incorrect words.
return (String[]) errorList.toArray(new String[errorList.size()]);
}
}</pre>
</div>
</div>
<div class="paragraph">
<p>Notice how much simpler this service implementation is when compared to the same service implemented in Example 6.
There are no references to OSGi interfaces in our application code and all tricky and complex code dealing with monitoring of services is handled for us.
We must still create a <code>manifest.mf</code> file that contains the meta-data for the bundle;
the manifest file is as follows:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>Bundle-Activator: tutorial.example8.Activator
Import-Package: tutorial.example2.service, tutorial.example6.service,
org.apache.felix.servicebinder
Bundle-Name: Service Binder Spell checker service
Bundle-Description: A bundle that implements a simple spell checker service
Bundle-Vendor: Apache Felix
Bundle-Version: 1.0.0
Metadata-Location: tutorial/example8/metadata.xml</pre>
</div>
</div>
<div class="paragraph">
<p>We specify which class is used to activate the bundle via the <code>Bundle-Activator</code> attribute and also specify that the bundle imports the spell checker, dictionary, and Service Binder packages.
(Note: Make sure your manifest file ends in a trailing carriage return or else the last line will be ignored.)</p>
</div>
<div class="paragraph">
<p>To compile the source code, we must include the <code>felix.jar</code> file (found in Felix' <code>lib</code> directory), the servicebinder.jar file, the example2.jar file, and the example6.jar file in the class path.
We compile the source file using a command like:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>javac -d c:\classes *.java</pre>
</div>
</div>
<div class="paragraph">
<p>This command compiles all source files and outputs the generated classes into a subdirectory of the <code>c:\classes</code> directory;
this subdirectory is <code>tutorial\example8</code>, named after the package we specified in the source file.
For the above command to work, the <code>c:\classes</code> directory must exist.</p>
</div>
<div class="paragraph">
<p>Before we can create our bundle JAR file, we must copy the bundle&#8217;s service dependency meta-data file, called <code>metadata.xml</code> above, into the example class' package.
Assuming that we used the above command to compile the bundle, then we should copy the <code>metadata.xml</code> file into <code>c:\classes\tutorial\example8</code>.
Now we can create the JAR file for our bundle using the following command:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>jar cfm example8.jar manifest.mf -C c:\classes tutorial\example8</pre>
</div>
</div>
<div class="paragraph">
<p>This command creates a JAR file using the manifest file we created and includes all of the classes and resources in the <code>tutorial\example8</code> directory inside of the <code>c:\classes</code> directory.
Once the JAR file is created, we are ready to install and start the bundle.</p>
</div>
<div class="paragraph">
<p>To run Felix, we follow the instructions described in usage.html.
When we start Felix, it asks for a profile name, we will put all of our bundles in a profile named <code>tutorial</code>.
After running Felix, we should stop all tutorial bundles except for the service bundles.
Use the <code>lb</code> command to make sure that only the bundles from Example 2 and Example 2b are active;
use the <code>start</code> and <code>stop</code> commands as appropriate to start and stop the various tutorial bundles, respectively.
(Note: Felix uses some bundles to provide its command shell, so do not stop these bundles.) We must also install the <code>servicebinder.jar</code> bundle that we downloaded at the beginning of this example.
Assuming that we saved the bundle in our tutorial directory, we install the bundle using the following command:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>install file:/c:/tutorial/servicebinder.jar</pre>
</div>
</div>
<div class="paragraph">
<p>We do not need to start the Service Binder bundle, because it is only a library.
Now we can install and start our spell checker service bundle.
Assuming that we created our bundle in the directory <code>c:\tutorial</code>, we can install and start it in Felix' shell using the following command:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>start file:/c:/tutorial/example8.jar</pre>
</div>
</div>
<div class="paragraph">
<p>The above command installs and starts the bundle in a single step;
it is also possible to install and start the bundle in two steps by using the Felix <code>install</code> and <code>start</code> shell commands.
To stop the bundle, use the Felix <code>stop</code> shell command.
Use the Felix shell <code>lb</code> command to get the bundle identifier number for the spell checker service bundle to stop and restart it at will using the <code>stop</code> and <code>start</code> commands, respectively.
Using the <code>services</code> command, we can see which services are currently available in the OSGi framework, including our dictionary and spell checker services.
We can experiment with our spell checker service&#8217;s dynamic availability by stopping the dictionary service bundles;
when both dictionary services are stopped, the services command will reveal that our bundle is no longer offering its spell checker service.
Likewise, when the dictionary services comeback, so will our spell checker service.
This bundle will work with the spell checker client bundle that we created in Example 7, so feel free to experiment.
To exit Felix, use the <code>shutdown</code> command.</p>
</div>
<div class="paragraph">
<p><em>[Note: The spell checker client bundle in Example 7 could also be re-implemented using the Service Binder approach outlined in this example.
The spell checker client has a one-to-one, dynamic service dependency on the spell checker service.
Further, an entire application of instances could be described in a single <code>metadata.xml</code> in a single bundle or across a collection of bundles and the Service Binder will automatically manage the service dependencies among them.]({{ refs.note-the-spell-checker-client-bundle-in-example-7-could-also-be-re-implemented-using-the-service-binder-approach-outlined-in-this-example-the-spell-checker-client-has-a-one-to-one-dynamic-service-dependency-on-the-spell-checker-service-further-an-entire-application-of-instances-could-be-described-in-a-single-metadata-xml-in-a-single-bundle-or-across-a-collection-of-bundles-and-the-service-binder-will-automatically-manage-the-service-dependencies-among-them.path }})</em></p>
</div>
</article>
<aside class="toc sidebar" data-title="Contents" data-levels="2">
<div class="toc-menu"></div>
</aside>
</div>
</main>
</div>
<footer class="footer">
<p>Content licensed under AL2. UI licensed under MPL-2.0 with extensions licensed under AL2</p>
</footer>
<script src="../../../_/js/site.js"></script>
<script async src="../../../_/js/vendor/highlight.js"></script>
</body>
</html>