Main

Component-based development

Eclipse and OSGi

http://paulonjava.blogspot.de/2013/11/building-bndtools-projects-with-gradle.html

  • GRADLE + BNDTOOLS

http://www.eclipsezone.com/articles/extensions-vs-services/

  • comparing Eclipse Extension Registry to OSGi services
  • describing Declarative Services in OSGi as the best of both worlds

http://karaf.apache.org/

  • lightweight OSGi container
  • hot-deployment
  • SSH access

http://bndtools.org/tutorial.html

  • totorial about bndtools
  • automates development with OSGi, e.g. declarative services
  • Bndtools follows the “generated manifest” approach to building OSGi bundles; this is in contrast to the “manifest first” approach used by some other tools.

http://www.aqute.biz/Bnd/Components

  • BND annotations explained
  • @Component, @Activate, @Deactivate, @Reference ...

http://blog.osgi.org/2011/04/osgi-lite.html

  • OSGi Lite = 80% functionality of OSGi
  • without module boudaries, in a single class loader

https://github.com/javakontor/OSGi-Service-Component-Annotation-Processor

  • Annotation processor for OSGi Declarative Service Components
  • supports BND annotations and RFC0172 annotations
  • generates XML files in OSGI-INF
  • Eclipse plugin

http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin.html

  • Bundle Plugin for Maven

http://stackoverflow.com/questions/434664/accessing-command-line-arguments-from-osgi-bundle

  • getting command line arguments from BundleContext when using BND-annotations + DS

http://dev.day.com/content/ddc/blog/2010/01/dsdelayedcomponent.html

  • about services (e.g. immediate vs delayed) ...

http://felix.apache.org/site/apache-felix-file-install.html

  • dynamic loading/unloading of bundles and configurations from a directory

Tips for OSGi development

  • use bndtools plugin for Eclipse
  • use "name.njbartlett.osgi.emf" project for EMF support in non-Eclipse applications
  • Import some bundles from your running eclipse plugins/ dir to the "local repository" located in the "cnf" project of your workspace (use the "Repositories" view for importing)
  • Most of your projects will contain multiple bundle descriptors (*.bnd) files.
  • Make sure you set "Declarative Services: Bnd Annotations" in all bundle descriptors where you have classes annotated with the @Component annotation.
  • To define a component X which provides an interface Y, use:
 @Component
 class X implements Y { ... }
  • To define a component X which just provides itself, use:
 @Component(provide=X.class)
 class X { ... }
  • To define a required interface XYZ, use
 @Reference
 void setXYZ(XYZ instance) { ... }
  • You can make the binding dynamic, i.e. your component will be notified about updates after it has started:
 @Reference(dynamic=true)
  • You can define a component that gets instantiated for each bundle separately. However, if there are multiple consumers within the same bundle, they share the instance.
 @Component(servicefactory=true)
 class X implements Y { ... }
  • You can define a component that can be dynamically created multiple times using a factory.
 // these instances will be created by the factory
 @Component(factory="MYNAME")
 class X implements Y { ... }


 // this component uses the factory
 @Component
 class Consumer {

   private ComponentInstance comp;

   @Reference(target = "(component.factory=MYNAME)")
   public void setFactory(final ComponentFactory factory) {
     // remember the component to control its lifecycle
     // or use it to create instances
     comp = factory.newInstance(properties);
     final Y serviceY = (Y) comp.getInstance();
   }

   @Deactivate
   void deactivate() {
     comp.dispose();
   }
 }
  • By default, bnd generates the bundles that include the original source code from the project. To disable bundling of the source code, add the following line to the bnd.bnd file:
 -sources: false
  • In order to preserve service configurations between OSGi restarts, add the following line to your *.bndrun file. If you don't do that, bndtools will use the generated/fw dir which is cleaned before running OSGi from a *.bndrun file.
 
 -runproperties: \
   launch.keep=true,\
   launch.storage.dir=/path/to/some/dir
 
  • To activate the web console, add the following bundles to the "Run Requirements". You can then visit http://localhost:8080/system/console/configMgr (username=admin, password=admim) and change the configuration settings of your components.
 org.apache.felix.http.jetty
 org.apache.felix.webconsole
 org.apache.felix.metatype

Model-driven development

OCL (Object Constraint Language)

Tips and Tricks