...
The next step would probably be to do some service binding. This is somewhat more overhead, as the referred to services must be declared. On the other hand, you do not have to care to listen for these services. As an example, we will refer to the OSGi LogService
. First we will examples of these strategies we will first use the lookup strategy to access an OSGi HttpService
and second then we will use the event strategy to access an OSGi LogService
(I personally prefer the event strategy, but your mileage may vary).
...
Code Block | ||
---|---|---|
| ||
<component...> ... <reference name="loghttp" interface="org.osgi.service.loghttp.LogServiceHttpService" cardinality="1..1" policy="static" /> ... </component> |
To use this service you call the ComponentContext.getService(String)
method, for example in the activate
method:
Code Block |
---|
protected void activate(ComponentContext context) { LogServiceHttpService loghttp = (LogService HttpService ) context.locateService( "loghttp" ); log.log(LogService.LOG_INFO, "Hello Components!"); } |
Receiving the Service
...