AspectComponent = 
 null, 10)
component.setInterface(EntitySynchronizer.class, properties);
return component;

For example this is what one of our Activators look like. Our component aspects 
<aspectedInterface> and also implements EntitySynchronizer. There are other 
services (only a handful AFAIK) that whiteboard in EntitySynchronizers and 
monitor the health of them by that interface.

From: Steve Runion <steve.run...@myfuelmaster.com>
Sent: Thursday, June 17, 2021 5:18 AM
To: users@felix.apache.org <users@felix.apache.org>
Subject: Re: @Component and @AspectService not playing nice

CAUTION: This email originated from outside of the organization. Do not click 
links or open attachments unless you recognize the sender and know the content 
is safe.

Thanks for the responses.

>From what I am reading out usage where we have services that are both 
>interceptors (aspects) and services (in their own right) that are white 
>boarded in is atypical. I could probably work around this by adding service 
>properties (or use one of the ones we are already adding to the aspect) to get 
>around the need for these to both be aspects and components.

Get Outlook for 
From: Pierre De Rop <pierre.de...@gmail.com>
Sent: Thursday, June 17, 2021 2:16:43 AM
To: users@felix.apache.org <users@felix.apache.org>
Subject: Re: @Component and @AspectService not playing nice

CAUTION: This email originated from outside of the organization. Do not click 
links or open attachments unless you recognize the sender and know the content 
is safe.

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:

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).

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

public class Activator extends DependencyActivatorBase {
     public void init(BundleContext context, DependencyManager dm) throws
Exception {
         Component aspectComponent = createAspectComponent()
             .setAspect(Database.class, null, 10)

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 ->

Hope this helps.

kind regards

On Thu, Jun 17, 2021 at 2:25 AM David Jencks <david.a.jen...@gmail.com>

> 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 <steve.run...@myfuelmaster.com>
> 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: users-unsubscr...@felix.apache.org
> For additional commands, e-mail: users-h...@felix.apache.org

Reply via email to