A New Approach to Software Development

A Gentle Introduction to OSGi - Part 2


We’ll have a closer look at…


… two of these services: LoggingService and EventAdmin with complete code samples. In the first sample, we will send traces and retrieve them with the LogService API. Sending traces is trivial, just injecting a reference to the LogService, then using it to store LogEntries. Reading these traces is not difficult while using the LogReaderService (Listing 1).



Figure 3 shows the results of two such bundles installed in a Felix container.



Listing 2 illustrates how OSGi provides a smart way to master coupling between bundles using a ‘messages broker’like : EventAdmin. Sending events with EventAdmin. Figure 4 shows events in action.



The two bundles use a naming convention while sharing a common topic, the object storing messages (events in the EventAdmin wording). It's important to ensure to use the same name in both bundles to get a working communication.




Jerome Moliere
Jerome Moliere

What do you think?

JAX Magazine - 2014 - 06 Exclucively for iPad users JAX Magazine on Android


Latest opinions