java - Can I inject proxies in front of Blueprint services published by other bundles? -
we using karaf
, number of osgi blueprint services
implement system.
is possible make "bundlelistener"
type of bundle that, when present in osgi
container, decorates our blueprint services
proxy bundles referring these services call proxy instead?
(i guess accomplished either somehow adding proxy in front of service in service registry, or changing reference obtained referring bundle - servicetracker.addingservice
style)
the standard way these hacks use service hooks in osgi core framework. hooks allow remove service view of 1 or more bundles. can register service proxies first service , not removed bundle's view.
existing:
+----------+ +----------+ | register |------<|------| using | +----------+ +----------+
proxied
+----------+ hide +----------+ | register |------<|-+--x-| using |---|>---+ proxied +----------+ | +----------+ | | | | +----------+ | +----| manager |--------+ +----------+
though @ first bit odd, "remove view" capability allows control in detail service bundle exposed while keeping overall complexity minimal. see chapter 55 in osgi 5.0.0 core. section 55.3.1 details proxying.
<soapbox>
i call these things hacks because proxies way have bad runtime temporal ordering qualities. if manager bundle (the 1 hides , creates proxies) started later bundle using service you're in trouble since using bundle temporarily exposed non-proxied service.
though there ways solve start ordering problem, suck since have undeclared (ordering) dependency. better ensure bundle uses proxy has special dependency, service type or special service property. since dependency explicit, have no more worries ordering, temporal dependency has become ordinary service dependency problem handled ds , other service managers in osgi.
using property/other type proxy
+----------+ +----------+ proxied=true | register | | using |---|>---+ +----------+ +----------+ | | | | +----------+ | +-----------<|------| manager |--------+ +----------+
you not want modify bundle registers service nor bundle uses service since kill whole idea of reusable aspect. programmers of registering/using bundles should blissfully unaware of manager's scheme. how se filter on using bundle?
if use declarative services (ds), you're in luck! ds can set filter on service reference through configuration admin 'target.' configuration property. manager bundle sees service proxied, registers second service special property (e.g. 'proxied=true'). using bundle has filter set through configuration admin ds' target reference property '(proxied=*)'.
</soapbox>
Comments
Post a Comment