Osgi in Apache Stanbol a Modular Software Stack and Reusable Set of Components for Semantic Content Management
Total Page:16
File Type:pdf, Size:1020Kb
stanbol.apache.org OSGi in Apache Stanbol a modular software stack and reusable set of components for semantic content management September 2012 - Bertrand Delacretaz - @bdelacretaz OSGi? java modularization specs from the OSGi alliance, www.osgi.org an OSGi bundle is a jar file with metadata, can provide an Activator and Services OSGi bundle OSGi framework MANIFEST.MF Bundle name starts, wires and runs a set of bundles, dynamically OSGi Bundle version Import/export packages OSGi framework bundle metadata ... Declarative Services Runtime Configuration Admin runs at startup initialized by OSGi setup by OSGi setup by OSGi Logging Bundle OSGisetup by OSGi Activator Component OSGI web console JMX HTTP service registered by OSGi Plain Old setup by OSGi Application module 1 setup by OSGi Java OSGisetup by OSGi Application module 2 implements Service Interface ... stanbol.apache.org Building Stanbol as a runnable jar file that embeds OSGi bundles to install at startup bundle list bundle list Stanbol Stanbol Stanbol launcher core commons Maven build runnable jar with embedded bundles bundle list bundle list OSGi bootstrap maven-launchpad-plugin OSGi framework OSGi Stanbol from Apache Sling services engines OSGi SCR services Stanbol engine #1 bundle list Stanbol engine #2 Clerezza Custom engine RDF libs ... Initial configs ... Apache Sling’s OSGi launcher stanbol.apache.org Starting Stanbol Start the OSGi framework, which starts all available bundles and services double-click or java -jar HTTP OSGi services Apache Felix’s requests Stanbol launcher Stanbol HTTP runnable jar core service with embedded bundles OSGi service OSGi bootstrap Engines OSGi framework manager OSGi SCR services Apache Sling’s Stanbol engine #1 OSGi OSGi service OSGi service OSGi service Stanbol engine #2 launcher Custom engine Engine A Engine B ... Initial configs ... Apache Felix’s Apache Felix’s Apache Felix’s Web console OSGi Config Services console Admin Runtime OSGi framework (Apache Felix) Starts, configures and wires services dynamically stanbol.apache.org Configuring Stanbol Using the Apache Felix webconsole // corresponding code excerpts: private static final double DEFAULT_MIN_SCORE = 0.33; @Property(doubleValue = DEFAULT_MIN_SCORE) public static final String MIN_SCORE = "locationEnhancementEngine.min-score"; ... @Activate // called when OSGi component is activated protected void activate(ComponentContext ce) { Dictionary<String, Object> properties = ce.getProperties(); setMinScore((Double) properties.get(MIN_SCORE)); ... stanbol.apache.org Extending Stanbol Adding a custom EnhancementEngine @Component @Service public class MyEngine implements EnhancementEngine { OSGi bundle @Activate public void activate(ComponentContext c) { Maven build MANIFEST.MF // initialize, configure, ... } OSGi maven-bundle-plugin adds OSGI metadata metadata public int canEnhance(ContentItem item) { if(...item matches our expectations...) { return ENHANCE_SYNCHRONOUS; maven-scr-plugin registered by OSGi } else { adds services metadata MyEngine return CANNOT_ENHANCE; } Service } public void computeEnhancements(ContentItem item) { // run the engine and add results to item’s // RDF graph based on the item’s InputStream } Install in } Stanbol no restart needed stanbol.apache.org.