458 lines
30 KiB
HTML
458 lines
30 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
|
||
|
||
|
||
|
||
<!--<link rel="shortcut icon" href="https://www.openhab.org/favicon.png"></link>-->
|
||
<title>Coding tasks for OSGi - openHAB 2 - Empowering the Smart Home</title>
|
||
|
||
<!-- CSS -->
|
||
<link type="text/css" rel="stylesheet" href="/v2.1/css/materialize.css" media="screen,projection" />
|
||
<link type="text/css" rel="stylesheet" href="/v2.1/css/pygments-jekyll-style.css" />
|
||
<link type="text/css" rel="stylesheet" href="/v2.1/css/styles.css" />
|
||
<link type="text/css" rel="stylesheet" href="/v2.1/css/openhab.css" />
|
||
<link type="text/css" rel="stylesheet" href="/v2.1/css/collapsible.css" />
|
||
|
||
<!-- Font -->
|
||
<link type="text/css" rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
|
||
<link type="text/css" rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:300,400,700" />
|
||
<link rel="canonical" href="http://docs.openhab.org/developers/prerequisites/osgitasks.html" />
|
||
<script type="text/javascript">var gaProperty = 'UA-47717934-3';var disableStr = 'ga-disable-' + gaProperty;if (document.cookie.indexOf(disableStr + '=true') > -1) {window[disableStr] = true;}</script>
|
||
<script>
|
||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
||
ga('create', 'UA-47717934-3', 'auto');
|
||
ga('set', 'anonymizeIp', true);
|
||
ga('send', 'pageview');
|
||
</script>
|
||
</head>
|
||
|
||
|
||
<body class="documentation">
|
||
<div id="header" class="navbar-fixed">
|
||
<nav role="navigation">
|
||
<div class="container">
|
||
<div class="nav-wrapper">
|
||
<a href="/v2.1/index.html"><img id="logo" src="/images/logo.png" /></a>
|
||
<a href="#" data-activates="nav-mobile" class="button-collapse"><i class="material-icons">menu</i></a>
|
||
<ul class="right hide-on-med-and-down">
|
||
<li><a href="/tutorials/index.html">Tutorials</a></li>
|
||
<li><a href="/v2.1/introduction.html">User Manual</a></li>
|
||
<li><a href="/developers/index.html">Developer Guide</a></li>
|
||
<li><a target="_blank" href="https://community.openhab.org">Community Forum</a></li>
|
||
<li><a target="_blank" href="https://github.com/openhab">GitHub</a></li>
|
||
<li class="search"><i class="material-icons">search</i></li>
|
||
<li class="search">
|
||
<form method="GET" id="searchform" class="search-form" action="/search">
|
||
<input id="query" name="q" type="text" class="search-form-input" placeholder="search" />
|
||
</form>
|
||
</li>
|
||
</ul>
|
||
<ul id="nav-mobile" class="side-nav">
|
||
<li><a href="/v2.1/index.html">Home</a></li>
|
||
<li><a href="/tutorials/index.html">Tutorials</a></li>
|
||
<li><a href="/v2.1/introduction.html">User Manual</a></li>
|
||
<li><a href="/developers/index.html">Developer Guide</a></li>
|
||
<li><a target="_blank" href="https://community.openhab.org">Community Forum</a></li>
|
||
<li><a target="_blank" href="https://github.com/openhab">GitHub</a></li>
|
||
<li class="search">
|
||
<form method="GET" id="searchformmob" class="search-form" action="/search">
|
||
<input id="querymob" name="q" type="text" class="search-form-input" placeholder="search" />
|
||
</form>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</nav>
|
||
</div>
|
||
|
||
|
||
<section id="documentation" class="text content-wrapper">
|
||
<div class="container">
|
||
<div class="side-nav-wrapper">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<ul class="nav">
|
||
<li><a href="/v2.1/developers">Overview</a></li>
|
||
<li><a href="/v2.1/developers/contributing/contributing">Contributing</a></li>
|
||
<li><a href="/v2.1/developers/prerequisites/osgi.html">Prerequisites</a>
|
||
<ul>
|
||
<li><a href="/v2.1/developers/prerequisites/osgi.html">OSGi</a>
|
||
<ul>
|
||
<li><a href="/v2.1/developers/prerequisites/osgi.html">Overview</a></li>
|
||
<li><a href="/v2.1/developers/prerequisites/osgids.html">Declarative Services</a></li>
|
||
<li><a href="/v2.1/developers/prerequisites/osgitasks.html">Coding tasks</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a href="/v2.1/developers/prerequisites/tycho.html">Tycho</a></li>
|
||
<li><a href="/v2.1/developers/prerequisites/equinox.html">Equinox</a></li>
|
||
<li><a href="/v2.1/developers/prerequisites/targetplatform.html">Target Platform</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a href="/v2.1/developers/development/ide.html">Basics</a>
|
||
<ul>
|
||
<li><a href="/v2.1/developers/development/ide.html">IDE Setup</a></li>
|
||
<li><a href="/v2.1/developers/development/guidelines.html">Code Guidelines</a></li>
|
||
<li><a href="/v2.1/developers/development/bindings.html">Developing Bindings</a></li>
|
||
<li><a href="/v2.1/developers/development/logging.html">Logging</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a href="/v2.1/developers/development/evolution.html">Migration from 1.x</a>
|
||
<ul>
|
||
<li><a href="/v2.1/developers/development/evolution.html">Technical Differences</a></li>
|
||
<li><a href="/v2.1/developers/development/compatibilitylayer.html">Compatibility Layer</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
</div>
|
||
<div class="content">
|
||
|
||
<h1 id="coding-tasks-for-osgi">Coding tasks for OSGi</h1>
|
||
|
||
<h2 id="introduction">Introduction</h2>
|
||
|
||
<p>OSGi coding tasks can help Java developers with no experience in OSGi and Eclipse Plug-in development to get familiar with writing bundles. This page contains tasks, related to several fundamental topics, and references to tutorials, where similar tasks are implemented.</p>
|
||
|
||
<h2 id="prerequisites">Prerequisites</h2>
|
||
|
||
<p>Before you start, you should first install the <a href="../development/ide.html">Eclipse IDE</a>.</p>
|
||
|
||
<p>In order to run your samples in an OSGi Runtime you might want to start Equinox in a command line.</p>
|
||
|
||
<p>You might take a look at the <a href="/developers/development/guidelines.html">Coding Guidelines</a> as well.</p>
|
||
|
||
<h2 id="tasks">Tasks</h2>
|
||
|
||
<p>The tasks are divided in several sections:</p>
|
||
|
||
<ul id="markdown-toc">
|
||
<li><a href="#i-writing-basic-osgi-bundle" id="markdown-toc-i-writing-basic-osgi-bundle">I. Writing basic OSGi bundle</a></li>
|
||
<li><a href="#ii-services" id="markdown-toc-ii-services">II. Services</a></li>
|
||
<li><a href="#iii-service-tracker" id="markdown-toc-iii-service-tracker">III. Service Tracker</a></li>
|
||
<li><a href="#iv-declarative-services-and-components" id="markdown-toc-iv-declarative-services-and-components">IV. Declarative Services and Components</a></li>
|
||
<li><a href="#v-events" id="markdown-toc-v-events">V. Events</a></li>
|
||
<li><a href="#vi-managed-services" id="markdown-toc-vi-managed-services">VI. Managed Services</a></li>
|
||
<li><a href="#vii-console-commands" id="markdown-toc-vii-console-commands">VII. Console Commands</a></li>
|
||
</ul>
|
||
|
||
<p>Sample implementations are present in the <a href="https://github.com/openhab/openhab-docs/tree/gh-pages/_sample_code/osgi_codings_tasks/bundles">openHAB docs repo</a>.</p>
|
||
|
||
<h3 id="i-writing-basic-osgi-bundle">I. Writing basic OSGi bundle</h3>
|
||
|
||
<ol>
|
||
<li>
|
||
<p>Create an <code class="highlighter-rouge">org.openhab.training.helloosgi</code> bundle, that prints a message on the console, when it is started and stopped. Test it in the OSGi Container.</p>
|
||
|
||
<p>Hint! You can install a bundle in the OSGi Container with the <code class="highlighter-rouge">install {url} </code> command.<br />
|
||
Hint! If you still have difficulties look at the
|
||
<a href="#writing-basic-osgi-bundle">reference section</a>.</p>
|
||
</li>
|
||
<li>
|
||
<p>Create an <code class="highlighter-rouge">org.openhab.training.utils</code> bundle, which contains class <code class="highlighter-rouge">TimeUtilities</code>, that has a single method <code class="highlighter-rouge">String getCurrentTimeStamp()</code> that returns the current time stamp in format “hh:mm”. Mind the <code class="highlighter-rouge">TimeUtilities</code> class might be used in some other bundles.</p>
|
||
|
||
<p>Hint! Find out how can you export packages in OSGi.</p>
|
||
</li>
|
||
<li>
|
||
<p>Create an <code class="highlighter-rouge">org.openhab.training.helloosgi.modified</code> bundle to use the <code class="highlighter-rouge">TimeUtilities</code> class to display the current time stamp on the console when it is started.</p>
|
||
</li>
|
||
</ol>
|
||
|
||
<h3 id="ii-services">II. Services</h3>
|
||
|
||
<ol>
|
||
<li>Create an <code class="highlighter-rouge">org.openhab.training.electricity.provider</code> bundle, which defines a service interface <code class="highlighter-rouge">ElectricityProvider</code> with one method:
|
||
<ul>
|
||
<li><code class="highlighter-rouge">boolean provide (int value)</code> - discharges the provider with the ‘value’ parameter. It should return true, if the requested charge is available in the provider and false, if it is not;</li>
|
||
</ul>
|
||
</li>
|
||
<li>Create an <code class="highlighter-rouge">org.openhab.training.electricity.homenetwork</code> bundle:
|
||
<ul>
|
||
<li>with <code class="highlighter-rouge">HomeElectricityNetwork</code> implementation of the <code class="highlighter-rouge">ElectricityProvider</code> interface with infinite charge (the <code class="highlighter-rouge">provide()</code> method should always return true);</li>
|
||
<li>which registers the <code class="highlighter-rouge">HomeElectricityNetwork</code> as <code class="highlighter-rouge">ElectricityProvider</code> in the OSGi <em>Service Registry</em> with <a href="https://osgi.org/javadoc/r4v43/core/org/osgi/framework/BundleContext.html"><em>BundleContext</em></a>.</li>
|
||
</ul>
|
||
|
||
<p>Hint! You can find similar tasks in the
|
||
<a href="#services">examples below</a>.</p>
|
||
</li>
|
||
<li>Create an <code class="highlighter-rouge">org.openhab.training.electricity.consumer</code> bundle, which contains an
|
||
interface <code class="highlighter-rouge">ElectricityConsumer</code> with methods:
|
||
<ul>
|
||
<li><code class="highlighter-rouge">void startConsuming()</code> - starts the device and displays a message on the console. If the device requires a provider (it is not energy independent), this method can set the current provider. After the device is started it should try to consume electricity equal to the device consumption from the current provider at fixed interval from 5 seconds and display a message on the console, which provider is in use at the moment;</li>
|
||
<li><code class="highlighter-rouge">void stopConsuming()</code> - stops the device and displays message on the console. The device should not consume electricity anymore. The device should stop, if the current provider is discharged;</li>
|
||
<li><code class="highlighter-rouge">void setCurrentProvider(ElectricityProvider)</code> - sets a current provider from a list with available providers;</li>
|
||
<li><code class="highlighter-rouge">List<ElectricityProvider> getAllAvailableProviders()</code> - returns a list with available providers (a provider is available, when it is registered in the <em>Service Registry</em> and has more charge, than the device consumption).</li>
|
||
</ul>
|
||
</li>
|
||
<li>Create an <code class="highlighter-rouge">org.openhab.training.electricity.radio</code> bundle, which:
|
||
<ul>
|
||
<li>implements the <code class="highlighter-rouge">ElectricityConsumer</code> interface in a <code class="highlighter-rouge">BasicRadio</code> consumer, which has specific consumption (e.g <code class="highlighter-rouge">int consumption = 5</code>) and can be connected to only one provider;</li>
|
||
<li>the device should be able to stop automatically, when there is no provider available and display a message on the console. After that it must be started manually;</li>
|
||
<li>use the <code class="highlighter-rouge">ElectricityProvider</code> service by getting it directly from the <em>BundleContext</em>.</li>
|
||
</ul>
|
||
</li>
|
||
</ol>
|
||
|
||
<h3 id="iii-service-tracker">III. Service Tracker</h3>
|
||
|
||
<ol>
|
||
<li>
|
||
<p>Create an <code class="highlighter-rouge">org.openhab.training.electricity.battery</code> bundle, which implements and registers <code class="highlighter-rouge">Battery</code> implementation of the <code class="highlighter-rouge">ElectricityProvider</code> service with finite charge (e.g <code class="highlighter-rouge">int capacity = 20</code>).</p>
|
||
|
||
<p>Hint! An ElectricityProvider can be used by different consumers simultaneously. Consider whether it is necessary to make an implementation of this class thread-safe.</p>
|
||
</li>
|
||
<li>Create an interface <code class="highlighter-rouge">DynamicConsumer</code> in an <code class="highlighter-rouge">org.openhab.training.electricity.dynamicconsumer</code> bundle that should manage the availability of the different <code class="highlighter-rouge">ElectricityProvider</code>. It defines two methods:
|
||
<ul>
|
||
<li><code class="highlighter-rouge">void providerAdded(ElectricityProvider)</code> - called when a new provider is registered in the <em>ServiceRegistry</em>. It should add the provider in a list with available electricity sources for the current device;</li>
|
||
<li><code class="highlighter-rouge">void providerRemoved(ElectricityProvider)</code> - called when a provider is unregistered from the <em>ServiceRegistry</em>. It should remove the provider from a list with available electricity sources for the current device.</li>
|
||
</ul>
|
||
</li>
|
||
<li>Create a <code class="highlighter-rouge">TV</code> consumer with <code class="highlighter-rouge">int consumption = 10</code>, that implements the <code class="highlighter-rouge">ElectricityConsumer</code> interface and the <code class="highlighter-rouge">DynamicConsumer</code>interface in an <code class="highlighter-rouge">org.openhab.training.electricity.tv</code> bundle by using <a href="https://osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html"><em>ServiceTracker</em></a>. The <code class="highlighter-rouge">TV</code> should be able to dynamically switch between different <code class="highlighter-rouge">ElectricityProvider</code>:
|
||
<ul>
|
||
<li>when both providers are available, it should work with the <code class="highlighter-rouge">HomeElectricityNetwork</code>;</li>
|
||
<li>otherwise it should use the provider that is available at the moment;</li>
|
||
<li>when no provider is available or it can not provide enough charge, the <code class="highlighter-rouge">TV</code> should stop;</li>
|
||
<li>it should be able to start automatically, if a new provider is available and is able to provide enough electricity.</li>
|
||
</ul>
|
||
|
||
<p>Hint! Install <code class="highlighter-rouge">org.eclipse.osgi.util</code> bundle in order to use <em>ServiceTracker</em>.
|
||
Tutorials with examples can be found
|
||
<a href="#service-trackers">below</a>.</p>
|
||
</li>
|
||
</ol>
|
||
|
||
<h3 id="iv-declarative-services-and-components">IV. Declarative Services and Components</h3>
|
||
|
||
<ol>
|
||
<li>Provider and consumer:
|
||
<ul>
|
||
<li>rewrite all tasks in section <a href="#ii-services">II.</a> and <a href="#iii-service-tracker">III.</a> to use the <code class="highlighter-rouge">ElectricityProvider</code> service by injecting it by the means of <a href="osgids.html"><em>Declarative Services</em></a> (do not use Service Tracker and BundleContext).The name of the new bundles will be the same, but ending with a .ds (e.g. <code class="highlighter-rouge">org.openhab.training.electricity.tv.ds</code>);</li>
|
||
</ul>
|
||
|
||
<p>Hint! Install <code class="highlighter-rouge">org.eclipse.equinox.ds</code> bundle in order to use <em>Declarative Services</em>.</p>
|
||
</li>
|
||
<li>
|
||
<p>Create a <code class="highlighter-rouge">SolarRadio</code> consumer that extends <code class="highlighter-rouge">BasicRadio</code> from IV.1 in an <code class="highlighter-rouge">org.openhab.training.electricity.solarradio</code> bundle. This radio does not need any <code class="highlighter-rouge">ElectricityProvider</code> to run, but will use one, if it is available (the device should not stop when there are no providers available).</p>
|
||
|
||
<p>Hint! Read about cardinality in OSGi Declarative Services!</p>
|
||
</li>
|
||
<li>Create a <code class="highlighter-rouge">CombinedSolarRadio</code> that extends <code class="highlighter-rouge">SolarRadio</code> and implements <code class="highlighter-rouge">DynamicConsumer</code> in <code class="highlighter-rouge">org.openhab.training.electricity.combinedradio</code> it the following way:
|
||
<ul>
|
||
<li>the consumer does not need any provider to run;</li>
|
||
<li>if one is available, it must set it as current and use it;</li>
|
||
<li>if more than one are available, add all to the list with available providers.</li>
|
||
</ul>
|
||
|
||
<p>Hint! What happens when you stop the provider that is not in use? Why does the <code class="highlighter-rouge">CombinedSolarRadio</code> stops and starts? Modify the consumer to handle the removal of the service dynamically - without calling the stop and start methods every time! Read about service policy in OSGi!</p>
|
||
|
||
<p>Hint! Test all the bundles in the OSGi container by starting and stopping the different <code class="highlighter-rouge">ElectricityProvider</code> implementations and track, if the consumers are used as expected.</p>
|
||
</li>
|
||
</ol>
|
||
|
||
<h3 id="v-events">V. Events</h3>
|
||
|
||
<ol>
|
||
<li>
|
||
<p>Create a bundle <code class="highlighter-rouge">org.openhab.training.util.sender</code> that registers as a service <code class="highlighter-rouge">TimeEventSender</code>, that sends events with topic “org/openhab/training/time” every minute with the current time stamp (hh:mm) (you can use the <code class="highlighter-rouge">TimeUtilities</code> class from chapter <a href="#i-writing-basic-osgi-bundle">I.</a>).</p>
|
||
|
||
<p>Hint! Install <code class="highlighter-rouge">org.eclipse.equinox.event</code> bundle in order to use <em>EventAdmin</em> service for sending events.<br />
|
||
Hint! <a href="https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html">ScheduledExecutorService</a> can be used in this task.</p>
|
||
</li>
|
||
<li>
|
||
<p>Extend the <code class="highlighter-rouge">org.openhab.training.electricity.tv.ds.TV</code> class from IV.1 in an <code class="highlighter-rouge">org.openhab.training.electricity.tv.events</code> bundle to listen for events and print them on the console.</p>
|
||
</li>
|
||
</ol>
|
||
|
||
<h3 id="vi-managed-services">VI. Managed Services</h3>
|
||
|
||
<ol>
|
||
<li>Implement the <a href="https://osgi.org/javadoc/r4v42/org/osgi/service/cm/ManagedService.html"><em>ManagedService</em></a> interface in the <code class="highlighter-rouge">org.openhab.training.electricity.tv.events</code> bundle and:
|
||
<ul>
|
||
<li>add a configuration to the <code class="highlighter-rouge">TV</code> class with property “autoSleep” and value a timestamp (hh:mm);</li>
|
||
<li>modify the method that listens for events with topic “time” to stop the bundle, when the “autoSleep” property is equal to the “time” topic.</li>
|
||
</ul>
|
||
</li>
|
||
<li>Create another implementation of the <code class="highlighter-rouge">ElectricityProvider</code> interface (<code class="highlighter-rouge">RechargableBattery</code>) in an <code class="highlighter-rouge">org.openhab.training.electricity.rechargeablebattery</code> bundle that:
|
||
<ul>
|
||
<li>has a finite charge (e.g <code class="highlighter-rouge">int capacity = 30</code>);</li>
|
||
<li>implements the <em>ManagedService</em> interface. After this modification, it should be possible to change the charge of a battery with a <code class="highlighter-rouge">setCharge(int capacity)</code> method;</li>
|
||
</ul>
|
||
|
||
<p>Hint! Read about the <a href="https://osgi.org/javadoc/r4v42/org/osgi/service/cm/ConfigurationAdmin.html">ConfigurationAdmin</a> service and how you can use it to change the configuration of a ManagedService. You might want to implement additional bundle that is using the ConfigurationAdmin service to change the configuration of the battery to perform a quick test.</p>
|
||
|
||
<p>Hint! Install <code class="highlighter-rouge">org.eclipse.equinox.cm</code> bundle in order to use <em>ConfigurationAdmin</em> service.</p>
|
||
</li>
|
||
<li>Create a <code class="highlighter-rouge">org.openhab.training.electricity.recharger</code> bundle that will wait 10 seconds after it is activated and will recharge a rechargeable battery if it is registered as a service.</li>
|
||
</ol>
|
||
|
||
<h3 id="vii-console-commands">VII. Console Commands</h3>
|
||
|
||
<ol>
|
||
<li>Implement a service in the <code class="highlighter-rouge">org.openhab.training.util.console</code> bundle that adds console command, that:
|
||
<ul>
|
||
<li>displays all <code class="highlighter-rouge">ElectricityProvider</code> implementations that are registered with their charge;</li>
|
||
<li>displays all consumers, to which providers are they connected (which providers are available) and what is the current provider at the moment;</li>
|
||
</ul>
|
||
|
||
<p>Hint! You might have to register all consumers as services in the OSGi ServiceRegistry.</p>
|
||
|
||
<ul>
|
||
<li>sets the charge of the <code class="highlighter-rouge">RechargableBattery</code> to a provided value;</li>
|
||
<li>changes the configuration of the <code class="highlighter-rouge">TV</code>.</li>
|
||
</ul>
|
||
|
||
<p>Hint! You can add console commands with the help of
|
||
<a href="http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fosgi%2Fframework%2Fconsole%2FCommandProvider.html">CommandProvider</a></p>
|
||
|
||
<p>Hint! Test the console commands in the OSGi runtime by starting the different Radio consumers and the TV consumer. Start only the <code class="highlighter-rouge">Battery</code> provider and wait until it is discharged. Check if the consumers have stopped as expected. Recharge the battery and check, if the consumers have started. You can try out different scenarios as well!</p>
|
||
</li>
|
||
</ol>
|
||
|
||
<h2 id="references">References</h2>
|
||
|
||
<p>Some of the tutorials listed below are not up-to-date with the latest versions of the Equinox framework or are written to be run in another implementation of the OSGi Runtime (e.g. Apache Felix). They can help you with solving the tasks above. This resources are divided in several groups.</p>
|
||
|
||
<h3 class="no_toc" id="multiple-topics">Multiple topics</h3>
|
||
<ul>
|
||
<li>This tutorials simply cover more than one from the topics below:
|
||
<ul>
|
||
<li><a href="http://enroute.osgi.org/book/150-tutorials.html">OSGi enRoute project</a></li>
|
||
<li><a href="http://www.vogella.com/tutorials/OSGi/article.html">Lars Vogel: OSGi Modularity</a>;</li>
|
||
<li><a href="http://www.vogella.com/tutorials/OSGiServices/article.html">Lars Vogel: OSGi Services</a>;</li>
|
||
<li><a href="http://www.javaworld.com/article/2077837/java-se/java-se-hello-osgi-part-1-bundles-for-beginners.html">Hello, OSGi, Part 1: Bundles for beginners</a>;</li>
|
||
<li><a href="https://mnlipp.github.io/osgi-getting-started/">OSGi Getting Started</a>;</li>
|
||
<li><a href="http://o7planning.org/en/10135/java-osgi-tutorial-for-beginners">Java OSGi Tutorial for Beginners</a>;</li>
|
||
<li><a href="http://crunchify.com/understand-osgi-concepts-try-to-follow-the-puzzle-approach/">Understand OSGi Concepts. Try to Follow the Puzzle Approach</a>.</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h3 class="no_toc" id="writing-basic-osgi-bundle">Writing basic OSGi bundle</h3>
|
||
<ul>
|
||
<li>This tutorials are focused on writing basic bundle, managing the dependencies between the bundles and running them in an OSGi container:
|
||
<ul>
|
||
<li><a href="http://www.eclipsezone.com/eclipse/forums/m92130843.html">Getting started with OSGi: Your first bundle</a>;</li>
|
||
<li><a href="http://www.eclipsezone.com/eclipse/forums/m92131032.html">Getting started with OSGi: Interacting with the Framework</a>;</li>
|
||
<li><a href="http://www.eclipsezone.com/eclipse/forums/t90544.html">Getting started with OSGi: Dependencies between Bundles</a>.</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h3 class="no_toc" id="services">Services</h3>
|
||
<ul>
|
||
<li>Registering and using Services with the low-level OSGi API:
|
||
<ul>
|
||
<li><a href="http://eclipsezone.com/eclipse/forums/t90688.html">Getting started with OSGi: Registering a Service</a>;</li>
|
||
<li><a href="http://www.eclipsezone.com/eclipse/forums/t90796.html">Getting started with OSGi: Consuming a Service</a>;</li>
|
||
<li><a href="http://felix.apache.org/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-1.html">Apache Felix Tutorial: A bundle that listens for OSGi service events</a>;</li>
|
||
<li><a href="http://felix.apache.org/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-2.html">Apache Felix Tutorial: A bundle that implements a dictionary service</a>;</li>
|
||
<li><a href="http://felix.apache.org/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-2b.html">Apache Felix Tutorial: A bundle that implements another dictionary service</a>;</li>
|
||
<li><a href="http://felix.apache.org/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-3.html">Apache Felix Tutorial: A bundle that implements a simple dictionary service client</a>;</li>
|
||
<li><a href="http://felix.apache.org/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-4.html">Apache Felix Tutorial: A bundle that implements a more robust dictionary service client</a>.</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h3 class="no_toc" id="service-trackers">Service Trackers</h3>
|
||
<ul>
|
||
<li>OSGi Service Tracker simplifies using services from the Framework’s registry. You can find example usage in the links below:
|
||
<ul>
|
||
<li><a href="http://www.eclipsezone.com/eclipse/forums/t91059.rhtml">Getting started with OSGi: Dynamic Service Tracking</a>;</li>
|
||
<li><a href="http://felix.apache.org/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-5.html">Apache Felix Tutorial: A bundle that implements a dictionary service client using the Service Tracker</a>;</li>
|
||
<li><a href="http://felix.apache.org/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-6.html">Apache Felix Tutorial: A bundle that implements a spell checker service using dictionary services.</a>;</li>
|
||
<li><a href="http://felix.apache.org/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-7.html">Apache Felix Tutorial: A bundle that implements a spell checker service client</a>;</li>
|
||
<li><a href="http://stackoverflow.com/questions/28748052/osgi-servicetracker-servicetrackercustomizer">OSGi - ServiceTracker - ServiceTrackerCustomizer</a>.</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h3 class="no_toc" id="declarative-services-and-components">Declarative Services and Components</h3>
|
||
<ul>
|
||
<li>OSGi Declarative Services is a high level API for managing services in OSGi. Its functionality is widely used in the openHAB project. Tutorials about the topic:
|
||
<ul>
|
||
<li><a href="http://blog.vogella.com/2016/06/21/getting-started-with-osgi-declarative-services/">Getting Started with OSGi Declarative Services</a></li>
|
||
<li><a href="http://www.eclipsezone.com/eclipse/forums/t96740.html">Getting started with OSGi: Introducing Declarative Services</a>;</li>
|
||
<li><a href="http://www.eclipsezone.com/eclipse/forums/t97690.rhtml">Getting started with OSGi: Declarative Services and Dependencies</a>;</li>
|
||
<li><a href="http://felix.apache.org/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-9.html">Apache Felix Tutorial: A bundle that implements a spell checker service using Declarative Services</a>.</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h3 class="no_toc" id="managed-services">Managed Services</h3>
|
||
<ul>
|
||
<li><a href="http://nakvic-dev.blogspot.bg/2010/11/osgi-declarative-managed-services-and.html">OSGi declarative managed services and configuration</a></li>
|
||
</ul>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<footer>
|
||
<div class="container">
|
||
<div class="row">
|
||
<div class="col s12 m7">
|
||
Copyright © 2017 by the <a href="https://github.com/openhab">openHAB Community</a> and the <a href="http://www.openhabfoundation.org/">openHAB Foundation e.V.</a>
|
||
</div>
|
||
<div class="col s12 m5">
|
||
<ul class="list-inline right-align">
|
||
<li><a href="/imprint.html">Imprint</a></li>
|
||
<li><a href="/privacy.html">Privacy Policy</a></li>
|
||
<li><a href="http://www.openhab.org">openHAB Website</a></li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</footer>
|
||
<script src="/v2.1/js/jquery.min.js"></script>
|
||
<script src="/v2.1/js/jquery.scrollme.min.js"></script>
|
||
<script src="/v2.1/js/jquery.sticky.js"></script>
|
||
<script src="/v2.1/js/materialize.min.js"></script>
|
||
<script src="/v2.1/js/init.js"></script>
|
||
|
||
<script>
|
||
$(document).ready(function () {
|
||
|
||
$('#oh2-checkbox').change(function () {
|
||
if (this.checked) $('.since-2x').show('slow');
|
||
else $('.source-oh2').hide('slow');
|
||
});
|
||
|
||
$('#oh1-checkbox').change(function () {
|
||
if (this.checked) $('.since-1x').show('slow');
|
||
else $('.source-oh1').hide('slow');
|
||
});
|
||
|
||
$('#legacy-checkbox').change(function () {
|
||
if (this.checked) $('.install-legacy').show('slow');
|
||
else $('.install-legacy').hide('slow');
|
||
});
|
||
|
||
$('#manual-checkbox').change(function () {
|
||
if (this.checked) $('.install-manual').show('slow');
|
||
else $('.install-manual').hide('slow');
|
||
});
|
||
|
||
});
|
||
</script>
|
||
|
||
</body>
|
||
</html>
|
||
|