Hello Steve,
These annotations are part of the Felix DependencyManager (DM) annotaitons.
So, the two annotations can't be mixed. @AspectService are specialized
DependencyManager components (like @AdapterService,
or @BundleAdapterService), and can be used to dynamically define an
interceptor (or a chain of interceptors) between a service consumer and a
service provider.
You will define the service consumer and the service provider using
DM @Components annotations, but you will define the interceptors using
the @AspectService annotation.
Example: let's say you have a Database service provider interface.
Something like:
public interface Database {
String getObject(String key);
}
The implementation will be defined using @Component annotation:
@Component
public class DatabaseImpl implements Database {
public String getObject(String key) { /* implementation */ }
}
Then if you want to define an aspect that provides a caching for your
Database service, you will define it like this with only the @AspectService:
(AspectService are like Components, and can use @ServiceDependency
annotations, if they need to depend on something).
@AspectService
public class DatabaseCache implements Database {
// The service we are intercepting (injected by reflection)
volatile Database database;
public String getObject(String key) {
// returns keys from our cache, else return database.getObject(key);
}
}
You can chain multiple aspects that will be ordered using the ranking
annotation attribute, like @AspectService(ranking=10). Once the Database
original service is registered, then the DatabaseCache interceptor will be
instantiated, and registered.
The above example corresponds to the following that is using the original
DM API:
public class Activator extends DependencyActivatorBase {
&Override
public void init(BundleContext context, DependencyManager dm) throws
Exception {
Component aspectComponent = createAspectComponent()
.setAspect(Database.class, null, 10)
.setImplementation(DatabaseCache.class):
dm.add(aspectComponent);
}
}
or if you are using the DM lambda API:
public class Activator extends DependencyManagerActivator {
public void init(BundleContext ctx, DependencyManager dm) throws
Exception {
aspect(Database.class, aspect ->
aspect.impl(DatabaseCache.class).rank(10));
}
}
Hope this helps.
kind regards
/pierre
On Thu, Jun 17, 2021 at 2:25 AM David Jencks <[email protected]>
wrote:
> I’m used to the DS OSGI spec @Component annotation but I guess you are
> using the DM annotations and not DS?
>
> David Jencks
>
> > On Jun 16, 2021, at 1:57 PM, Steve Runion <[email protected]>
> wrote:
> >
> > My company has used activators for quite some time, instead of
> annotations, due to a perceived inability for the annotations to fit our
> needs.
> >
> > I have cornered the use case that is reported to be the challenge. We
> have services that are both aspects on services by their interfaces and
> also implement another (common) interface which are whiteboarded in
> elsewhere. The plumbing to get that to work would look like…
> >
> > @AspectService(ranking = 10, service = AimEncryptionKeyService.class)
> > @Component(provides = EntitySynchronizer.class)
> >
> > … however it seems as if these two annotations are not intended to be
> used as the same time. Whichever one is first is applied and the second is
> ignored. Is anyone aware of a workaround, or an idiomatic way, to get this
> scenario to work?
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>