Given a service Sender
with properties, and an aspect service LogSender
, how does LogSender
get the service properties of the current Sender
? I'd like to add a property to optionally log the data that a specific Sender
is sending.
component.getServiceProperties();
seems to return the LogSender
's service properties instead of Sender
's properties.
I've looked at ConfigAdmin
but I don't see a way to associate the Sender
that LogSender
aspected, with the specific configuration used.
I'm using Apache Felix as my OSGi container if that's relevant.
Here's the Activator
's init
method after adding ConfigurationAdmin
to the dependency list.
public void init(BundleContext context, DependencyManager manager) throws Exception {
manager.add(createAspectService(Sender.class, null, 10).setImplementation(LogSender.class)
.add(createServiceDependency().setService(ConfigurationAdmin.class)
.setRequired(true)));
.add(createServiceDependency().setService(LogService.class).setRequired(true)));
}
To inject the service properties of the original Sender into the LogSender aspect, you can use the signature in DependencyActivatorBase (or DependencyManager), which allows to specify "add/change/remove" LogSender aspect callback methods:
Then the LogSenderAspect callbacks method signature can take as arguments the Sender service, as well as the Sender service properties Map.
Now, the second (simpler) solution is to specify a service filter for your aspect, and in this case; no need to specify any callbacks.
let's take a look at the first solution with callbacks, where the LogSender aspect defines a "setSender(Sender, Map)" method, and the aspect will then only log the "send" method of Sender services having "foo=bar" service properties (here, we ignore service change/removed callbacks):
Now, a simpler solution consists in using a service filter "(foo=bar)" when defining your aspect, and in this case, no need to use callback:
does this help ? /Pierre