The project code is hosted at github. The development is enviroment is based on the Eclipse Bndtools plugin. If you want to follow the tutorial logic, the easiest way to get started is to clone the repository, checkout branch track1 and then import the projects into a new Eclipse workspace:
git clone https://github.com/Amplifino/nestor cd nestor git checkout track1
In order to start we need an OSGI framework implementation. We choose Felix as our reference container, but the examples should also work on Equinox. We add a few standard OSGI services to the bare framework:
Note: when deploying servlet based web applications in OSGI one has two options:
Next we need a console to interact with the OSGI framework. We will actually use two, the Gogo (command line) Console and the Apache Felix Web console.
Finally we want to make it easy for bundles to log to the OSGI Log Service.
With Declarative Services it is trivial to reference the log service from a component, but passing the log service reference forward to all objects that need to log is rather cumbersome.
While java.util.logging is probably not the best logging framework, it has the advantage of being accessible from any context.
Hence we create a bundle that adds a handler to java.util.logging's root logger that forwards LogRecords to the OSGI Log Service. By default it will only forward messages with a log level of INFO, but this can be changed using Config Admin. Note that this only configures the handler, not the logger. Loggers have their own level (that also defaults to INFO) and a log message needs to pass both the logger and the handler treshold. Logger log levels can be configured programmatically or through a logging.properties file.
The com.amplifino.nestor.logging.test projects shows how you can create bundle test in Bndtools. To run them select Bnd OSGI Test Launcher (JUnit) from the Run as menu. The required bundles for the test are defined in the bnd.bnd bundle configuration file.
This results in the following bundle list:
The com.amplifino.nestor.logging.test project shows how you can create bundle test in Bndtools. To run them select Bnd OSGI Test Launcher (JUnit) from the Run as menu. The required bundles for the test are defined in the bnd.bnd bundle configuration file. It also contains a runner.bndrun file to start an OSGI container with the above bundle list.