blob: 2e4b37bb16293744f4d2b36a6ae7d73fcfd7d681 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Apache Felix Event Admin :: Apache Felix</title>
<link rel="canonical" href="https://felix.apache.org/documentation/subprojects/apache-felix-event-admin.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="apache-felix-dependency-manager.html">Dependency Manager</a>
<a class="navbar-item" href="apache-felix-event-admin.html">Event Admin</a>
<a class="navbar-item" href="apache-felix-file-install.html">File Install</a>
<a class="navbar-item" href="apache-felix-framework.html">Framework</a>
<a class="navbar-item" href="apache-felix-gogo.html">Gogo Shell</a>
<a class="navbar-item" href="apache-felix-healthchecks.html">Health Checks</a>
<a class="navbar-item" href="apache-felix-inventory.html">Inventory</a>
<a class="navbar-item" href="apache-felix-log.html">Log</a>
<a class="navbar-item" href="apache-felix-logback.html">Logback</a>
<a class="navbar-item" href="apache-felix-maven-bundle-plugin.html">Maven bundle plugin</a>
<a class="navbar-item" href="apache-felix-maven-scr-plugin.html">Maven SCR plugin</a>
<a class="navbar-item" href="apache-felix-metatype-service.html">Metatype Service</a>
<a class="navbar-item" href="apache-felix-preferences-service.html">Preferences Service</a>
<a class="navbar-item" href="apache-felix-remote-shell.html">Remote Shell</a>
<a class="navbar-item" href="apache-felix-script-console-plugin.html">Script console plugin</a>
<a class="navbar-item" href="apache-felix-shell.html">Lightweight shell</a>
<a class="navbar-item" href="apache-felix-shell-tui.html">Shell TUI</a>
<a class="navbar-item" href="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="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="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="apache-felix-dependency-manager/guides/annotations.html">Dependency Manager - Annotations</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/background.html">Dependency Manager - Background</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="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="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="apache-felix-dependency-manager/guides/development.html">Dependency Manager - Development</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/history.html">Dependency Manager - History</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/javadocs.html">Dependency Manager - JavaDocs</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="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="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="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="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="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="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="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="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="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="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="apache-felix-dependency-manager/reference/components.html">Dependency Manager - Components</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="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="apache-felix-dependency-manager/reference/dependencies.html">Dependency Manager - Dependencies</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="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="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="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="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="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="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="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="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="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="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="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="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="apache-felix-dependency-manager/tutorials/sample-code.html">Dependency Manager sample projects</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item is-current-page" data-depth="2">
<a class="nav-link" href="apache-felix-event-admin.html">Apache Felix Event Admin</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="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="apache-felix-framework.html">Apache Felix Framework</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="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="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="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="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="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="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="apache-felix-gogo.html">Apache Felix Gogo</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="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="apache-felix-healthchecks.html">Apache Felix Health Checks</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-inventory.html">Apache Felix Inventory Printer</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-log.html">Apache Felix Log</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-logback.html">Apache Felix Logback</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="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="apache-felix-metatype-service.html">Apache Felix Metatype Service</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="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="apache-felix-preferences-service.html">Apache Felix Preferences Service</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-remote-shell.html">Apache Felix Remote Shell</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-shell.html">Apache Felix Shell</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="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="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="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="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="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="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="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="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="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="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>
</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="../tutorials-examples-and-presentations/apache-felix-application-demonstration.html">Apache Felix Application Demonstration</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial.html">Apache Felix OSGi Tutorial</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../tutorials-examples-and-presentations/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="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/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="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/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="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/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="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/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="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/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="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/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="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/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="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-7.html">Example 7 - Spell Checker Client Bundle</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/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="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/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="../subprojects.html">Subprojects</a></li>
<li><a href="apache-felix-event-admin.html">Apache Felix Event Admin</a></li>
</ul>
</nav>
<div class="edit-this-page"><a href="https://github.com/apache/felix-antora-site/edit/main/modules/ROOT/pages/subprojects/apache-felix-event-admin.adoc">Edit this Page</a></div>
</div>
<div class="content">
<article class="doc">
<h1 class="page">Apache Felix Event Admin</h1>
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>The Event Admin Service Specification, part of the OSGi Compendium specification, defines a general inter-bundle communication mechanism.
The communication conforms to the popular publish/subscribe paradigm and can be performed in a synchronous or asysnchronous manner.</p>
</div>
<div class="paragraph">
<p>The main components in a publish/subscribe communication are:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><em>Event Publisher</em> - sends events or messages related to a specific <em>topic</em></p>
</li>
<li>
<p><em>Event Handler</em> (or <em>Subscriber</em>) - expresses interest in one or more topics and receives all the messages belonging to such topics.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Events are composed of two attributes:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>a <em>topic</em> defining the nature of the event;
topic names are usually arranged in a hierarchical namespace, where slashes are used to separate the levels (i.e.
"org/osgi/framework/FrameworkEvent/STARTED") and</p>
</li>
<li>
<p>a set of <em>properties</em> describing the event.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_creating_an_event_publisher"><a class="anchor" href="#_creating_an_event_publisher"></a>Creating an Event Publisher</h2>
<div class="sectionbody">
<div class="paragraph">
<p>An event publisher is a simple Java class that creates events and sends them using the <code>EventAdmin</code> service interface, for example:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>public void reportGenerated(Report report, BundleContext context)
{
ServiceReference ref = context.getServiceReference(EventAdmin.class.getName());
if (ref != null)
{
EventAdmin eventAdmin = (EventAdmin) context.getService(ref);</pre>
</div>
</div>
<div class="literalblock">
<div class="content">
<pre>Dictionary properties = new Hashtable();
properties.put("title", report.getTitle());
properties.put("path" , report.getAbsolutePath());
properties.put("time", System.currentTimeMillis());</pre>
</div>
</div>
<div class="literalblock">
<div class="content">
<pre>Event reportGeneratedEvent = new Event("com/acme/reportgenerator/GENERATED", properties);</pre>
</div>
</div>
<div class="literalblock">
<div class="content">
<pre> eventAdmin.sendEvent(reportGeneratedEvent);
}
}</pre>
</div>
</div>
<div class="paragraph">
<p>The <code>EventAdmin.sendEvent()</code> method sends the <code>Event</code> object synchronously.
To send it asynchronously, use the <code>EventAdmin.postEvent()</code> method, such as:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>//..
Event reportGeneratedEvent = new Event("com/acme/reportgenerator/GENERATED", properties);
eventAdmin.postEvent(reportGeneratedEvent);</pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_creating_an_event_handler"><a class="anchor" href="#_creating_an_event_handler"></a>Creating an Event Handler</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Creating an event handler is as simple as implementing the <code>EventHandler</code> interface:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>public class ReportEventHandler implements EventHandler
{
public void handleEvent(Event event)
{
String reportTitle = (String) event.getProperty("title");
String reportPath = (String) event.getProperty("path");</pre>
</div>
</div>
<div class="literalblock">
<div class="content">
<pre> sendReportByEmail(reportTitle, reportPath);
}</pre>
</div>
</div>
<div class="literalblock">
<div class="content">
<pre>//..</pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_registering_an_event_handler"><a class="anchor" href="#_registering_an_event_handler"></a>Registering an Event Handler</h2>
<div class="sectionbody">
<div class="paragraph">
<p>To receive event notifications, the event handler must be registered as a OSGi service under the object class <code>org.osgi.service.event.EventHandler</code>.
When registering the service, a <code>String\[\]({{ refs..path }})</code> property named <code><strong>EVENT_TOPIC</strong></code> must be specified;
this property describes the list of topics in which the event handler is interested.
For example:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>String[] topics = new String[] {
"com/acme/reportgenerator/GENERATED"
};</pre>
</div>
</div>
<div class="literalblock">
<div class="content">
<pre>Dictionary props = new Hashtable();
props.put(EventConstants.EVENT_TOPIC, topics);
bundleContext.registerService(EventHandler.class.getName(), new ReportEventHandler() , props);</pre>
</div>
</div>
<div class="paragraph">
<p>It is possible to use '*' as a wildcard in the final character of the EVENT_TOPIC, like in this example:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>String[] topics = new String[] {
"com/acme/reportgenerator/*"
};</pre>
</div>
</div>
<div class="literalblock">
<div class="content">
<pre>Dictionary props = new Hashtable();
props.put(EventConstants.EVENT_TOPIC, topics);
bundleContext.registerService(EventHandler.class.getName(), new ReportEventHandler() , props);</pre>
</div>
</div>
<div class="paragraph">
<p>Finally, it is possible to specify an additional <code>EVENT_FILTER</code> property to filter event notifications;
the filter expression follows, the normal LDAP syntax:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>String[] topics = new String[] {
"com/acme/reportgenerator/GENERATED"
};</pre>
</div>
</div>
<div class="literalblock">
<div class="content">
<pre>Dictionary props = new Hashtable();
props.put(EventConstants.EVENT_TOPIC, topics);
props.put(EventConstants.EVENT_FILTER, "(title=samplereport)");
bundleContext.registerService(EventHandler.class.getName(), new ReportEventHandler() , props);</pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_osgi_events"><a class="anchor" href="#_osgi_events"></a>OSGi Events</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Every OSGi framework sends (asynchronously) a number of events that can be captured by any bundle.</p>
</div>
<div class="sect2">
<h3 id="_framework_events"><a class="anchor" href="#_framework_events"></a>Framework Events</h3>
<div class="ulist">
<ul>
<li>
<p>org/osgi/framework/BundleEvent/STARTED</p>
</li>
<li>
<p>org/osgi/framework/BundleEvent/ERROR</p>
</li>
<li>
<p>org/osgi/framework/BundleEvent/PACKAGES_REFRESHED</p>
</li>
<li>
<p>org/osgi/framework/BundleEvent/STARTLEVEL_CHANGED</p>
</li>
<li>
<p>org/osgi/framework/BundleEvent/WARNING</p>
</li>
<li>
<p>org/osgi/framework/BundleEvent/INFO</p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_bundle_events"><a class="anchor" href="#_bundle_events"></a>Bundle Events</h3>
<div class="ulist">
<ul>
<li>
<p>org/osgi/framework/BundleEvent/INSTALLED</p>
</li>
<li>
<p>org/osgi/framework/BundleEvent/STARTED</p>
</li>
<li>
<p>org/osgi/framework/BundleEvent/STOPPED</p>
</li>
<li>
<p>org/osgi/framework/BundleEvent/UPDATED</p>
</li>
<li>
<p>org/osgi/framework/BundleEvent/UNINSTALLED</p>
</li>
<li>
<p>org/osgi/framework/BundleEvent/RESOLVED</p>
</li>
<li>
<p>org/osgi/framework/BundleEvent/UNRESOLVED</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The followig properties are always present in a bundle event object:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><em>bundle.id</em></p>
</li>
<li>
<p><em>bundle.symbolicName</em></p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_service_events"><a class="anchor" href="#_service_events"></a>Service Events</h3>
<div class="ulist">
<ul>
<li>
<p>org/osgi/framework/ServiceEvent/REGISTERED</p>
</li>
<li>
<p>org/osgi/framework/ServiceEvent/MODIFIED</p>
</li>
<li>
<p>org/osgi/framework/ServiceEvent/UNREGISTERING</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The following properties are always present in a service event object:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><em>service</em></p>
</li>
<li>
<p><em>service.id</em></p>
</li>
<li>
<p><em>service.pid</em></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Each of the aforementioned events actually contains a wider set of properties.
Check the OSGi Compendium specification, section 113.6, for a complete list.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_configuration"><a class="anchor" href="#_configuration"></a>Configuration</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The Apache Felix Event Admin implementation is trying the deliver the events as fast as possible.
Events sent from different threads are sent in parallel.
Events from the same thread are sent in the order they are received (this is according to the spec).
A timeout can be configured which is used for event handlers.
If an event handler takes longer than the configured timeout to process an event, it is denied.
Once a handler is in a denylist, it doesn&#8217;t get sent any events anymore.
The Felix Event Admin can be configured either through framework properties or through the configuration admin using PID <code>org.apache.felix.eventadmin.impl.EventAdmin</code>.
This is a list of configuration properties:</p>
</div>
<hr>
<div class="paragraph">
<p><strong>Thread Pool Size</strong></p>
</div>
<div class="paragraph">
<p><em>Property</em>: org.apache.felix.eventadmin.ThreadPoolSize + <em>Default</em>: 20 + <em>Type</em>: Integer</p>
</div>
<div class="paragraph">
<p>The size of the thread pool used for event delivery.
The default value is 20.
Increase in case of a large amount of events.
A value of less then 2 triggers the default value.
If the pool is exhausted, event delivery is blocked until a thread becomes available from the pool.
Each event is delivered in a thread from the pool unless the ignore timeouts is configured for the receiving event handler.</p>
</div>
<hr>
<div class="paragraph">
<p><strong>Async/sync Thread Pool Ratio</strong></p>
</div>
<div class="paragraph">
<p><em>Property</em>: org.apache.felix.eventadmin.AsyncToSyncThreadRatio + <em>Since</em>: Release 1.4.2 + <em>Default</em>: 0.5 + <em>Type</em>: Double</p>
</div>
<div class="paragraph">
<p>The ratio of asynchronous to synchronous threads in the internal thread pool.
Ratio must be positive and may be adjusted to represent the distribution of post to send operations.
Applications with higher number of post operations should have a higher ratio.</p>
</div>
<hr>
<div class="paragraph">
<p><strong>Timeout</strong></p>
</div>
<div class="paragraph">
<p><em>Property</em>: org.apache.felix.eventadmin.Timeout + <em>Default</em>: 5000 + <em>Type</em>: Integer</p>
</div>
<div class="paragraph">
<p>The deny-listing timeout in milliseconds.
The default value is 5000.
Increase or decrease at own discretion.
A value of less then 100 turns timeouts off.
Any other value is the time in milliseconds granted to each event handler before it gets denied.</p>
</div>
<hr>
<div class="paragraph">
<p><strong>Require Topic</strong></p>
</div>
<div class="paragraph">
<p><em>Property</em>: org.apache.felix.eventadmin.RequireTopic + <em>Default</em>: true + <em>Type</em>: Boolean</p>
</div>
<div class="paragraph">
<p>Are event handlers required to be registered with a topic?
This is enabled by default.
The specification says that event handlers must register with a list of topics they are interested in.
Disabling this setting will enable that handlers without a topic are receiving all events (i.e., they are treated the same as with a topic=*).</p>
</div>
<hr>
<div class="paragraph">
<p><strong>Ignore Timeouts</strong></p>
</div>
<div class="paragraph">
<p><em>Property</em>: org.apache.felix.eventadmin.IgnoreTimeout + <em>Default</em>: empty + <em>Type</em>: String</p>
</div>
<div class="paragraph">
<p>Configure event handlers to be called without a timeout.
If a timeout is configured by default all event handlers are called using the timeout.
For performance optimization it is possible to configure event handlers where the timeout handling is not used - this reduces the thread usage from the thread pools as the timout handling requires an additional thread to call the event handler.
However, the application should work without this configuration property.
It is a pure optimization!
The value is a list of strings.
If a string ends with a dot, all handlers in exactly this package are ignored.
If the string ends with a star, all handlers in this package and all subpackages are ignored.
If the string neither ends with a dot nor with a start, this is assumed to define an exact class name.</p>
</div>
<hr>
<div class="paragraph">
<p><strong>Ignore Topics</strong></p>
</div>
<div class="paragraph">
<p><em>Property</em>: org.apache.felix.eventadmin.IgnoreTopic + <em>Since</em>: Release 1.4.0 + <em>Default</em>: empty + <em>Type</em>: String</p>
</div>
<div class="paragraph">
<p>For performance optimization it is possible to configure topics which are ignored by the event admin implementation.
In this case, a event is not delivered to registered event handlers.
The value is a list of strings (separated by comma).
" +If a single value ends with a dot, all topics in exactly this package are ignored.
If a single value ends with a star, all topics in this package and all sub packages are ignored.
If a single value neither ends with a dot nor with a start, this is assumed to define an exact topic.
A single star can be used to disable delivery completely.</p>
</div>
<hr>
<div class="paragraph">
<p><strong>Log Level</strong></p>
</div>
<div class="paragraph">
<p><em>Property</em>: org.apache.felix.eventadmin.LogLevel + <em>Note</em>: This property can&#8217;t be set through the OSGi configuration.
+ <em>Default</em>: 2 (=WARNING) + <em>Type</em>: Integer</p>
</div>
<div class="paragraph">
<p>This sets the log level used for messages outputted by the event admin implementation.
Valid values are 1 (=ERROR), 2 (=WARNING), 3 (=INFO), and 4 (=DEBUG).
The default is 2 and an invalid value sets the level to the default value.</p>
</div>
<hr>
</div>
</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>